/**
  * Returns an HTML string containing an 'a' element for the given page
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @param  boolean      $hasParent if the breadcrumb has a parent
  * @return string
  */
 public function htmlify(AbstractPage $page, $hasParent = false)
 {
     $html = '<li';
     if (!$hasParent) {
         $html .= ' class="active"';
     }
     $html .= '>';
     $label = $page->getLabel();
     if (null !== ($translator = $this->getTranslator())) {
         $label = $translator->translate($label, $this->getTranslatorTextDomain());
     }
     $escaper = $this->view->plugin('escapeHtml');
     $label = $escaper($label);
     if ($page->getHref() && ($hasParent || !$hasParent && $this->getLinkLast())) {
         $anchorAttribs = $this->htmlAttribs(array('href' => $page->getHref()));
         $html .= '<a' . $anchorAttribs . '>' . $label . '</a>';
     } else {
         $html .= $label;
     }
     if ($hasParent) {
         $html .= '<span class="divider">' . $this->getSeparator() . '</span>';
     }
     $html .= '</li>';
     return $html;
 }
 protected function decorateDropdown($content, \Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array())
 {
     //Get attribs
     $liAttribs = array('id' => $page->getId(), 'class' => 'dropdown' . ($page->isActive(true) ? ' active' : ''));
     $html = "\n" . '<li' . $this->htmlAttribs($liAttribs) . '>' . "\n" . $content . "\n</li>";
     return $html;
 }
Esempio n. 3
0
 /**
  * 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  AbstractPage $page  page to check
  * @return bool                whether page is accepted by ACL
  */
 protected function acceptAcl(AbstractPage $page)
 {
     if (!($acl = $this->getAcl())) {
         // no acl registered means don't use acl
         return true;
     }
     $role = $this->getRole();
     $roles = $this->getRoles();
     $resource = $page->getResource();
     if ($resource === NULL) {
         return true;
     }
     $resource = $this->acl->hasResourceOrParent($resource);
     if ($resource === false || $resource === NULL) {
         return false;
     }
     if (!$roles) {
         $roles = array($role);
     }
     if ($resource) {
         foreach ($roles as $r) {
             /**
              * TODO: for now this has been set to allow an item if its resource is not found
              */
             if (!$acl->hasResource($resource) || $acl->isAllowed($r, $resource)) {
                 return true;
             }
         }
         return false;
     }
     return true;
 }
Esempio n. 4
0
 protected function isActive(AbstractPage $page, $recursive = true)
 {
     if ($page->get('identifier') != $this->identifier && $recursive) {
         foreach ($page->getPages() as $subPage) {
             if ($this->isActive($subPage, $recursive)) {
                 return true;
             }
         }
         return false;
     }
     return $page->get('identifier') == $this->identifier;
 }
 public function htmlifyLabel(AbstractPage $page)
 {
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     /** @var \Zend\View\Helper\EscapeHtml $escaper */
     $escaper = $this->view->plugin('escapeHtml');
     $label = $escaper($label);
     if (isset($page->icon)) {
         $attribs = array('class' => 'fa fa-' . $page->icon);
         $label = '<i ' . $this->htmlAttribs($attribs) . '></i> ' . $label;
     }
     return $label;
 }
