/**
  * Generates a 'List' element.
  *
  * @param array   $items   Array with the elements of the list
  * @param boolean $ordered Specifies ordered/unordered list; default unordered
  * @param array   $attribs Attributes for the ol/ul tag.
  * @return string The list XHTML.
  */
 public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
 {
     if (!is_array($items)) {
         #require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('First param must be an array');
         $e->setView($this->view);
         throw $e;
     }
     $list = '';
     foreach ($items as $item) {
         if (!is_array($item)) {
             if ($escape) {
                 $item = $this->view->escape($item);
             }
             $list .= '<li>' . $item . '</li>' . self::EOL;
         } else {
             if (6 < strlen($list)) {
                 $list = substr($list, 0, strlen($list) - 6) . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
             } else {
                 $list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
             }
         }
     }
     if ($attribs) {
         $attribs = $this->_htmlAttribs($attribs);
     } else {
         $attribs = '';
     }
     $tag = 'ul';
     if ($ordered) {
         $tag = 'ol';
     }
     return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
 }
Example #2
0
    /**
     * Constructor
     *
     * Grab local copies of various MVC objects
     *
     * @return void
     */
    public function __construct()
    {
        $front   = Zend_Controller_Front::getInstance();
        $modules = $front->getControllerDirectory();
        if (empty($modules)) {
            // require_once 'Zend/View/Exception.php';
            $e = new Zend_View_Exception('Action helper depends on valid front controller instance');
            $e->setView($this->view);
            throw $e;
        }

        $request  = $front->getRequest();
        $response = $front->getResponse();

        if (empty($request) || empty($response)) {
            // require_once 'Zend/View/Exception.php';
            $e = new Zend_View_Exception('Action view helper requires both a registered request and response object in the front controller instance');
            $e->setView($this->view);
            throw $e;
        }

        $this->request       = clone $request;
        $this->response      = clone $response;
        $this->dispatcher    = clone $front->getDispatcher();
        $this->defaultModule = $front->getDefaultModule();
    }
Example #3
0
 public function findHelper($proxy, $strict = true)
 {
     if (isset($this->_helpers[$proxy])) {
         return $this->_helpers[$proxy];
     }
     if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) {
         $this->view->addHelperPath(str_replace('_', '/', self::NS), self::NS);
     }
     if ($strict) {
         $helper = $this->view->getHelper($proxy);
     } else {
         try {
             $helper = $this->view->getHelper($proxy);
         } catch (Zend_Loader_PluginLoader_Exception $e) {
             return null;
         }
     }
     if (!$helper instanceof Zend_View_Helper_Navigation_Helper) {
         if ($strict) {
             require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception(sprintf('Proxy helper "%s" is not an instance of ' . 'Zend_View_Helper_Navigation_Helper', get_class($helper)));
             $e->setView($this->view);
             throw $e;
         }
         return null;
     }
     $this->_inject($helper);
     $this->_helpers[$proxy] = $helper;
     return $helper;
 }
Example #4
0
 public function __set($key, $val)
 {
     if ('_' != substr($key, 0, 1)) {
         $this->_proxyData->{$key} = $val;
         return;
     }
     require_once 'Zend/View/Exception.php';
     $e = new Zend_View_Exception('Setting private or protected class members is not allowed');
     $e->setView($this);
     throw $e;
 }
Example #5
0
 /**
  * Set translator
  *
  * @param  Zend_Translate|Zend_Translate_Adapter|null $translator
  * @return Zend_View_Helper_FormElement
  */
 public function setTranslator($translator = null)
 {
     if (null === $translator) {
         $this->_translator = null;
     } elseif ($translator instanceof Zend_Translate_Adapter) {
         $this->_translator = $translator;
     } elseif ($translator instanceof Zend_Translate) {
         $this->_translator = $translator->getAdapter();
     } else {
         $e = new Zend_View_Exception('Invalid translator specified');
         $e->setView($this->view);
         throw $e;
     }
     return $this;
 }
