Example #1
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 Zend_View_Helper_Navigation_Abstract::htmlify()}.
  *
  * @param  Zend_Navigation_Page $page  page to generate HTML for
  * @return string                      HTML string for the given page
  */
 public function htmlify(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_merge($page->getCustomProperties(), array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass()));
     // does page have a href?
     if ($href = $page->getHref()) {
         if ($page->isActive()) {
             if ($attribs['class'] != '') {
                 $attribs['class'] .= ' ';
             }
             $attribs['class'] .= 'ui-btn-active';
         }
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
         $attribs['accesskey'] = $page->getAccessKey();
     } else {
         $element = 'span';
     }
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $this->view->escape($label) . '</' . $element . '>';
 }
Example #2
0
 /**
  * Recursively add pages to the container
  * 
  * @param Zoo_Object_Tree $tree
  * @param Zend_Navigation_Container $container
  * @param int $key
  * @return void
  */
 function treeToPageContainer(&$tree, Zend_Navigation_Page $container, $key = 0)
 {
     $children = $tree->getFirstChild($key);
     foreach ($children as $child) {
         $page = $this->nodeToPage($child);
         $container->addPage($page);
         $this->treeToPageContainer($tree, $page, $child->id);
     }
 }
Example #3
0
 function getLiClass(Zend_Navigation_Page $subPage, $isActive)
 {
     if ($isActive && $this->_activeClass) {
         return ' class="' . $this->_activeClass . '"';
     }
     if ($subPage->get('disabled') && $this->_disabledClass) {
         return ' class="' . $this->_disabledClass . '"';
     }
     if ($this->_normalClass) {
         return ' class="' . $this->_normalClass . '"';
     }
 }
Example #4
0
 public function _getHtmlLabel(Zend_Navigation_Page $page)
 {
     // get label and title for translating
     $label = $page->getLabel();
     // translate label and title?
     if ($this->getUseTranslator() && ($t = $this->getTranslator())) {
         if (is_string($label) && !empty($label)) {
             $label = $t->translate($label);
         }
     }
     return $this->view->escape($label);
 }