Esempio n. 6
0
 /**
  * Get list item class.
  *
  * @param AbstractPage $page
  *
  * @return string
  */
 public function getLiClass(AbstractPage $page)
 {
     /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */
     $escaper = $this->getView()->plugin('escapeHtmlAttr');
     $liClasses = array($this->liClass);
     if ($this->getAddClassToListItem()) {
         $liClasses[] = $page->getClass();
     }
     if ($page->hasPages()) {
         $liClasses[] = $this->getLiHasMenuClass();
     }
     if ($page->isActive(true)) {
         $liClasses[] = $this->getLiActiveClass();
     }
     return $escaper(implode(' ', $liClasses));
 }
 /**
  * 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 AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page               page to generate HTML for
  * @param  bool         $escapeLabel        Whether or not to escape the label
  * @param  bool         $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $page->getTitle());
     if ($addClassToListItem === false) {
         $attribs['class'] = $page->getClass();
     }
     // does page have a href?
     $href = $page->getHref();
     if ('#' !== $href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     $label = $page->getLabel();
     //$this->translate(, $page->getTextDomain());
     if ($escapeLabel === true) {
         /** @var \Zend\View\Helper\EscapeHtml $escaper */
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }
Esempio n. 8
0
 public function testShouldFailIfUnableToDetermineType()
 {
     try {
         $page = AbstractPage::factory(array('label' => 'My Invalid Page'));
     } catch (Navigation\Exception\InvalidArgumentException $e) {
         return;
     }
     $this->fail('An exception has not been thrown for invalid page type');
 }
 /**
  * Get the feed list and the posts of the feed we are looking at now
  *
  * @return void
  */
 public function indexAction()
 {
     $viewData = array();
     $flashMessenger = $this->flashMessenger();
     $username = $this->params()->fromRoute('username');
     $currentFeedId = $this->params()->fromRoute('feed_id');
     $userData = ApiClient::getUser($username);
     if ($userData !== FALSE) {
         $hydrator = new ClassMethods();
         $user = $hydrator->hydrate($userData, new User());
     } else {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $subscribeForm = new SubscribeForm();
     $unsubscribeForm = new UnsubscribeForm();
     $subscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-subscribe', array('username' => $username)));
     $unsubscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-unsubscribe', array('username' => $username)));
     $hydrator = new ClassMethods();
     $response = ApiClient::getFeeds($username);
     $feeds = array();
     foreach ($response as $r) {
         $feeds[$r['id']] = $hydrator->hydrate($r, new Feed());
     }
     if ($currentFeedId === null && !empty($feeds)) {
         $currentFeedId = reset($feeds)->getId();
     }
     $feedsMenu = new Navigation();
     $router = $this->getEvent()->getRouter();
     $routeMatch = $this->getEvent()->getRouteMatch()->setParam('feed_id', $currentFeedId);
     foreach ($feeds as $f) {
         $feedsMenu->addPage(AbstractPage::factory(array('title' => $f->getTitle(), 'icon' => $f->getIcon(), 'route' => 'feeds', 'routeMatch' => $routeMatch, 'router' => $router, 'params' => array('username' => $username, 'feed_id' => $f->getId()))));
     }
     $currentFeed = $currentFeedId != null ? $feeds[$currentFeedId] : null;
     if ($currentFeed != null) {
         $paginator = new Paginator(new ArrayAdapter($currentFeed->getArticles()));
         $paginator->setItemCountPerPage(5);
         $paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
         $viewData['paginator'] = $paginator;
         $viewData['feedId'] = $currentFeedId;
     }
     $unsubscribeForm->get('feed_id')->setValue($currentFeedId);
     $viewData['subscribeForm'] = $subscribeForm;
     $viewData['unsubscribeForm'] = $unsubscribeForm;
     $viewData['username'] = $username;
     $viewData['feedsMenu'] = $feedsMenu;
     $viewData['user'] = $user;
     $viewData['paginator'] = $paginator;
     $viewData['feedId'] = $currentFeedId;
     $viewData['feed'] = $currentFeed;
     $this->layout()->username = $username;
     if ($flashMessenger->hasMessages()) {
         $viewData['flashMessages'] = $flashMessenger->getMessages();
     }
     return $viewData;
 }
Esempio n. 10
0
 /**
  * @override htmlify from the parent/base/super class
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // !!! This method will be executed in the namespace of the class
     // !!! But the methods of the super/base class will be executed in its own namespace
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $title);
     $attribs['class'] = '';
     if ($addClassToListItem === false) {
         $attribs['class'] = $page->getClass();
     }
     // Stoyan
     $attribs['class'] .= $attribs['class'] ? ' ' : '';
     $attribs['class'] .= $page->getAnchorClass();
     //		echo 'Menu<pre>';
     //		echo 'Class: ' . $page->getClass();
     //		echo 'Anchor Class: ' . $page->getAnchorClass();
     //		print_r($attribs);
     //		echo '</pre>';
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }
Esempio n. 11
0
 /**
  * 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  AbstractPage $page  page to check
  * @return bool                whether page is accepted by ACL
  */
 protected function acceptAcl(AbstractPage $page)
 {
     if (!($acl = $this->getAcl())) {
         // no acl registered means don't use acl
         return true;
     }
     $role = $this->getRole();
     $roles = $this->getRoles();
     $resource = $page->getResource();
     $privilege = $page->getPrivilege();
     if (!$roles) {
         $roles = array($roles);
     }
     if ($resource || $privilege) {
         foreach ($roles as $r) {
             // determine using helper role and page resource/privilege
             return $acl->hasResource($resource) && $acl->isAllowed($r, $resource);
         }
         return false;
     }
     return true;
 }
Esempio n. 12
0
 public function testGetChildrenShouldReturnTheCurrentPage()
 {
     $container = new Navigation\Navigation();
     $page = Page\AbstractPage::factory(array('type' => 'uri'));
     $container->addPage($page);
     $this->assertEquals($page, $container->getChildren());
 }
Esempio n. 13
0
 /**
  * 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 AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page   page to generate HTML for
  * @param bool $escapeLabel     Whether or not to escape the label
  * @return string               HTML string for the given page
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass());
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }
Esempio n. 14
0
 /**
  * Checks if the container has the given page
  *
  * @param  Page\AbstractPage $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(Page\AbstractPage $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;
 }
Esempio n. 15
0
 /**
  * Returns an HTML string containing an 'a' element for the given page
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @return string
  */
 public function htmlify(AbstractPage $page)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for anchor element
     $attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass(), 'href' => $page->getHref(), 'target' => $page->getTarget());
     $escaper = $this->view->plugin('escapeHtml');
     return '<a' . $this->htmlAttribs($attribs) . '>' . $escaper($label) . '</a>';
 }