Example #6
0
    /**
     * Set or retrieve doctype
     *
     * @param  string $doctype
     * @return Zend_View_Helper_Doctype
     */
    public function doctype($doctype = null)
    {
        if (null !== $doctype) {
            switch ($doctype) {
                case self::XHTML11:
                case self::XHTML1_STRICT:
                case self::XHTML1_TRANSITIONAL:
                case self::XHTML1_FRAMESET:
                case self::XHTML_BASIC1:
                case self::XHTML1_RDFA:
                case self::XHTML5:
                case self::HTML4_STRICT:
                case self::HTML4_LOOSE:
                case self::HTML4_FRAMESET:
                case self::HTML5:
                    $this->setDoctype($doctype);
                    break;
                default:
                    if (substr($doctype, 0, 9) != '<!DOCTYPE') {
                        require_once 'Zend/View/Exception.php';
                        $e = new Zend_View_Exception('The specified doctype is malformed');
                        $e->setView($this->view);
                        throw $e;
                    }
                    if (stristr($doctype, 'xhtml')) {
                        $type = self::CUSTOM_XHTML;
                    } else {
                        $type = self::CUSTOM;
                    }
                    $this->setDoctype($type);
                    $this->_registry['doctypes'][$type] = $doctype;
                    break;
            }
        }

        return $this;
    }
 /**
  * Override offsetSet
  *
  * @param  string|int $index
  * @param  mixed $value
  * @return void
  */
 public function offsetSet($index, $value)
 {
     if (!$this->_isValid($value)) {
         //require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
         $e->setView($this->view);
         throw $e;
     }
     return $this->getContainer()->offsetSet($index, $value);
 }
Example #8
0
 /**
  * Create item for alternate link item
  *
  * @param  array $args
  * @return stdClass
  */
 public function createDataAlternate(array $args)
 {
     if (3 > count($args)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception(sprintf('Alternate tags require 3 arguments; %s provided', count($args)));
         $e->setView($this->view);
         throw $e;
     }
     $rel = 'alternate';
     $href = array_shift($args);
     $type = array_shift($args);
     $title = array_shift($args);
     if (0 < count($args) && is_array($args[0])) {
         $extras = array_shift($args);
         $extras = (array) $extras;
         if (isset($extras['media']) && is_array($extras['media'])) {
             $extras['media'] = implode(',', $extras['media']);
         }
     }
     $href = (string) $href;
     $type = (string) $type;
     $title = (string) $title;
     $attributes = compact('rel', 'href', 'type', 'title', 'extras');
     return $this->createData($attributes);
 }
Example #9
0
 /**
  * Returns the set locale for translations
  *
  * @throws Zend_View_Exception When no Zend_Translate instance was set
  * @return string|Zend_Locale
  */
 public function getLocale()
 {
     $translate = $this->getTranslator();
     if ($translate === null) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
         $e->setView($this->view);
         throw $e;
     }
     return $translate->getLocale();
 }
Example #10
0
 /**
  * Render the provided pages.  This checks if $view->paginator is set and,
  * if so, uses that.  Also, if no scrolling style or partial are specified,
  * the defaults will be used (if set).
  *
  * @param  Zend_Paginator (Optional) $paginator
  * @param  string $scrollingStyle (Optional) Scrolling style
  * @param  string $partial (Optional) View partial
  * @param  array|string $params (Optional) params to pass to the partial
  * @return string
  * @throws Zend_View_Exception
  */
 public function paginationControl(Zend_Paginator $paginator = null, $scrollingStyle = null, $partial = null, $params = null)
 {
     if ($paginator === null) {
         if (isset($this->view->paginator) and $this->view->paginator !== null and $this->view->paginator instanceof Zend_Paginator) {
             $paginator = $this->view->paginator;
         } else {
             /**
              * @see Zend_View_Exception
              */
             require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception('No paginator instance provided or incorrect type');
             $e->setView($this->view);
             throw $e;
         }
     }
     if ($partial === null) {
         if (self::$_defaultViewPartial === null) {
             /**
              * @see Zend_View_Exception
              */
             require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception('No view partial provided and no default set');
             $e->setView($this->view);
             throw $e;
         }
         $partial = self::$_defaultViewPartial;
     }
     $pages = get_object_vars($paginator->getPages($scrollingStyle));
     if ($params !== null) {
         $pages = array_merge($pages, (array) $params);
     }
     if (is_array($partial)) {
         if (count($partial) != 2) {
             /**
              * @see Zend_View_Exception
              */
             require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception('A view partial supplied as an array must contain two values: the filename and its module');
             $e->setView($this->view);
             throw $e;
         }
         if ($partial[1] !== null) {
             return $this->view->partial($partial[0], $partial[1], $pages);
         }
         $partial = $partial[0];
     }
     return $this->view->partial($partial, $pages);
 }
