Index: library/Zend/View/Helper/Navigation/Links.php =================================================================== --- library/Zend/View/Helper/Navigation/Links.php (revision 24555) +++ library/Zend/View/Helper/Navigation/Links.php (working copy) @@ -769,7 +769,7 @@ foreach ($types as $relation => $pages) { foreach ($pages as $page) { if ($r = $this->renderLink($page, $attrib, $relation)) { - $output .= $indent . $r . self::EOL; + $output .= $indent . $r . $this->getEOL(); } } } Index: library/Zend/View/Helper/Navigation/Sitemap.php =================================================================== --- library/Zend/View/Helper/Navigation/Sitemap.php (revision 24555) +++ library/Zend/View/Helper/Navigation/Sitemap.php (working copy) @@ -52,7 +52,7 @@ * @var string */ const SITEMAP_XSD = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'; - + /** * Whether XML output should be formatted * @@ -106,34 +106,9 @@ return $this; } - // Accessors: + // Accessors: /** - * Sets whether XML output should be formatted - * - * @param bool $formatOutput [optional] whether output - * should be formatted. Default - * is true. - * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns - * self - */ - public function setFormatOutput($formatOutput = true) - { - $this->_formatOutput = (bool) $formatOutput; - return $this; - } - - /** - * Returns whether XML output should be formatted - * - * @return bool whether XML output should be formatted - */ - public function getFormatOutput() - { - return $this->_formatOutput; - } - - /** * Sets whether the XML declaration should be used in output * * @param bool $useXmlDecl whether XML delcaration @@ -478,6 +453,6 @@ $dom->saveXML() : $dom->saveXML($dom->documentElement); - return rtrim($xml, PHP_EOL); + return rtrim($xml, self::EOL); } } Index: library/Zend/View/Helper/Navigation/HelperAbstract.php =================================================================== --- library/Zend/View/Helper/Navigation/HelperAbstract.php (revision 24555) +++ library/Zend/View/Helper/Navigation/HelperAbstract.php (working copy) @@ -70,6 +70,13 @@ * @var string */ protected $_indent = ''; + + /** + * Whether HTML/XML output should be formatted + * + * @var bool + */ + protected $_formatOutput = true; /** * Translator @@ -264,16 +271,64 @@ } /** - * Returns indentation + * Returns indentation (format output is respected) + * + * @see getFormatOutput() * - * @return string + * @return string indentation string or an empty string */ public function getIndent() { + if (false === $this->getFormatOutput()) { + return ''; + } + return $this->_indent; } + + /** + * Returns the EOL character (format output is respected) + * + * @see self::EOL + * @see getFormatOutput() + * + * @return string standard EOL charater or an empty string + */ + public function getEOL() + { + if (false === $this->getFormatOutput()) { + return ''; + } + + return self::EOL; + } /** + * Sets whether HTML/XML output should be formatted + * + * @param bool $formatOutput [optional] whether output + * should be formatted. Default + * is true. + * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns + * self + */ + public function setFormatOutput($formatOutput = true) + { + $this->_formatOutput = (bool) $formatOutput; + return $this; + } + + /** + * Returns whether HTML/XML output should be formatted + * + * @return bool whether HTML/XML output should be formatted + */ + public function getFormatOutput() + { + return $this->_formatOutput; + } + + /** * Sets translator to use in helper * * Implements {@link Zend_View_Helper_Navigation_Helper::setTranslator()}. Index: library/Zend/View/Helper/Navigation/Menu.php =================================================================== --- library/Zend/View/Helper/Navigation/Menu.php (revision 24555) +++ library/Zend/View/Helper/Navigation/Menu.php (working copy) @@ -64,6 +64,13 @@ * @var string|array */ protected $_partial = null; + + /** + * Inner indentation string + * + * @var string + */ + protected $_innerIndent = ' '; /** * View helper entry point: @@ -194,7 +201,38 @@ { return $this->_partial; } + + /** + * Set the inner indentation string for using in {@link render()}, optionally + * a number of spaces to indent with + * + * @param string|int $indent indentation string or + * number of spaces + * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface, + * returns self + */ + public function setInnerIndent($indent) + { + $this->_innerIndent = $this->_getWhitespace($indent); + return $this; + } + /** + * Returns inner indentation (format output is respected) + * + * @see getFormatOutput() + * + * @return string indentation string or an empty string + */ + public function getInnerIndent() + { + if (false === $this->getFormatOutput()) { + return ''; + } + + return $this->_innerIndent; + } + // Public methods: /** @@ -252,18 +290,28 @@ */ protected function _normalizeOptions(array $options = array()) { + // Indent if (isset($options['indent'])) { $options['indent'] = $this->_getWhitespace($options['indent']); } else { $options['indent'] = $this->getIndent(); } + + // Inner ident + if (isset($options['innerIndent'])) { + $options['innerIndent'] = $this->_getWhitespace($options['innerIndent']); + } else { + $options['innerIndent'] = $this->getInnerIndent(); + } + // UL class if (isset($options['ulClass']) && $options['ulClass'] !== null) { $options['ulClass'] = (string) $options['ulClass']; } else { $options['ulClass'] = $this->getUlClass(); } + // Min depth if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { $options['minDepth'] = (int) $options['minDepth']; @@ -276,6 +324,7 @@ $options['minDepth'] = 0; } + // Max depth if (array_key_exists('maxDepth', $options)) { if (null !== $options['maxDepth']) { $options['maxDepth'] = (int) $options['maxDepth']; @@ -284,10 +333,12 @@ $options['maxDepth'] = $this->getMaxDepth(); } + // Only active branch if (!isset($options['onlyActiveBranch'])) { $options['onlyActiveBranch'] = $this->getOnlyActiveBranch(); } + // Render parents if (!isset($options['renderParents'])) { $options['renderParents'] = $this->getRenderParents(); } @@ -301,17 +352,19 @@ * Renders the deepest active menu within [$minDepth, $maxDeth], (called * from {@link renderMenu()}) * - * @param Zend_Navigation_Container $container container to render - * @param array $active active page and depth - * @param string $ulClass CSS class for first UL - * @param string $indent initial indentation - * @param int|null $minDepth minimum depth - * @param int|null $maxDepth maximum depth - * @return string rendered menu + * @param Zend_Navigation_Container $container container to render + * @param array $active active page and depth + * @param string $ulClass CSS class for first UL + * @param string $indent initial indentation + * @param string $innerIndent inner indentation + * @param int|null $minDepth minimum depth + * @param int|null $maxDepth maximum depth + * @return string rendered menu */ protected function _renderDeepestMenu(Zend_Navigation_Container $container, $ulClass, $indent, + $innerIndent, $minDepth, $maxDepth) { @@ -333,16 +386,17 @@ } $ulClass = $ulClass ? ' class="' . $ulClass . '"' : ''; - $html = $indent . '' . self::EOL; + $html = $indent . '' . $this->getEOL(); foreach ($active['page'] as $subPage) { if (!$this->accept($subPage)) { continue; } $liClass = $subPage->isActive(true) ? ' class="active"' : ''; - $html .= $indent . ' ' . self::EOL; - $html .= $indent . ' ' . $this->htmlify($subPage) . self::EOL; - $html .= $indent . ' ' . self::EOL; + $html .= $indent . $innerIndent . '' . $this->getEOL(); + $html .= $indent . str_repeat($innerIndent, 2) . $this->htmlify($subPage) + . $this->getEOL(); + $html .= $indent . $innerIndent . '' . $this->getEOL(); } $html .= $indent . ''; @@ -353,17 +407,19 @@ /** * Renders a normal menu (called from {@link renderMenu()}) * - * @param Zend_Navigation_Container $container container to render - * @param string $ulClass CSS class for first UL - * @param string $indent initial indentation - * @param int|null $minDepth minimum depth - * @param int|null $maxDepth maximum depth - * @param bool $onlyActive render only active branch? + * @param Zend_Navigation_Container $container container to render + * @param string $ulClass CSS class for first UL + * @param string $indent initial indentation + * @param string $innerIndent inner indentation + * @param int|null $minDepth minimum depth + * @param int|null $maxDepth maximum depth + * @param bool $onlyActive render only active branch? * @return string */ protected function _renderMenu(Zend_Navigation_Container $container, $ulClass, $indent, + $innerIndent, $minDepth, $maxDepth, $onlyActive) @@ -417,8 +473,8 @@ } // make sure indentation is correct - $depth -= $minDepth; - $myIndent = $indent . str_repeat(' ', $depth); + $depth -= $minDepth; + $myIndent = $indent . str_repeat($innerIndent, $depth * 2); if ($depth > $prevDepth) { // start new ul tag @@ -427,25 +483,26 @@ } else { $ulClass = ''; } - $html .= $myIndent . '' . self::EOL; + $html .= $myIndent . '' . $this->getEOL(); } else if ($prevDepth > $depth) { // close li/ul tags until we're at current depth for ($i = $prevDepth; $i > $depth; $i--) { - $ind = $indent . str_repeat(' ', $i); - $html .= $ind . ' ' . self::EOL; - $html .= $ind . '' . self::EOL; + $ind = $indent . str_repeat($innerIndent, $i * 2); + $html .= $ind . $innerIndent . '' . $this->getEOL(); + $html .= $ind . '' . $this->getEOL(); } // close previous li tag - $html .= $myIndent . ' ' . self::EOL; + $html .= $myIndent . $innerIndent. '' . $this->getEOL(); } else { // close previous li tag - $html .= $myIndent . ' ' . self::EOL; + $html .= $myIndent . $innerIndent. '' . $this->getEOL(); } // render li tag and page $liClass = $isActive ? ' class="active"' : ''; - $html .= $myIndent . ' ' . self::EOL - . $myIndent . ' ' . $this->htmlify($page) . self::EOL; + $html .= $myIndent . $innerIndent . '' . $this->getEOL() + . $myIndent . str_repeat($innerIndent, 2) . $this->htmlify($page) + . $this->getEOL(); // store as previous depth for next iteration $prevDepth = $depth; @@ -455,8 +512,8 @@ // done iterating container; close open ul/li tags for ($i = $prevDepth+1; $i > 0; $i--) { $myIndent = $indent . str_repeat(' ', $i-1); - $html .= $myIndent . ' ' . self::EOL - . $myIndent . '' . self::EOL; + $html .= $myIndent . $innerIndent . '' . $this->getEOL() + . $myIndent . '' . $this->getEOL(); } $html = rtrim($html, self::EOL); } @@ -495,12 +552,14 @@ $html = $this->_renderDeepestMenu($container, $options['ulClass'], $options['indent'], + $options['innerIndent'], $options['minDepth'], $options['maxDepth']); } else { $html = $this->_renderMenu($container, $options['ulClass'], $options['indent'], + $options['innerIndent'], $options['minDepth'], $options['maxDepth'], $options['onlyActiveBranch']); @@ -524,27 +583,35 @@ * )); * * - * @param Zend_Navigation_Container $container [optional] container to - * render. Default is to render - * the container registered in - * the helper. - * @param string $ulClass [optional] CSS class to - * use for UL element. Default - * is to use the value from - * {@link getUlClass()}. - * @param string|int $indent [optional] indentation as - * a string or number of - * spaces. Default is to use - * the value retrieved from - * {@link getIndent()}. + * @param Zend_Navigation_Container $container [optional] container to + * render. Default is to render + * the container registered in + * the helper. + * @param string $ulClass [optional] CSS class to + * use for UL element. Default + * is to use the value from + * {@link getUlClass()}. + * @param string|int $indent [optional] indentation as + * a string or number of + * spaces. Default is to use + * the value retrieved from + * {@link getIndent()}. + * @param string|int $innerIndent [optional] inner + * indentation as a string + * or number of spaces. + * Default is to use the + * value retrieved from + * {@link getInnerIndent()}. * @return string rendered content */ public function renderSubMenu(Zend_Navigation_Container $container = null, $ulClass = null, - $indent = null) + $indent = null, + $innerIndent = null) { return $this->renderMenu($container, array( 'indent' => $indent, + 'innerIndent' => $innerIndent, 'ulClass' => $ulClass, 'minDepth' => null, 'maxDepth' => null,