Esempio n. 16
0
 public function testAclFiltersAwayPagesFromPageProperty()
 {
     $acl = new Acl\Acl();
     $acl->addRole(new Role\GenericRole('member'));
     $acl->addRole(new Role\GenericRole('admin'));
     $acl->addResource(new Resource\GenericResource('protected'));
     $acl->allow('admin', 'protected');
     $this->_helper->setAcl($acl);
     $this->_helper->setRole($acl->getRole('member'));
     $samplePage = AbstractPage::factory(array('label' => 'An example page', 'uri' => 'http://www.example.com/', 'resource' => 'protected'));
     $active = $this->_helper->findOneByLabel('Home');
     $expected = array('alternate' => false, 'stylesheet' => false, 'start' => false, 'next' => 'Page 1', 'prev' => false, 'contents' => false, 'index' => false, 'glossary' => false, 'copyright' => false, 'chapter' => 'array(4)', 'section' => false, 'subsection' => false, 'appendix' => false, 'help' => false, 'bookmark' => false);
     $actual = array();
     foreach ($expected as $type => $discard) {
         $active->addRel($type, $samplePage);
         $found = $this->_helper->findRelation($active, 'rel', $type);
         if (null === $found) {
             $actual[$type] = false;
         } elseif (is_array($found)) {
             $actual[$type] = 'array(' . count($found) . ')';
         } else {
             $actual[$type] = $found->getLabel();
         }
     }
     $this->assertEquals($expected, $actual);
 }
 /**
  * Returns an HTML string of page label with icon support.
  *
  * @param  AbstractPage $page page to generate HTML for
  * @param  bool $escapeLabel Whether or not to escape the label
  * @return string
  */
 public function htmlifyLabel(AbstractPage $page, $escapeLabel = true, $isTreeView = false)
 {
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     if ($escapeLabel) {
         /** @var \Zend\View\Helper\EscapeHtml $escaper */
         $escaper = $this->view->plugin('escapeHtml');
         $label = $escaper($label);
     }
     $label = '<span>' . $label . '</span>';
     if (isset($page->icon)) {
         $attribs = array('class' => 'fa fa-' . $page->icon);
         $label = '<i ' . $this->htmlAttribs($attribs) . '></i> ' . $label;
     }
     if ($isTreeView) {
         $label .= '<i class="fa fa-angle-left pull-right"></i>';
     }
     return $label;
 }