Example #11
0
 /**
  * Override set to enforce style creation
  *
  * @param  mixed $value
  * @return void
  */
 public function set($value)
 {
     if (!$this->_isValid($value)) {
         // require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Invalid value passed to set; please use setStyle()');
         $e->setView($this->view);
         throw $e;
     }
     return $this->getContainer()->set($value);
 }
Example #12
0
 /**
  * Renders the given $container by invoking the partial view helper
  *
  * The container will simply be passed on as a model to the view script
  * as-is, and will be available in the partial script as 'container', e.g.
  * <code>echo 'Number of pages: ', count($this->container);</code>.
  *
  * @param  Zend_Navigation_Container $container  [optional] container to
  *                                               pass to view script. Default
  *                                               is to use the container
  *                                               registered in the helper.
  * @param  string|array             $partial     [optional] partial view
  *                                               script to use. Default is to
  *                                               use the partial registered
  *                                               in the helper. If an array
  *                                               is given, it is expected to
  *                                               contain two values; the
  *                                               partial view script to use,
  *                                               and the module where the
  *                                               script can be found.
  * @return string                                helper output
  */
 public function renderPartial(Zend_Navigation_Container $container = null, $partial = null)
 {
     if (null === $container) {
         $container = $this->getContainer();
     }
     if (null === $partial) {
         $partial = $this->getPartial();
     }
     if (empty($partial)) {
         $e = new Zend_View_Exception('Unable to render menu: No partial view script provided');
         $e->setView($this->view);
         throw $e;
     }
     $model = array('container' => $container);
     if (is_array($partial)) {
         if (count($partial) != 2) {
             $e = new Zend_View_Exception('Unable to render menu: A view partial supplied as ' . 'an array must contain two values: partial view ' . 'script and module where script can be found');
             $e->setView($this->view);
             throw $e;
         }
         return $this->view->partial($partial[0], $partial[1], $model);
     }
     return $this->view->partial($partial, null, $model);
 }
Example #13
0
 /**
  * Retrieve plugin loader for a specific plugin type
  *
  * @param  string $type
  * @return Zend_Loader_PluginLoader
  */
 public function getPluginLoader($type)
 {
     $type = strtolower($type);
     if (!in_array($type, $this->_loaderTypes)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception(sprintf('Invalid plugin loader type "%s"; cannot retrieve', $type));
         $e->setView($this);
         throw $e;
     }
     if (!array_key_exists($type, $this->_loaders)) {
         $prefix = 'Zend_View_';
         $pathPrefix = 'Zend/View/';
         $pType = ucfirst($type);
         switch ($type) {
             case 'filter':
             case 'helper':
             default:
                 $prefix .= $pType;
                 $pathPrefix .= $pType;
                 $loader = new Centurion_Loader_PluginLoader(array($prefix => $pathPrefix), $type);
                 $this->_loaders[$type] = $loader;
                 break;
         }
     }
     return $this->_loaders[$type];
 }