Example #5
0
 function addDefaultPages()
 {
     $separator = new Am_Navigation_Admin_Item_Separator();
     $this->addPage(array('id' => 'dashboard', 'controller' => 'admin', 'label' => ___('Dashboard')));
     $this->addPage(Zend_Navigation_Page::factory(array('id' => 'users', 'uri' => '#', 'label' => ___('Users'), 'resource' => 'grid_u', 'privilege' => 'browse', 'pages' => array_merge(array(array('id' => 'users-browse', 'controller' => 'admin-users', 'label' => ___('Browse Users'), 'resource' => 'grid_u', 'privilege' => 'browse', 'class' => 'bold'), array('id' => 'users-insert', 'uri' => REL_ROOT_URL . '/admin-users?_u_a=insert', 'label' => ___('Add User'), 'resource' => 'grid_u', 'privilege' => 'insert')), !Am_Di::getInstance()->config->get('manually_approve') ? array() : array(array('id' => 'user-not-approved', 'controller' => 'admin-users', 'action' => 'not-approved', 'label' => ___('Not Approved Users'), 'resource' => 'grid_u', 'privilege' => 'browse')), array(array('id' => 'users-email', 'controller' => 'admin-email', 'label' => ___('E-Mail Users'), 'resource' => Am_Auth_Admin::PERM_EMAIL), clone $separator, array('id' => 'users-import', 'controller' => 'admin-import', 'label' => ___('Import Users'), 'resource' => Am_Auth_Admin::PERM_IMPORT))))));
     $this->addPage(array('id' => 'reports', 'uri' => '#', 'label' => ___('Reports'), 'pages' => array(array('id' => 'reports-reports', 'controller' => 'admin-reports', 'label' => ___('Reports'), 'resource' => Am_Auth_Admin::PERM_REPORT), array('id' => 'reports-payments', 'type' => 'Am_Navigation_Page_Mvc', 'controller' => 'admin-payments', 'label' => ___('Payments'), 'resource' => array('grid_payment', 'grid_invoice')))));
     $this->addPage(array('id' => 'products', 'uri' => '#', 'label' => ___('Products'), 'pages' => array_filter(array(array('id' => 'products-manage', 'controller' => 'admin-products', 'label' => ___('Manage Products'), 'resource' => 'grid_product', 'class' => 'bold'), array('id' => 'products-coupons', 'controller' => 'admin-coupons', 'label' => ___('Coupons'), 'resource' => 'grid_coupon')))));
     /**
      *  Temporary disable this menu if user is on upgrade controller in order to avoid error: 
      *  Fatal error: Class Folder contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (ResourceAbstract::getAccessType)
      *  
      *   @todo Remove this in the future;
      * 
      */
     $content_pages = array();
     if (Zend_Controller_Front::getInstance()->getRequest()->getControllerName() != 'admin-upgrade') {
         foreach (Am_Di::getInstance()->resourceAccessTable->getAccessTables() as $t) {
             $k = $t->getPageId();
             $content_pages[] = array('id' => 'content-' . $k, 'module' => 'default', 'controller' => 'admin-content', 'action' => 'index', 'label' => $t->getAccessTitle(), 'resource' => 'grid_content', 'params' => array('page_id' => $k), 'route' => 'inside-pages');
         }
     }
     $this->addPage(array('id' => 'content', 'controller' => 'admin-content', 'label' => ___('Protect Content'), 'resource' => 'grid_content', 'class' => 'bold', 'pages' => $content_pages));
     $this->addPage(array('id' => 'configuration', 'uri' => '#', 'label' => ___('Configuration'), 'pages' => array_filter(array(array('id' => 'setup', 'controller' => 'admin-setup', 'label' => ___('Setup/Configuration'), 'resource' => Am_Auth_Admin::PERM_SETUP, 'class' => 'bold'), array('id' => 'saved-form', 'controller' => 'admin-saved-form', 'label' => ___('Forms Editor'), 'resource' => @constant('Am_Auth_Admin::PERM_FORM'), 'class' => 'bold'), array('id' => 'fields', 'controller' => 'admin-fields', 'label' => ___('Add User Fields'), 'resource' => @constant('Am_Auth_Admin::PERM_ADD_USER_FIELD')), array('id' => 'email-template-layout', 'controller' => 'admin-email-template-layout', 'label' => ___('Email Layouts'), 'resource' => Am_Auth_Admin::PERM_SETUP), array('id' => 'ban', 'controller' => 'admin-ban', 'label' => ___('Blocking IP/E-Mail'), 'resource' => @constant('Am_Auth_Admin::PERM_BAN')), array('id' => 'countries', 'controller' => 'admin-countries', 'label' => ___('Countries/States'), 'resource' => @constant('Am_Auth_Admin::PERM_COUNTRY_STATE')), array('id' => 'admins', 'controller' => 'admin-admins', 'label' => ___('Admin Accounts'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('id' => 'change-pass', 'controller' => 'admin-change-pass', 'label' => ___('Change Password'))))));
     $this->addPage(array('id' => 'utilites', 'uri' => '#', 'label' => ___('Utilities'), 'order' => 1000, 'pages' => array_filter(array(Am_Di::getInstance()->modules->isEnabled('cc') ? null : array('id' => 'backup', 'controller' => 'admin-backup', 'label' => ___('Backup'), 'resource' => Am_Auth_Admin::PERM_BACKUP_RESTORE), Am_Di::getInstance()->modules->isEnabled('cc') ? null : array('id' => 'restore', 'controller' => 'admin-restore', 'label' => ___('Restore'), 'resource' => Am_Auth_Admin::PERM_BACKUP_RESTORE), array('id' => 'rebuild', 'controller' => 'admin-rebuild', 'label' => ___('Rebuild Db'), 'resource' => @constant('Am_Auth_Admin::PERM_REBUILD_DB')), clone $separator, array('id' => 'logs', 'type' => 'Am_Navigation_Page_Mvc', 'controller' => 'admin-logs', 'label' => ___('Logs'), 'resource' => array(@constant('Am_Auth_Admin::PERM_LOGS'), @constant('Am_Auth_Admin::PERM_LOGS_ACCESS'), @constant('Am_Auth_Admin::PERM_LOGS_INVOICE'), @constant('Am_Auth_Admin::PERM_LOGS_MAIL'), @constant('Am_Auth_Admin::PERM_LOGS_ADMIN'))), array('id' => 'info', 'controller' => 'admin-info', 'label' => ___('System Info'), 'resource' => @constant('Am_Auth_Admin::PERM_SYSTEM_INFO')), clone $separator, array('id' => 'trans-global', 'controller' => 'admin-trans-global', 'label' => ___('Edit Messages'), 'resource' => @constant('Am_Auth_Admin::PERM_TRANSLATION')), array('id' => 'clear', 'controller' => 'admin-clear', 'label' => ___('Delete Old Records'), 'resource' => @constant('Am_Auth_Admin::PERM_CLEAR')), array('id' => 'build-demo', 'controller' => 'admin-build-demo', 'label' => ___('Build Demo'), 'resource' => @constant('Am_Auth_Admin::PERM_BUILD_DEMO'))))));
     $this->addPage(array('id' => 'help', 'uri' => '#', 'label' => ___('Help & Support'), 'order' => 1001, 'pages' => array_filter(array(array('id' => 'documentation', 'uri' => 'http://www.amember.com/docs/', 'target' => '_blank', 'label' => ___('Documentation')), array('id' => 'report-bugs', 'uri' => 'http://bt.amember.com/', 'target' => '_blank', 'label' => ___('Report Bugs'))))));
     Am_Di::getInstance()->hook->call(Am_Event::ADMIN_MENU, array('menu' => $this));
     /// workaround against using the current route for generating urls
     foreach (new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST) as $child) {
         if ($child instanceof Zend_Navigation_Page_Mvc && $child->getRoute() === null) {
             $child->setRoute('default');
         }
     }
 }
Example #6
0
 public function toXtype(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(), 'text' => $label, 'iconCls' => $page->get('iconClass'), 'cls' => $page->getClass());
     // does page have a href?
     if ($href = $page->getHref()) {
         $attribs['href'] = $href;
         $attribs['hrefTarget'] = $page->getTarget();
     }
     foreach ($attribs as $key => &$attr) {
         if (empty($attr)) {
             unset($attribs[$key]);
         }
     }
     return $attribs;
 }