Esempio n. 18
0
 public function testToArrayMethod()
 {
     $options = array('label' => 'foo', 'uri' => 'http://www.example.com/foo.html', 'fragment' => 'bar', 'id' => 'my-id', 'class' => 'my-class', 'title' => 'my-title', 'target' => 'my-target', 'rel' => array(), 'rev' => array(), 'order' => 100, 'active' => true, 'visible' => false, 'resource' => 'joker', 'privilege' => null, 'foo' => 'bar', 'meaning' => 42, 'pages' => array(array('label' => 'foo.bar', 'uri' => 'http://www.example.com/foo.html'), array('label' => 'foo.baz', 'uri' => 'http://www.example.com/foo.html')));
     $page = AbstractPage::factory($options);
     $toArray = $page->toArray();
     // tweak options to what we expect toArray() to contain
     $options['type'] = 'Zend\\Navigation\\Page\\Uri';
     // calculate diff between toArray() and $options
     $diff = array_diff_assoc($toArray, $options);
     // should be no diff
     $this->assertEquals(array(), $diff);
     // $toArray should have 2 sub pages
     $this->assertEquals(2, count($toArray['pages']));
     // tweak options to what we expect sub page 1 to be
     $options['label'] = 'foo.bar';
     $options['fragment'] = null;
     $options['order'] = null;
     $options['id'] = null;
     $options['class'] = null;
     $options['title'] = null;
     $options['target'] = null;
     $options['resource'] = null;
     $options['active'] = false;
     $options['visible'] = true;
     unset($options['foo']);
     unset($options['meaning']);
     // assert that there is no diff from what we expect
     $subPageOneDiff = array_diff_assoc($toArray['pages'][0], $options);
     $this->assertEquals(array(), $subPageOneDiff);
     // tweak options to what we expect sub page 2 to be
     $options['label'] = 'foo.baz';
     // assert that there is no diff from what we expect
     $subPageTwoDiff = array_diff_assoc($toArray['pages'][1], $options);
     $this->assertEquals(array(), $subPageTwoDiff);
 }
Esempio n. 19
0
 /**
  * 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 AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page page to generate HTML for
  * @param  bool $escapeLabel Whether or not to escape the label
  * @param  bool $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $addonLeft = $page->get('addon-left');
     $addonRight = $page->get('addon-right');
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = ['id' => $page->getId(), 'title' => $title];
     // add additional attributes
     $attr = $page->get('attribs');
     if (is_array($attr)) {
         $attribs = $attribs + $attr;
     }
     //if ($addClassToListItem === false) {
     $attribs['class'] = $page->getClass();
     //}
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($addonLeft) {
         $html .= $addonLeft;
     }
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     if ($addonRight) {
         $html .= $addonRight;
     }
     $html .= '</' . $element . '>';
     return $html;
 }
Esempio n. 20
0
 public function testToArrayMethod()
 {
     $options = array('label' => 'foo', 'uri' => 'http://www.example.com/foo.html', 'fragment' => 'bar', 'id' => 'my-id', 'class' => 'my-class', 'title' => 'my-title', 'target' => 'my-target', 'rel' => array(), 'rev' => array(), 'order' => 100, 'active' => true, 'visible' => false, 'resource' => 'joker', 'privilege' => null, 'foo' => 'bar', 'meaning' => 42, 'pages' => array(array('type' => 'Zend\\Navigation\\Page\\Uri', 'label' => 'foo.bar', 'fragment' => null, 'id' => null, 'class' => null, 'title' => null, 'target' => null, 'rel' => array(), 'rev' => array(), 'order' => null, 'resource' => null, 'privilege' => null, 'active' => null, 'visible' => 1, 'pages' => array(), 'uri' => 'http://www.example.com/foo.html'), array('label' => 'foo.baz', 'type' => 'Zend\\Navigation\\Page\\Uri', 'label' => 'foo.bar', 'fragment' => null, 'id' => null, 'class' => null, 'title' => null, 'target' => null, 'rel' => array(), 'rev' => array(), 'order' => null, 'resource' => null, 'privilege' => null, 'active' => null, 'visible' => 1, 'pages' => array(), 'uri' => 'http://www.example.com/foo.html')));
     $page = AbstractPage::factory($options);
     $toArray = $page->toArray();
     // tweak options to what we expect toArray() to contain
     $options['type'] = 'Zend\\Navigation\\Page\\Uri';
     ksort($options);
     ksort($toArray);
     $this->assertEquals($options, $toArray);
 }
Esempio n. 21
0
 /**
  * Converts a $mixed value to an array of pages
  *
  * @param  mixed $mixed     mixed value to get page(s) from
  * @param  bool  $recursive whether $value should be looped
  *                          if it is an array or a config
  * @return AbstractPage|array|null
  */
 protected function convertToPages($mixed, $recursive = true)
 {
     if ($mixed instanceof AbstractPage) {
         // value is a page instance; return directly
         return $mixed;
     } elseif ($mixed instanceof AbstractContainer) {
         // value is a container; return pages in it
         $pages = array();
         foreach ($mixed as $page) {
             $pages[] = $page;
         }
         return $pages;
     } elseif ($mixed instanceof Traversable) {
         $mixed = ArrayUtils::iteratorToArray($mixed);
     } elseif (is_string($mixed)) {
         // value is a string; make an URI page
         return AbstractPage::factory(array('type' => 'uri', 'uri' => $mixed));
     }
     if (is_array($mixed) && !empty($mixed)) {
         if ($recursive && is_numeric(key($mixed))) {
             // first key is numeric; assume several pages
             $pages = array();
             foreach ($mixed as $value) {
                 $value = $this->convertToPages($value, false);
                 if ($value) {
                     $pages[] = $value;
                 }
             }
             return $pages;
         } else {
             // pass array to factory directly
             try {
                 $page = AbstractPage::factory($mixed);
                 return $page;
             } catch (\Exception $e) {
             }
         }
     }
     // nothing found
     return null;
 }
 protected function renderDropdown(\Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array())
 {
     $class = $page->getClass();
     $this->addWord('btn', $class);
     if ($page->isActive(true)) {
         $this->addWord('active', $class);
     }
     $page->setClass($class);
     $html = parent::renderDropdown($page, $renderIcons, $activeIconInverse, $options);
     return $html;
 }