Example #14
0
 /**
  * Finds a view script from the available directories.
  *
  * @param string $name The base name of the script.
  * @return void
  */
 protected function _script($name)
 {
     if ($this->isLfiProtectionOn() && preg_match('#\\.\\.[\\\\/]#', $name)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Requested scripts may not include parent directory traversal ("../", "..\\" notation)');
         $e->setView($this);
         throw $e;
     }
     if (0 == count($this->_path['script'])) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('no view script directory set; unable to determine location for view script');
         $e->setView($this);
         throw $e;
     }
     /* original
        foreach ($this->_path['script'] as $dir) {
            if (is_readable($dir . $name)) {
                return $dir . $name;
            }
        }
        */
     // alcalbg: layout conflict detector
     $count = 0;
     $ret = $ret_log = false;
     foreach ($this->_path['script'] as $dir) {
         if (is_readable($dir . $name)) {
             if ($ret === false) {
                 $ret = $dir . $name;
             }
             $ret_log = $dir . $name;
             ++$count;
         }
     }
     if ($count > 2) {
         foreach ($this->_path['script'] as $dir) {
             if ($dir . $name != $ret_log && is_readable($dir . $name)) {
                 $message = 'Possible layout conflict: ' . $dir . $name;
                 Application_Plugin_Common::log($message);
             }
         }
     }
     if ($ret) {
         return $ret;
     }
     // alcalbg: end
     require_once 'Zend/View/Exception.php';
     $message = "script '{$name}' not found in path (" . implode(PATH_SEPARATOR, $this->_path['script']) . ")";
     $e = new Zend_View_Exception($message);
     $e->setView($this);
     throw $e;
 }
Example #15
0
 /**
  * Override offsetSet
  *
  * @param  string|int $index
  * @param  mixed $value
  * @return void
  */
 public function offsetSet($index, $value)
 {
     if (!$this->_isValid($value)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
         $e->setView($this->view);
         throw $e;
     }
     // we don't need to overwrite existing files - will shift them by one
     if ($this->getContainer()->offsetExists($index)) {
         $values = $this->getContainer()->getArrayCopy();
         $keys = $this->getContainer()->getKeys();
         // insert value to required position. Keys will be restored later
         $offset = array_search($index, $keys);
         array_splice($values, $offset, 0, array($value));
         // rebuild array keys
         $arrKeys = array_fill_keys($keys, null);
         $result = array();
         foreach ($arrKeys as $key => $dummy) {
             if ($key === $index) {
                 do {
                     $result[$key] = $dummy;
                     $key++;
                 } while (isset($keys[$key]));
             }
             $result[$key] = $dummy;
         }
         // restore keys in result array
         $i = 0;
         foreach ($result as $key => $dummy) {
             $result[$key] = $values[$i++];
         }
         return $this->getContainer()->exchangeArray($result);
     }
     return $this->getContainer()->offsetSet($index, $value);
 }
Example #16
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();
    }
 /**
  * Sets ACL role(s) to use when iterating pages
  *
  * Implements {@link Zend_View_Helper_Navigation_Helper::setRole()}.
  *
  * @param  mixed $role                                 [optional] role to
  *                                                     set. Expects a string,
  *                                                     an instance of type
  *                                                     {@link Zend_Acl_Role_Interface},
  *                                                     or null. Default is
  *                                                     null, which will set
  *                                                     no role.
  * @throws Zend_View_Exception                         if $role is invalid
  * @return Zend_View_Helper_Navigation_HelperAbstract  fluent interface,
  *                                                     returns self
  */
 public function setRole($role = null)
 {
     if (null === $role || is_string($role) || $role instanceof Zend_Acl_Role_Interface) {
         $this->_role = $role;
     } else {
         #require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception(sprintf('$role must be a string, null, or an instance of ' . 'Zend_Acl_Role_Interface; %s given', gettype($role)));
         $e->setView($this->view);
         throw $e;
     }
     return $this;
 }