Example #7
0
 function getLiClass(Zend_Navigation_Page $subPage, $isActive)
 {
     $class = '';
     if ($isActive && $this->_activeClass) {
         $class .= $this->_activeClass . ' ';
     } elseif ($subPage->get('disabled') && $this->_disabledClass) {
         $class .= $this->_disabledClass . ' ';
     } elseif ($this->_normalClass) {
         $class .= $this->_normalClass . ' ';
     }
     if ($subPage->hasChildren()) {
         $class .= $this->_hasChildrenClass . ' ';
     }
     if ($class = trim($class)) {
         return " class=\"{$class}\"";
     }
 }
Example #8
0
 public function htmlify(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, 'class' => $page->getClass());
     // does page have a href?
     if ($href = $page->getHref()) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     // dodanie ikonki
     if (null !== $page->icon) {
         $icon = '<img src="' . $this->view->baseUrl() . $this->_iconPath . '/' . $page->icon . '" alt="" /> ';
     } else {
         $icon = '';
     }
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $icon . $this->view->escape($label) . '</' . $element . '>';
 }
Example #9
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 Zend_View_Helper_Navigation_Abstract::htmlify()}.
  *
  * @param  Zend_Navigation_Page $page  page to generate HTML for
  * @return string                      HTML string for the given page
  */
 public function htmlify(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, 'class' => $page->getClass());
     // does page have a href?
     if ($href = $page->getHref()) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $label . '</' . $element . '>';
 }
 public function buildAdminNav()
 {
     $identity = Zend_Auth::getInstance()->getIdentity()->toArray();
     if ($identity['role'] === 'Root') {
         $visible = false;
     } else {
         $visible = false;
     }
     $pages = array(Zend_Navigation_Page::factory(array('label' => 'Accounts', 'action' => 'index', 'controller' => 'modify', 'module' => 'accounts', 'route' => 'admin', 'id' => 'accounts', 'order' => 990, 'visible' => $visible, 'resource' => new Accounts_Model_Acl_Resource_Accounts(), 'pages' => array(Zend_Navigation_Page::factory(array('label' => 'Create Account', 'action' => 'index', 'controller' => 'create', 'module' => 'accounts', 'route' => 'admin')), Zend_Navigation_Page::factory(array('label' => 'Modify Account', 'action' => 'index', 'controller' => 'modify', 'module' => 'accounts', 'route' => 'admin'))))));
     return $pages;
 }
 /**
  *Takes the module menus and converts them to Zend_Navigation_Page
  * @param array $sections
  * @param array $moduleMenus
  * @param array $menus
  * @return
  */
 function getModulePages($sections, $moduleMenus, &$menus)
 {
     foreach ($sections as $section) {
         if (isset($moduleMenus[$section])) {
             foreach ($moduleMenus[$section] as $title => $mvc) {
                 $mvc['label'] = $title;
                 $menus[] = Zend_Navigation_Page::factory($mvc);
             }
         }
     }
     return $menus;
 }
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return Zend_Navigation
  */
 public function init()
 {
     if (!$this->_container) {
         $options = $this->getOptions();
         $pages = isset($options['pages']) ? $options['pages'] : array();
         $this->_container = new Zend_Navigation($pages);
         if (isset($options['defaultPageType'])) {
             Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']);
         }
     }
     $this->store();
     return $this->_container;
 }
 public function tearDown()
 {
     Zend_Navigation_Page::setDefaultPageType();
     // Restore original autoloaders
     $loaders = spl_autoload_functions();
     foreach ($loaders as $loader) {
         spl_autoload_unregister($loader);
     }
     foreach ($this->loaders as $loader) {
         spl_autoload_register($loader);
     }
     // Reset autoloader instance so it doesn't affect other tests
     Zend_Loader_Autoloader::resetInstance();
 }