Esempio n. 23
0
 /**
  * Returns an HTML string containing an 'a' element for the given page
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @return string              HTML string (<a href="…">Label</a>)
  */
 public function htmlify(AbstractPage $page)
 {
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     $title = $this->translate($page->getTitle(), $page->getTextDomain());
     // get attribs for anchor element
     $attribs = ['id' => $page->getId(), 'title' => $title, 'class' => $page->getClass(), 'href' => $page->getHref(), 'target' => $page->getTarget()];
     /** @var \Zend\View\Helper\EscapeHtml $escaper */
     $escaper = $this->view->plugin('escapeHtml');
     $label = $escaper($label);
     return '<a' . $this->htmlAttribs($attribs) . '>' . $label . '</a>';
 }
Esempio n. 24
0
 /**
  * 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(), 'params' => $this->getParams(), 'route' => $this->getRoute()));
 }
Esempio n. 25
0
 /**
  * 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 AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @return string              HTML string for the given page
  */
 public function htmlify(AbstractPage $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, 'class' => $page->getClass());
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $escaper = $this->view->plugin('escapeHtml');
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $escaper($label) . '</' . $element . '>';
 }
Esempio n. 26
0
 /**
  * Returns an array representation of the page
  *
  * @return array
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), array('uri' => $this->getUri()));
 }
Esempio n. 27
0
 public function renderNavbar(\Zend\Navigation\Navigation $container = null, $leftElements = null, $rightElements = null, \Zend\Navigation\Page\AbstractPage $brandLink = null, $brandName = null, $fixed = true, $fixedBottom = false, $responsive = true, $renderIcons = true, $inverse = false)
 {
     if (null === $container) {
         $container = $this->getContainer();
     }
     if ($leftElements && !is_array($leftElements)) {
         $leftElements = array($leftElements);
     }
     if ($rightElements && !is_array($rightElements)) {
         $rightElements = array($rightElements);
     }
     $html = '';
     //Navbar scaffolding
     $navbarClass = 'navbar';
     if ($fixed) {
         if ($fixedBottom) {
             $navbarClass .= ' navbar-fixed-bottom';
         } else {
             $navbarClass .= ' navbar-fixed-top';
         }
     }
     if ($inverse) {
         $navbarClass .= ' navbar-inverse';
     }
     $html .= '<div class="' . $navbarClass . '">';
     $html .= "\n" . '<div class="navbar-inner">';
     $html .= "\n" . '<div class="container">';
     //Responsive (button)
     if ($responsive) {
         $html .= "\n" . '<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">';
         $html .= "\n" . '<span class="icon-bar"></span>';
         $html .= "\n" . '<span class="icon-bar"></span>';
         $html .= "\n" . '<span class="icon-bar"></span>';
         $html .= "\n" . '</a>';
     }
     //Brand
     if ($brandLink) {
         $view = $this->getView();
         if ($brandName) {
             $brandName = $view->escapeHtml($brandName);
         } else {
             $brandName = $view->escapeHtml($brandLink->getLabel());
         }
         $html .= "\n" . '<a class="brand" href="' . $brandLink->getHref() . '">' . $brandName . '</a>';
     }
     //Responsive (div)
     if ($responsive) {
         $html .= "\n" . '<div class="nav-collapse">';
     }
     //Primary container
     $options = array('align' => null, 'ulClass' => 'nav');
     $html .= "\n" . $this->renderContainer($container, $renderIcons, true, $options);
     //Left elements
     if ($leftElements) {
         $html .= "\n" . $this->renderElements($leftElements, 'left', $renderIcons);
     }
     //Right elements
     if ($rightElements) {
         $html .= "\n" . $this->renderElements($rightElements, 'right', $renderIcons);
     }
     //Responsive (close div)
     if ($responsive) {
         $html .= "\n" . '</div>';
     }
     //Scaffolding (close divs)
     $html .= "\n</div>";
     $html .= "\n</div>";
     $html .= "\n</div>";
     return $html;
 }
Esempio n. 28
0
 /**
  * This is a rewrite of the parent classes version that should be mostly compatable
  * while adding functionality for Twitter Bootstrap.
  * 
  * Returns an HTML string containing an 'a' element for the given page.
  *
  * Overrides {@link AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page               page to generate HTML for
  * @param  bool         $escapeLabel        Whether or not to escape the label
  * @param  bool         $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false, $attribs = array())
 {
     // Set attributes
     $pageAttribs = array('id' => $page->getId(), 'title' => $this->translate($page->getTitle(), $page->getTextDomain()));
     if ($addClassToListItem === false) {
         if (key_exists('class', $attribs)) {
             $attribs['class'] .= ' ' . $page->getClass();
         } else {
             $pageAttribs['class'] = $page->getClass();
         }
     }
     if ($page->getHref()) {
         $pageAttribs['href'] = $page->getHref();
         $pageAttribs['target'] = $page->getTarget();
     } else {
         $pageAttribs['href'] = "#";
     }
     // Merge attributes from the page with passed attributs
     // if two attributes conflict, passed attributes should win.
     $attribs = array_merge($pageAttribs, $attribs);
     // Convert attributes array into a string of HTML/XML attributes
     $attributesString = "";
     foreach ($attribs as $key => $value) {
         if (!($value === null || is_string($value) && !strlen($value))) {
             $attributesString .= "{$key}='{$value}' ";
         }
     }
     // Set Label
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     if ($escapeLabel === true) {
         /** @var \Zend\View\Helper\EscapeHtml $escaper */
         $escaper = $this->view->plugin('escapeHtml');
         $label = $escaper($label);
     }
     $html = "<a {$attributesString}>{$label}</a>";
     return $html;
 }