Example #18
0
    /**
     * Returns a DOMDocument containing the Sitemap XML for the given container
     *
     * @param  Zend_Navigation_Container $container  [optional] container to get
     *                                               breadcrumbs from, defaults
     *                                               to what is registered in the
     *                                               helper
     * @return DOMDocument                           DOM representation of the
     *                                               container
     * @throws Zend_View_Exception                   if schema validation is on
     *                                               and the sitemap is invalid
     *                                               according to the sitemap
     *                                               schema, or if sitemap
     *                                               validators are used and the
     *                                               loc element fails validation
     */
    public function getDomSitemap(Zend_Navigation_Container $container = null)
    {
        if (null === $container) {
            $container = $this->getContainer();
        }

        // check if we should validate using our own validators
        if ($this->getUseSitemapValidators()) {
            require_once 'Zend/Validate/Sitemap/Changefreq.php';
            require_once 'Zend/Validate/Sitemap/Lastmod.php';
            require_once 'Zend/Validate/Sitemap/Loc.php';
            require_once 'Zend/Validate/Sitemap/Priority.php';

            // create validators
            $locValidator        = new Zend_Validate_Sitemap_Loc();
            $lastmodValidator    = new Zend_Validate_Sitemap_Lastmod();
            $changefreqValidator = new Zend_Validate_Sitemap_Changefreq();
            $priorityValidator   = new Zend_Validate_Sitemap_Priority();
        }

        // create document
        $dom = new DOMDocument('1.0', 'UTF-8');
        $dom->formatOutput = $this->getFormatOutput();

        // ...and urlset (root) element
        $urlSet = $dom->createElementNS(self::SITEMAP_NS, 'urlset');
        $dom->appendChild($urlSet);

        // create iterator
        $iterator = new RecursiveIteratorIterator($container,
            RecursiveIteratorIterator::SELF_FIRST);

        $maxDepth = $this->getMaxDepth();
        if (is_int($maxDepth)) {
            $iterator->setMaxDepth($maxDepth);
        }
        $minDepth = $this->getMinDepth();
        if (!is_int($minDepth) || $minDepth < 0) {
            $minDepth = 0;
        }

        // iterate container
        foreach ($iterator as $page) {
            if ($iterator->getDepth() < $minDepth || !$this->accept($page)) {
                // page should not be included
                continue;
            }

            // get absolute url from page
            if (!$url = $this->url($page)) {
                // skip page if it has no url (rare case)
                continue;
            }

            // create url node for this page
            $urlNode = $dom->createElementNS(self::SITEMAP_NS, 'url');
            $urlSet->appendChild($urlNode);

            if ($this->getUseSitemapValidators() &&
                !$locValidator->isValid($url)) {
                require_once 'Zend/View/Exception.php';
                $e = new Zend_View_Exception(sprintf(
                        'Encountered an invalid URL for Sitemap XML: "%s"',
                        $url));
                $e->setView($this->view);
                throw $e;
            }

            // put url in 'loc' element
            $urlNode->appendChild($dom->createElementNS(self::SITEMAP_NS,
                                                        'loc', $url));

            // add 'lastmod' element if a valid lastmod is set in page
            if (isset($page->lastmod)) {
                $lastmod = strtotime((string) $page->lastmod);

                // prevent 1970-01-01...
                if ($lastmod !== false) {
                    $lastmod = date('c', $lastmod);
                }

                if (!$this->getUseSitemapValidators() ||
                    $lastmodValidator->isValid($lastmod)) {
                    $urlNode->appendChild(
                        $dom->createElementNS(self::SITEMAP_NS, 'lastmod',
                                              $lastmod)
                    );
                }
            }

            // add 'changefreq' element if a valid changefreq is set in page
            if (isset($page->changefreq)) {
                $changefreq = $page->changefreq;
                if (!$this->getUseSitemapValidators() ||
                    $changefreqValidator->isValid($changefreq)) {
                    $urlNode->appendChild(
                        $dom->createElementNS(self::SITEMAP_NS, 'changefreq',
                                              $changefreq)
                    );
                }
            }

            // add 'priority' element if a valid priority is set in page
            if (isset($page->priority)) {
                $priority = $page->priority;
                if (!$this->getUseSitemapValidators() ||
                    $priorityValidator->isValid($priority)) {
                    $urlNode->appendChild(
                        $dom->createElementNS(self::SITEMAP_NS, 'priority',
                                              $priority)
                    );
                }
            }
        }

        // validate using schema if specified
        if ($this->getUseSchemaValidation()) {
            if (!@$dom->schemaValidate(self::SITEMAP_XSD)) {
                require_once 'Zend/View/Exception.php';
                $e = new Zend_View_Exception(sprintf(
                        'Sitemap is invalid according to XML Schema at "%s"',
                        self::SITEMAP_XSD));
                $e->setView($this->view);
                throw $e;
            }
        }

        return $dom;
    }