Example #14
0
 function addDefaultPages()
 {
     $separator = new Am_Navigation_Admin_Item_Separator();
     $this->addPage(array('id' => 'dashboard', 'controller' => 'admin', 'label' => ___("Dashboard")));
     $this->addPage(Zend_Navigation_Page::factory(array('id' => 'users', 'uri' => '#', 'label' => ___("Users"), 'resource' => 'grid_u', 'privilege' => 'browse', 'pages' => array_merge(array(array('id' => 'users-browse', 'controller' => 'admin-users', 'label' => ___('Browse Users'), 'resource' => 'grid_u', 'privilege' => 'browse', 'class' => 'bold'), array('id' => 'users-insert', 'uri' => REL_ROOT_URL . '/admin-users?_u_a=insert', 'label' => ___('Add User'), 'resource' => 'grid_u', 'privilege' => 'insert')), !Am_Di::getInstance()->config->get('manually_approve') ? array() : array(array('id' => 'user-not-approved', 'controller' => 'admin-users', 'action' => 'not-approved', 'label' => ___('Not Approved Users'), 'resource' => 'grid_u', 'privilege' => 'browse')), array(array('id' => 'users-email', 'controller' => 'admin-email', 'label' => ___('E-Mail Users'), 'resource' => Am_Auth_Admin::PERM_EMAIL), clone $separator, array('id' => 'users-import', 'controller' => 'admin-import', 'label' => ___('Import Users'), 'resource' => Am_Auth_Admin::PERM_IMPORT))))));
     $this->addPage(array('id' => 'reports', 'uri' => '#', 'label' => ___("Reports"), 'pages' => array(array('id' => 'reports-reports', 'controller' => 'admin-reports', 'label' => ___('Reports'), 'resource' => Am_Auth_Admin::PERM_REPORT), array('id' => 'reports-payments', 'controller' => 'admin-payments', 'label' => ___('Payments'), 'resource' => Am_Auth_Admin::PERM_REPORT))));
     $this->addPage(array('id' => 'products', 'uri' => '#', 'label' => ___('Products'), 'pages' => array_filter(array(array('id' => 'products-manage', 'controller' => 'admin-products', 'label' => ___('Manage Products'), 'resource' => 'grid_product', 'class' => 'bold'), array('id' => 'products-protect', 'controller' => 'admin-content', 'label' => ___('Protect Content'), 'resource' => 'grid_content', 'class' => 'bold'), array('id' => 'products-coupons', 'controller' => 'admin-coupons', 'label' => ___('Coupons'), 'resource' => 'grid_coupon')))));
     $this->addPage(array('id' => 'configuration', 'uri' => '#', 'label' => ___('Configuration'), 'pages' => array_filter(array(array('controller' => 'admin-setup', 'label' => ___('Setup/Configuration'), 'resource' => Am_Auth_Admin::PERM_SETUP, 'class' => 'bold'), array('controller' => 'admin-tax', 'label' => ___('Tax Settings'), 'resource' => Am_Auth_Admin::PERM_SETUP), array('controller' => 'admin-fields', 'label' => ___('Add Fields'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-admins', 'label' => ___('Admin Accounts'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-saved-form', 'label' => ___('Forms Editor'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-ban', 'label' => ___('Blocking IP/E-Mail'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-change-pass', 'label' => ___('Change Password'))))));
     $this->addPage(array('id' => 'utilites', 'uri' => '#', 'label' => ___('Utilites'), 'order' => 1000, 'pages' => array_filter(array(array('controller' => 'admin-backup', 'label' => ___('Backup'), 'resource' => Am_Auth_Admin::PERM_BACKUP_RESTORE), array('controller' => 'admin-restore', 'label' => ___('Restore'), 'resource' => Am_Auth_Admin::PERM_BACKUP_RESTORE), array('controller' => 'admin-rebuild', 'label' => ___('Rebuild Db'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), clone $separator, array('controller' => 'admin-logs', 'label' => ___('Logs'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-info', 'label' => ___('Version Info'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), clone $separator, array('controller' => 'admin-clear', 'label' => ___('Delete Old Records'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER), array('controller' => 'admin-build-demo', 'label' => ___('Build Demo'), 'resource' => Am_Auth_Admin::PERM_SUPER_USER)))));
     $this->addPage(array('id' => 'help', 'uri' => '#', 'label' => ___('Help & Support'), 'pages' => array_filter(array(array('uri' => 'http://www.amember.com/docs/', 'label' => ___('Documentation')), array('uri' => 'http://bt.amember.com/', 'label' => ___('Report Bugs'))))));
     Am_Di::getInstance()->hook->call(Am_Event::ADMIN_MENU, array('menu' => $this));
     /// workaround against using the current route for generating urls
     foreach (new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST) as $child) {
         if ($child instanceof Zend_Navigation_Page_Mvc && $child->getRoute() === null) {
             $child->setRoute('default');
         }
     }
 }
Example #15
0
File: Sitemap.php Project: cwcw/cms
 /**
  *
  */
 public function getSitemap()
 {
     if (is_null($this->_sitemap)) {
         $options = $this->getOptions();
         $front = $this->getBootstrap()->getResource('FrontController');
         $root = dirname($front->getModuleDirectory());
         //modules directory
         $acl = $this->getBootstrap()->getResource('Acl');
         $role = $this->getBootstrap()->getPluginResource('acl')->getRole();
         try {
             $dir = new DirectoryIterator($root);
         } catch (Exception $e) {
             throw new Streamwide_Exception("Directory {$root} not readable");
         }
         $this->_sitemap = new Zend_Navigation();
         foreach ($dir as $file) {
             if ($file->isDot() || !$file->isDir()) {
                 continue;
             }
             $module = $file->getFilename();
             // Don't use SCCS directories as modules
             if (preg_match('/^[^a-z]/i', $module) || 'CVS' == $module) {
                 continue;
             }
             $controllerPath = "{$root}/{$module}/controllers";
             $controllers = $this->_getControllers($controllerPath);
             foreach ($controllers as $controller => $class) {
                 $actions = $this->_getActions($class);
                 foreach ($actions as $action) {
                     $mca = new Streamwide_Web_Acl_Resource_Mca($module, strtolower($controller), strtolower($action));
                     $all = new Streamwide_Web_Acl_Resource_Mca('*', '*', '*');
                     if ($acl->has($mca) && !$acl->isAllowed($role, $mca)) {
                         continue;
                     }
                     if (!$acl->has($mca) && !$acl->isAllowed($role, $all)) {
                         continue;
                     }
                     $this->_sitemap->addPage(Zend_Navigation_Page::factory(array("label" => "{$module}/{$controller}/{$action}", "module" => $module, "controller" => $controller, "action" => $action)));
                 }
             }
         }
     }
     return $this->_sitemap;
 }
Example #16
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 Zend_View_Helper_Navigation_Abstract::htmlify()}.
  *
  * @param  Zend_Navigation_Page $page  page to generate HTML for
  * @return string                      HTML string for the given page
  */
 public function htmlify(Zend_Navigation_Page $page)
 {
     if (isset($page->custom_html)) {
         return $page->custom_html;
     }
     // 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?
     if ($href = $page->getHref()) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     if (isset($page->attribs)) {
         $attribs = array_merge($attribs, $page->attribs);
     }
     if (isset($page->iconClass)) {
         $icoHtml = '<span class="' . $page->iconClass . '"></span>';
     } else {
         $icoHtml = '';
     }
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $icoHtml . $this->view->escape($label) . '</' . $element . '>';
 }
Example #17
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 Zend_View_Helper_Navigation_Abstract::htmlify()}.
  *
  * @param  Zend_Navigation_Page $page  page to generate HTML for
  * @return string                      HTML string for the given page
  */
 public function htmlify(Zend_Navigation_Page $page)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if ($this->getUseTranslator()) {
         $_page = $page;
         $pageTranslator = null;
         while ($_page instanceof Zend_Navigation_Page && !($pageTranslator = $_page->get('translator'))) {
             $_page = $_page->getParent();
         }
         if ($pageTranslator) {
             $t = Axis::translate($pageTranslator);
             if (is_string($label) && !empty($label)) {
                 // $label = $t->translate($label);
                 $label = $t->__($label);
             }
             if (is_string($title) && !empty($title)) {
                 // $title = $t->translate($title);
                 $title = $t->__($title);
             }
         }
     }
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $title);
     // does page have a href?
     if ($href = $page->getHref()) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     return '<' . $element . $this->_htmlAttribs($attribs) . '>' . '<span>' . $this->view->escape($label) . '</span>' . '</' . $element . '>';
 }
Example #18
0
    /**
     * Renders the given $page as a link element, with $attrib = $relation
     *
     * @param  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 Zend_View_Exception             if $attrib is invalid
     */
    public function renderLink(Zend_Navigation_Page $page, $attrib, $relation)
    {
        if (!in_array($attrib, array('rel', 'rev'))) {
            require_once 'Zend/View/Exception.php';
            $e = new 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();
    }
Example #19
0
    /**
     * Returns an escaped absolute URL for the given page
     *
     * @param  Zend_Navigation_Page $page  page to get URL from
     * @return string
     */
    public function url(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);
    }
Example #20
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  Zend_Navigation_Page $page  page to check
  * @return bool                        whether page is accepted by ACL
  */
 protected function _acceptAcl(Zend_Navigation_Page $page)
 {
     if (true == $page->get('invalid')) {
         return false;
     }
     return parent::_acceptAcl($page);
 }
Example #21
0
 /**
  * Returns an array representation of the page
  *
  * @return array
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), array('uri' => $this->getUri()));
 }
Example #22
0
 public static function setDefaultPageType($type = null)
 {
     if ($type !== null && !is_string($type)) {
         throw new Zend_Navigation_Exception('Cannot set default page type: type is no string but should be');
     }
     self::$_defaultPageType = $type;
 }
Example #23
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(),
             'module'       => $this->getModule(),
             'params'       => $this->getParams(),
             'route'        => $this->getRoute(),
             'reset_params' => $this->getResetParams()
         ));
 }
Example #24
0
 /**
  * Checks if the container has the given page
  *
  * @param  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(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;
 }
Example #25
0
 public function testAclFiltersAwayPagesFromPageProperty()
 {
     $acl = new Zend_Acl();
     $acl->addRole(new Zend_Acl_Role('member'));
     $acl->addRole(new Zend_Acl_Role('admin'));
     $acl->add(new Zend_Acl_Resource('protected'));
     $acl->allow('admin', 'protected');
     $this->_helper->setAcl($acl);
     $this->_helper->setRole($acl->getRole('member'));
     $samplePage = Zend_Navigation_Page::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);
 }
Example #26
0
 /**
  * @group ZF-11805
  */
 public function testFactoryExceptionWhenNoPageTypeDetected()
 {
     // Without label
     try {
         $page = Zend_Navigation_Page::factory(array());
         $this->fail('An invalid value was set, but a ' . 'Zend_Navigation_Exception was not thrown');
     } catch (Zend_Navigation_Exception $e) {
         $this->assertSame('Invalid argument: Unable to determine class to instantiate', $e->getMessage());
     }
     // With label
     try {
         $page = Zend_Navigation_Page::factory(array('label' => 'Foo'));
         $this->fail('An invalid value was set, but a ' . 'Zend_Navigation_Exception was not thrown');
     } catch (Zend_Navigation_Exception $e) {
         $this->assertSame('Invalid argument: Unable to determine class to instantiate' . ' (Page label: Foo)', $e->getMessage());
     }
 }
 public function buildAdminNav()
 {
     $pages = array(Zend_Navigation_Page::factory(array('label' => 'Agents', 'action' => 'index', 'controller' => 'index', 'module' => 'agents', 'route' => 'admin', 'id' => 'agents', 'order' => 100, 'resource' => new Agents_Model_Acl_Resource_Agents(), 'pages' => array(Zend_Navigation_Page::factory(array('label' => 'Create Agent', 'action' => 'index', 'controller' => 'create', 'module' => 'agents', 'route' => 'admin')), Zend_Navigation_Page::factory(array('label' => 'Modify Agent', 'action' => 'index', 'controller' => 'modify', 'module' => 'agents', 'route' => 'admin'))))));
     return $pages;
 }
Example #28
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 Zend_View_Helper_Navigation_Abstract::htmlify()}.
  *
  * @param  Zend_Navigation_Page $page  page to generate HTML for
  * @return string                      HTML string for the given page
  */
 public function htmlify(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  Zend_Navigation_Page $page  page to check
  * @return bool                        whether page is accepted by ACL
  */
 protected function _acceptAcl(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;
 }
Example #30
0
 /**
  * The page will be invisible if it has no resource and no visible children
  * This method is used to hide empty parent items in backend navigation
  *
  * @param  Zend_Navigation_Page $page      page to check
  * @return bool
  */
 public function isVisibleAtBackend(Zend_Navigation_Page $page)
 {
     if ($page->getResource()) {
         return true;
     }
     $visible = true;
     $iterator = new RecursiveIteratorIterator($page, RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $child) {
         if (!$child->getResource()) {
             continue;
             // anchor page
         }
         $visible = $this->accept($child, false);
         if ($visible) {
             break;
         }
     }
     return $visible;
 }