Esempio n. 29
0
 /**
  * Returns an escaped absolute URL for the given page
  *
  * @param  AbstractPage $page
  * @return string
  */
 public function url(AbstractPage $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
         $basePathHelper = $this->getView()->plugin('basepath');
         $curDoc = $basePathHelper();
         $curDoc = '/' == $curDoc ? '' : trim($curDoc, '/');
         $url = rtrim($this->getServerUrl(), '/') . '/' . $curDoc . (empty($curDoc) ? '' : '/') . $href;
     }
     if (!in_array($url, $this->urls)) {
         $this->urls[] = $url;
         return $this->xmlEscape($url);
     }
     return null;
 }
Esempio n. 30
0
 /**
  * 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 AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page               page to generate HTML for
  * @param  bool         $escapeLabel        Whether or not to escape the label
  * @param  bool         $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $element = 'a';
     $extended = '';
     $attribs = array('id' => $page->getId(), 'title' => $title, 'href' => '#');
     $class = array();
     if ($addClassToListItem === false) {
         $class[] = $page->getClass();
     }
     if ($page->isDropdown) {
         $attribs['data-toggle'] = 'dropdown';
         $class[] = 'dropdown-toggle';
         $extended = ' <b class="caret"></b>';
     }
     if (count($class) > 0) {
         $attribs['class'] = implode(' ', $class);
     }
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= $extended;
     $html .= '</' . $element . '>';
     return $html;
 }