Example #19
0
 /**
  * Find helper
  *
  * @param string $proxy
  * @param bool $strict
  * @return null|NavigationViewHelperHelper
  * @throws ViewException
  */
 public function findHelper($proxy, $strict = true)
 {
     if (isset($this->_helpers[$proxy])) {
         return $this->_helpers[$proxy];
     }
     if (!$strict) {
         if (!$this->getPluginManager()->has($proxy)) {
             return null;
         }
     }
     $helper = $this->getPluginManager()->get($proxy);
     if (!$helper instanceof NavigationViewHelperHelper) {
         if ($strict) {
             $e = new ViewException(sprintf('Proxy helper "%s" is not an instance of ' . 'Zend_View_Helper_Navigation_Helper', get_class($helper)));
             $e->setView($this->view);
             throw $e;
         }
         return null;
     }
     $this->_inject($helper);
     $this->_helpers[$proxy] = $helper;
     return $helper;
 }
Example #20
0
 /**
  * Sets a translation Adapter for translation
  *
  * @param  Zend_Translate|Zend_Translate_Adapter $translate
  * @return Zend_View_Helper_HeadTitle
  */
 public function setTranslator($translate)
 {
     if ($translate instanceof Zend_Translate_Adapter) {
         $this->_translator = $translate;
     } elseif ($translate instanceof Zend_Translate) {
         $this->_translator = $translate->getAdapter();
     } else {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
         $e->setView($this->view);
         throw $e;
     }
     return $this;
 }
Example #21
0
 /**
  * Renders the given $container by invoking the partial view helper
  *
  * The container will simply be passed on as a model to the view script,
  * so in the script it will be available in <code>$this->container</code>.
  *
  * @param  Zend_Navigation_Container $container  [optional] container to
  *                                               pass to view script.
  *                                               Default is to use the
  *                                               container registered in the
  *                                               helper.
  * @param  string|array             $partial     [optional] partial view
  *                                               script to use. Default is
  *                                               to use the partial
  *                                               registered in the helper.
  *                                               If an array is given, it is
  *                                               expected to contain two
  *                                               values; the partial view
  *                                               script to use, and the
  *                                               module where the script can
  *                                               be found.
  * @return string                                helper output
  */
 public function renderPartial(Zend_Navigation_Container $container = null, $partial = null)
 {
     if (null === $container) {
         $container = $this->getContainer();
     }
     if (null === $partial) {
         $partial = $this->getPartial();
     }
     if (empty($partial)) {
         //--//require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Unable to render menu: No partial view script provided');
         $e->setView($this->view);
         throw $e;
     }
     // put breadcrumb pages in model
     $model = array('pages' => array());
     if ($active = $this->findActive($container)) {
         $active = $active['page'];
         $model['pages'][] = $active;
         while ($parent = $active->getParent()) {
             if ($parent instanceof Zend_Navigation_Page) {
                 $model['pages'][] = $parent;
             } else {
                 break;
             }
             if ($parent === $container) {
                 // break if at the root of the given container
                 break;
             }
             $active = $parent;
         }
         $model['pages'] = array_reverse($model['pages']);
     }
     if (is_array($partial)) {
         if (count($partial) != 2) {
             //--//require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception('Unable to render menu: A view partial supplied as ' . 'an array must contain two values: partial view ' . 'script and module where script can be found');
             $e->setView($this->view);
             throw $e;
         }
         return $this->view->partial($partial[0], $partial[1], $model);
     }
     return $this->view->partial($partial, null, $model);
 }
Example #22
0
 /**
  * Overload
  *
  * Proxy to container methods
  *
  * @param  string $method
  * @param  array $args
  * @return mixed
  */
 public function __call($method, $args)
 {
     $container = $this->getContainer();
     if (method_exists($container, $method)) {
         $return = call_user_func_array(array($container, $method), $args);
         if ($return === $container) {
             // If the container is returned, we really want the current object
             return $this;
         }
         return $return;
     }
     require_once PHP_LIBRARY_PATH . 'Zend/View/Exception.php';
     $e = new Zend_View_Exception('Method "' . $method . '" does not exist');
     $e->setView($this->view);
     throw $e;
 }
Example #23
0
 /**
  * Build meta HTML string
  *
  * @param  string $type
  * @param  string $typeValue
  * @param  string $content
  * @param  array $modifiers
  * @return string
  */
 public function itemToString(stdClass $item)
 {
     if (!in_array($item->type, $this->_typeKeys)) {
         #require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception(sprintf('Invalid type "%s" provided for meta', $item->type));
         $e->setView($this->view);
         throw $e;
     }
     $type = $item->type;
     $modifiersString = '';
     foreach ($item->modifiers as $key => $value) {
         if (!is_null($this->view) && $this->view->doctype()->isHtml5() && $key == 'scheme') {
             #require_once 'Zend/View/Exception.php';
             throw new Zend_View_Exception('Invalid modifier ' . '"scheme" provided; not supported by HTML5');
         }
         if (!in_array($key, $this->_modifierKeys)) {
             continue;
         }
         $modifiersString .= $key . '="' . $this->_escape($value) . '" ';
     }
     if ($this->view instanceof Zend_View_Abstract) {
         if ($this->view->doctype()->isHtml5() && $type == 'charset') {
             $tpl = $this->view->doctype()->isXhtml() ? '<meta %s="%s"/>' : '<meta %s="%s">';
         } elseif ($this->view->doctype()->isXhtml()) {
             $tpl = '<meta %s="%s" content="%s" %s/>';
         } else {
             $tpl = '<meta %s="%s" content="%s" %s>';
         }
     } else {
         $tpl = '<meta %s="%s" content="%s" %s/>';
     }
     $meta = sprintf($tpl, $type, $this->_escape($item->{$type}), $this->_escape($item->content), $modifiersString);
     if (isset($item->modifiers['conditional']) && !empty($item->modifiers['conditional']) && is_string($item->modifiers['conditional'])) {
         $meta = '<!--[if ' . $this->_escape($item->modifiers['conditional']) . ']>' . $meta . '<![endif]-->';
     }
     return $meta;
 }
Example #24
0
 /**
  * Finds a view script from the available directories.
  *
  * @param string $name The base name of the script.
  * @return void
  */
 protected function _script($name)
 {
     if ($this->isLfiProtectionOn() && preg_match('#\\.\\.[\\\\/]#', $name)) {
         $e = new Zend_View_Exception('Requested scripts may not include parent directory traversal ("../", "..\\" notation)');
         $e->setView($this);
         throw $e;
     }
     if (0 == count($this->_path['script'])) {
         $e = new Zend_View_Exception('no view script directory set; unable to determine location for view script');
         $e->setView($this);
         throw $e;
     }
     foreach ($this->_path['script'] as $dir) {
         if (is_readable($dir . $name)) {
             return $dir . $name;
         }
     }
     $message = "script '{$name}' not found in path (" . implode(PATH_SEPARATOR, $this->_path['script']) . ")";
     $e = new Zend_View_Exception($message);
     $e->setView($this);
     throw $e;
 }
Example #25
0
 /**
  * Registers a helper object, bypassing plugin loader
  *
  * @param  Zend_View_Helper_Abstract|object $helper
  * @param  string $name
  * @return Zend_View_Abstract
  * @throws Zend_View_Exception
  */
 public function registerHelper($helper, $name)
 {
     if (!is_object($helper)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('View helper must be an object');
         $e->setView($this);
         throw $e;
     }
     if (!$helper instanceof Zend_View_Interface) {
         if (!method_exists($helper, $name)) {
             require_once 'Zend/View/Exception.php';
             $e = new Zend_View_Exception('View helper must implement Zend_View_Interface or have a method matching the name provided');
             $e->setView($this);
             throw $e;
         }
     }
     if (method_exists($helper, 'setView')) {
         $helper->setView($this);
     }
     $name = ucfirst($name);
     $this->_helper[$name] = $helper;
     return $this;
 }