v7‰PNG IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ±üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0AºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT Helper/AdminMenuCollapsed.php 0000644 00000010172 15210162116 0012174 0 ustar 00 acl = $acl; } public function adminMenuCollapsed() { return $this; } public function renderMenu(Am_Navigation_Container $container, $options = array()) { $html = ''; foreach ($container as $page) { /* @var $page Am_Navigation_Page */ if ($this->acl && ($resources = $page->getResource())) { $hasPermission = false; foreach ((array)$resources as $resource) { if ($this->acl->hasPermission($resource, $page->getPrivilege())) $hasPermission = true; } if (!$hasPermission) continue; } if ($page->isActive() ) { $this->activePageId = $this->getId($page); } if (!$page->isVisible(true)) continue; if (!$page->getHref()) continue; $subMenu = $this->renderSubMenu($page); if (!$page->hasChildren() || ($page->hasChildren() && $subMenu)) { $html .= sprintf('
*
* Bar
*
*
*
* After:
*
*
* Bar
*
*
*
* @param bool $flag [optional] adds CSS class from
* page to li element
*
* @return Am_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function addPageClassToLi($flag = true)
{
$this->_addPageClassToLi = (bool) $flag;
return $this;
}
/**
* Returns a flag indicating whether the CSS class from page to be added to
* li element
*
* @return bool
*/
public function getAddPageClassToLi()
{
return $this->_addPageClassToLi;
}
/**
* 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 Am_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:
/**
* 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 Am_View_Helper_Navigation_Abstract::htmlify()}.
*
* @param Am_Navigation_Page $page page to generate HTML for
* @return string HTML string for the given page
*/
public function htmlify(Am_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';
}
// custom cgi-central
if ($page->get('disabled'))
$attribs['onclick'] = 'return false;';
// Add custom HTML attributes
$attribs = array_merge($attribs, $page->getCustomHtmlAttribs());
return '<' . $element . $this->_htmlAttribs($attribs) . '>'
. $this->view->escape($label)
. '' . $element . '>';
}
/**
* Normalizes given render options
*
* @param array $options [optional] options to normalize
* @return array normalized options
*/
protected function _normalizeOptions(array $options = array())
{
// Ident
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();
}
// UL id
if (isset($options['ulId']) && $options['ulId'] !== null) {
$options['ulId'] = (string) $options['ulId'];
} else {
$options['ulId'] = $this->getUlId();
}
// Active class
if (isset($options['activeClass']) && $options['activeClass'] !== null
) {
$options['activeClass'] = (string) $options['activeClass'];
} else {
$options['activeClass'] = $this->getActiveClass();
}
// Parent class
if (isset($options['parentClass']) && $options['parentClass'] !== null) {
$options['parentClass'] = (string) $options['parentClass'];
} else {
$options['parentClass'] = $this->getParentClass();
}
// Minimum depth
if (array_key_exists('minDepth', $options)) {
if (null !== $options['minDepth']) {
$options['minDepth'] = (int) $options['minDepth'];
}
} else {
$options['minDepth'] = $this->getMinDepth();
}
if ($options['minDepth'] < 0 || $options['minDepth'] === null) {
$options['minDepth'] = 0;
}
// Maximum depth
if (array_key_exists('maxDepth', $options)) {
if (null !== $options['maxDepth']) {
$options['maxDepth'] = (int) $options['maxDepth'];
}
} else {
$options['maxDepth'] = $this->getMaxDepth();
}
// Only active branch
if (!isset($options['onlyActiveBranch'])) {
$options['onlyActiveBranch'] = $this->getOnlyActiveBranch();
}
// Expand sibling nodes of active branch
if (!isset($options['expandSiblingNodesOfActiveBranch'])) {
$options['expandSiblingNodesOfActiveBranch'] = $this->getExpandSiblingNodesOfActiveBranch();
}
// Render parents?
if (!isset($options['renderParents'])) {
$options['renderParents'] = $this->getRenderParents();
}
// Render parent class?
if (!isset($options['renderParentClass'])) {
$options['renderParentClass'] = $this->getRenderParentClass();
}
// Add page CSS class to LI element
if (!isset($options['addPageClassToLi'])) {
$options['addPageClassToLi'] = $this->getAddPageClassToLi();
}
foreach (array('activeClass', 'normalClass', 'disabledClass') as $k)
if (!empty($options[$k]))
$this->{'_'.$k} = $options[$k];
return $options;
}
// Render methods:
/**
* Renders the deepest active menu within [$minDepth, $maxDeth], (called
* from {@link renderMenu()})
*
* @param Am_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 string|null $ulId unique identifier (id)
* for first UL
* @param bool $addPageClassToLi adds CSS class from
* page to li element
* @param string|null $activeClass CSS class for active
* element
* @param string $parentClass CSS class for parent
* li's
* @param bool $renderParentClass Render parent class?
* @return string rendered menu (HTML)
*/
protected function _renderDeepestMenu(Am_Navigation_Container $container,
$ulClass,
$indent,
$innerIndent,
$minDepth,
$maxDepth,
$ulId,
$addPageClassToLi,
$activeClass,
$parentClass,
$renderParentClass)
{
if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) {
return '';
}
// special case if active page is one below minDepth
if ($active['depth'] < $minDepth) {
if (!$active['page']->hasPages()) {
return '';
}
} else if (!$active['page']->hasPages()) {
// found pages has no children; render siblings
$active['page'] = $active['page']->getParent();
} else if (is_int($maxDepth) && $active['depth'] + 1 > $maxDepth) {
// children are below max depth; render siblings
$active['page'] = $active['page']->getParent();
}
$attribs = array(
'class' => $ulClass,
'id' => $ulId,
);
// We don't need a prefix for the menu ID (backup)
$skipValue = $this->_skipPrefixForId;
$this->skipPrefixForId();
$html = $indent . '
* renderMenu($container, array(
* 'indent' => $indent,
* 'ulClass' => $ulClass,
* 'minDepth' => null,
* 'maxDepth' => null,
* 'onlyActiveBranch' => true,
* 'renderParents' => false
* ));
*
*
* @param Am_Navigation_Container $container [optional] container to
* render. Default is to render
* the container registered in
* the helper.
* @param string|null $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|null $ulId [optional] Unique identifier
* (id) use for UL element
* @param bool $addPageClassToLi adds CSS class from
* page to li element
* @param string|int $innerIndent [optional] inner
* indentation as a string
* or number of spaces.
* Default is to use the
* {@link getInnerIndent()}.
* @return string rendered content
*/
public function renderSubMenu(Am_Navigation_Container $container = null,
$ulClass = null,
$indent = null,
$ulId = null,
$addPageClassToLi = false,
$innerIndent = null)
{
return $this->renderMenu($container, array(
'indent' => $indent,
'innerIndent' => $innerIndent,
'ulClass' => $ulClass,
'minDepth' => null,
'maxDepth' => null,
'onlyActiveBranch' => true,
'renderParents' => false,
'ulId' => $ulId,
'addPageClassToLi' => $addPageClassToLi,
));
}
/**
* 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.
* echo 'Number of pages: ', count($this->container);.
*
* @param Am_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
*
* @throws Am_View_Exception When no partial script is set
*/
public function renderPartial(Am_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 Am_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) {
//--//require_once 'Zend/View/Exception.php';
$e = new Am_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);
}
// Am_View_Helper_Navigation_Helper:
/**
* Renders menu
*
* Implements {@link Am_View_Helper_Navigation_Helper::render()}.
*
* If a partial view is registered in the helper, the menu will be rendered
* using the given partial script. If no partial is registered, the menu
* will be rendered as an 'ul' element by the helper's internal method.
*
* @see renderPartial()
* @see renderMenu()
*
* @param Am_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
*/
public function render(Am_Navigation_Container $container = null)
{
if ($partial = $this->getPartial()) {
return $this->renderPartial($container, $partial);
} else {
return $this->renderMenu($container);
}
}
//
function setHasChildrenClass($class)
{
$this->_hasChildrenClass = $class;
return $this;
}
function getLiClass(Am_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\"";
}
/**
* Renders a normal menu (called from {@link renderMenu()})
*
* @param Am_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?
* @return string
*/
protected function _renderMenu(Am_Navigation_Container $container,
$ulClass,
$indent,
$innerIndent,
$minDepth,
$maxDepth,
$onlyActive,
$expandSibs,
$ulId,
$addPageClassToLi,
$activeClass,
$parentClass,
$renderParentClass)
{
$html = '';
// find deepest active
if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
$foundPage = $found['page'];
$foundDepth = $found['depth'];
} else {
$foundPage = null;
}
// create iterator
$iterator = new RecursiveIteratorIterator($container,
RecursiveIteratorIterator::SELF_FIRST);
if (is_int($maxDepth)) {
$iterator->setMaxDepth($maxDepth);
}
// iterate container
$prevDepth = -1;
foreach ($iterator as $page) {
$depth = $iterator->getDepth();
$isActive = $page->isActive(true);
if ($depth < $minDepth || !$this->accept($page)) {
// page is below minDepth or not accepted by acl/visibilty
continue;
} else if ($onlyActive && !$isActive) {
// page is not active itself, but might be in the active branch
$accept = false;
if ($foundPage) {
if ($foundPage->hasPage($page)) {
// accept if page is a direct child of the active page
$accept = true;
} else if ($foundPage->getParent()->hasPage($page)) {
// page is a sibling of the active page...
if (!$foundPage->hasPages() ||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
// accept if active page has no children, or the
// children are too deep to be rendered
$accept = true;
}
}
}
if (!$accept) {
continue;
}
}
// make sure indentation is correct
$depth -= $minDepth;
$myIndent = $indent . str_repeat(' ', $depth);
if ($depth > $prevDepth) {
// start new ul tag
if ($ulClass && $depth == 0) {
$ulClass = ' class="' . $ulClass . '"';
} else {
$ulClass = '';
}
$html .= $myIndent . '
* // proxy to Menu helper and render container:
* echo $this->navigation()->menu();
*
* // proxy to Breadcrumbs helper and set indentation:
* $this->navigation()->breadcrumbs()->setIndent(8);
*
* // proxy to container and find all pages with 'blog' route:
* $blogPages = $this->navigation()->findAllByRoute('blog');
*
*
* @param string $method helper name or method name in
* container
* @param array $arguments [optional] arguments to pass
* @return mixed returns what the proxied call returns
* @throws Zend_View_Exception if proxying to a helper, and the
* helper is not an instance of the
* interface specified in
* {@link findHelper()}
* @throws Zend_Navigation_Exception if method does not exist in container
*/
public function __call($method, array $arguments = array())
{
// check if call should proxy to another helper
if ($helper = $this->findHelper($method, false)) {
return call_user_func_array(array($helper, $method), $arguments);
}
// default behaviour: proxy call to container
return parent::__call($method, $arguments);
}
/**
* Returns the helper matching $proxy
*
* The helper must implement the interface
* {@link Zend_View_Helper_Navigation_Helper}.
*
* @param string $proxy helper name
* @param bool $strict [optional] whether
* exceptions should be
* thrown if something goes
* wrong. Default is true.
* @return Zend_View_Helper_Navigation_Helper helper instance
* @throws Zend_Loader_PluginLoader_Exception if $strict is true and
* helper cannot be found
* @throws Zend_View_Exception if $strict is true and
* helper does not implement
* the specified interface
*/
public function findHelper($proxy, $strict = true)
{
if (isset($this->_helpers[$proxy])) {
return $this->_helpers[$proxy];
}
if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) {
// Add navigation helper path at the beginning
$paths = $this->view->getHelperPaths();
$this->view->setHelperPath(null);
$this->view->addHelperPath(
str_replace('_', '/', self::NS),
self::NS);
foreach ($paths as $ns => $path) {
$this->view->addHelperPath($path, $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;
}
/**
* Injects container, ACL, and translator to the given $helper if this
* helper is configured to do so
*
* @param Zend_View_Helper_Navigation_Helper $helper helper instance
* @return void
*/
protected function _inject(Zend_View_Helper_Navigation_Helper $helper)
{
if ($this->getInjectContainer() && !$helper->hasContainer()) {
$helper->setContainer($this->getContainer());
}
if ($this->getInjectAcl()) {
if (!$helper->hasAcl()) {
$helper->setAcl($this->getAcl());
}
if (!$helper->hasRole()) {
$helper->setRole($this->getRole());
}
}
if ($this->getInjectTranslator() && !$helper->hasTranslator()) {
$helper->setTranslator($this->getTranslator());
}
}
// Accessors:
/**
* Sets the default proxy to use in {@link render()}
*
* @param string $proxy default proxy
* @return Zend_View_Helper_Navigation fluent interface, returns self
*/
public function setDefaultProxy($proxy)
{
$this->_defaultProxy = (string) $proxy;
return $this;
}
/**
* Returns the default proxy to use in {@link render()}
*
* @return string the default proxy to use in {@link render()}
*/
public function getDefaultProxy()
{
return $this->_defaultProxy;
}
/**
* Sets whether container should be injected when proxying
*
* @param bool $injectContainer [optional] whether container should
* be injected when proxying. Default
* is true.
* @return Zend_View_Helper_Navigation fluent interface, returns self
*/
public function setInjectContainer($injectContainer = true)
{
$this->_injectContainer = (bool) $injectContainer;
return $this;
}
/**
* Returns whether container should be injected when proxying
*
* @return bool whether container should be injected when proxying
*/
public function getInjectContainer()
{
return $this->_injectContainer;
}
/**
* Sets whether ACL should be injected when proxying
*
* @param bool $injectAcl [optional] whether ACL should be
* injected when proxying. Default is
* true.
* @return Zend_View_Helper_Navigation fluent interface, returns self
*/
public function setInjectAcl($injectAcl = true)
{
$this->_injectAcl = (bool) $injectAcl;
return $this;
}
/**
* Returns whether ACL should be injected when proxying
*
* @return bool whether ACL should be injected when proxying
*/
public function getInjectAcl()
{
return $this->_injectAcl;
}
/**
* Sets whether translator should be injected when proxying
*
* @param bool $injectTranslator [optional] whether translator should
* be injected when proxying. Default
* is true.
* @return Zend_View_Helper_Navigation fluent interface, returns self
*/
public function setInjectTranslator($injectTranslator = true)
{
$this->_injectTranslator = (bool) $injectTranslator;
return $this;
}
/**
* Returns whether translator should be injected when proxying
*
* @return bool whether translator should be injected when proxying
*/
public function getInjectTranslator()
{
return $this->_injectTranslator;
}
// Zend_View_Helper_Navigation_Helper:
/**
* Renders helper
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
* @throws Zend_Loader_PluginLoader_Exception if helper cannot be found
* @throws Zend_View_Exception if helper doesn't implement
* the interface specified in
* {@link findHelper()}
*/
public function render(Zend_Navigation_Container $container = null)
{
$helper = $this->findHelper($this->getDefaultProxy());
return $helper->render($container);
}
}
Helper/FormSelect.php 0000644 00000015405 15210162401 0010534 0 ustar 00 \n")
{
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
extract($info); // name, id, value, attribs, options, listsep, disable
// force $value to array so we can compare multiple values to multiple
// options; also ensure it's a string for comparison purposes.
$value = array_map('strval', (array) $value);
// check if element may have multiple values
$multiple = '';
if (substr($name, -2) == '[]') {
// multiple implied by the name
$multiple = ' multiple="multiple"';
}
if (isset($attribs['multiple'])) {
// Attribute set
if ($attribs['multiple']) {
// True attribute; set multiple attribute
$multiple = ' multiple="multiple"';
// Make sure name indicates multiple values are allowed
if (!empty($multiple) && (substr($name, -2) != '[]')) {
$name .= '[]';
}
} else {
// False attribute; ensure attribute not set
$multiple = '';
}
unset($attribs['multiple']);
}
// handle the options classes
$optionClasses = array();
if (isset($attribs['optionClasses'])) {
$optionClasses = $attribs['optionClasses'];
unset($attribs['optionClasses']);
}
// now start building the XHTML.
$disabled = '';
if (true === $disable) {
$disabled = ' disabled="disabled"';
}
// Build the surrounding select element first.
$xhtml = '";
return $xhtml;
}
/**
* Builds the actual ";
return $opt;
}
}
Helper/HtmlList.php 0000644 00000005430 15210162401 0010226 0 ustar 00 setView($this->view);
throw $e;
}
$list = '';
foreach ($items as $item) {
if (!is_array($item)) {
if ($escape) {
$item = $this->view->escape($item);
}
$list .= '
* // METHOD // SAME AS
* $h->findRelNext($page); // $h->findRelation($page, 'rel', 'next')
* $h->findRevSection($page); // $h->findRelation($page, 'rev', 'section');
* $h->findRelFoo($page); // $h->findRelation($page, 'rel', 'foo');
*
*
* @param string $method method name
* @param array $arguments method arguments
* @throws Zend_Navigation_Exception if method does not exist in container
*/
public function __call($method, array $arguments = array())
{
if (@preg_match('/find(Rel|Rev)(.+)/', $method, $match)) {
return $this->findRelation($arguments[0],
strtolower($match[1]),
strtolower($match[2]));
}
return parent::__call($method, $arguments);
}
// Accessors:
/**
* Sets the helper's render flag
*
* The helper uses the bitwise '&' operator against the hex values of the
* render constants. This means that the flag can is "bitwised" value of
* the render constants. Examples:
*
* // render all links except glossary
* $flag = Zend_View_Helper_Navigation_Links:RENDER_ALL ^
* Zend_View_Helper_Navigation_Links:RENDER_GLOSSARY;
* $helper->setRenderFlag($flag);
*
* // render only chapters and sections
* $flag = Zend_View_Helper_Navigation_Links:RENDER_CHAPTER |
* Zend_View_Helper_Navigation_Links:RENDER_SECTION;
* $helper->setRenderFlag($flag);
*
* // render only relations that are not native W3C relations
* $helper->setRenderFlag(Zend_View_Helper_Navigation_Links:RENDER_CUSTOM);
*
* // render all relations (default)
* $helper->setRenderFlag(Zend_View_Helper_Navigation_Links:RENDER_ALL);
*
*
* Note that custom relations can also be rendered directly using the
* {@link renderLink()} method.
*
* @param int $renderFlag render flag
* @return Zend_View_Helper_Navigation_Links fluent interface, returns self
*/
public function setRenderFlag($renderFlag)
{
$this->_renderFlag = (int) $renderFlag;
return $this;
}
/**
* Returns the helper's render flag
*
* @return int render flag
*/
public function getRenderFlag()
{
return $this->_renderFlag;
}
// Finder methods:
/**
* Finds all relations (forward and reverse) for the given $page
*
* The form of the returned array:
*
* // $page denotes an instance of Zend_Navigation_Page
* $returned = array(
* 'rel' => array(
* 'alternate' => array($page, $page, $page),
* 'start' => array($page),
* 'next' => array($page),
* 'prev' => array($page),
* 'canonical' => array($page)
* ),
* 'rev' => array(
* 'section' => array($page)
* )
* );
*
*
* @param Zend_Navigation_Page $page page to find links for
* @return array related pages
*/
public function findAllRelations(Zend_Navigation_Page $page,
$flag = null)
{
if (!is_int($flag)) {
$flag = self::RENDER_ALL;
}
$result = array('rel' => array(), 'rev' => array());
$native = array_values(self::$_RELATIONS);
foreach (array_keys($result) as $rel) {
$meth = 'getDefined' . ucfirst($rel);
$types = array_merge($native, array_diff($page->$meth(), $native));
foreach ($types as $type) {
if (!$relFlag = array_search($type, self::$_RELATIONS)) {
$relFlag = self::RENDER_CUSTOM;
}
if (!($flag & $relFlag)) {
continue;
}
if ($found = $this->findRelation($page, $rel, $type)) {
if (!is_array($found)) {
$found = array($found);
}
$result[$rel][$type] = $found;
}
}
}
return $result;
}
/**
* Finds relations of the given $rel=$type from $page
*
* This method will first look for relations in the page instance, then
* by searching the root container if nothing was found in the page.
*
* @param Zend_Navigation_Page $page page to find relations for
* @param string $rel relation, "rel" or "rev"
* @param string $type link type, e.g. 'start', 'next'
* @return Zend_Navigaiton_Page|array|null page(s), or null if not found
* @throws Zend_View_Exception if $rel is not "rel" or "rev"
*/
public function findRelation(Zend_Navigation_Page $page, $rel, $type)
{
if (!in_array($rel, array('rel', 'rev'))) {
//--//require_once 'Zend/View/Exception.php';
$e = new Zend_View_Exception(sprintf(
'Invalid argument: $rel must be "rel" or "rev"; "%s" given',
$rel));
$e->setView($this->view);
throw $e;
}
if (!$result = $this->_findFromProperty($page, $rel, $type)) {
$result = $this->_findFromSearch($page, $rel, $type);
}
return $result;
}
/**
* Finds relations of given $type for $page by checking if the
* relation is specified as a property of $page
*
* @param Zend_Navigation_Page $page page to find relations for
* @param string $rel relation, 'rel' or 'rev'
* @param string $type link type, e.g. 'start', 'next'
* @return Zend_Navigation_Page|array|null page(s), or null if not found
*/
protected function _findFromProperty(Zend_Navigation_Page $page, $rel, $type)
{
$method = 'get' . ucfirst($rel);
if ($result = $page->$method($type)) {
if ($result = $this->_convertToPages($result)) {
if (!is_array($result)) {
$result = array($result);
}
foreach ($result as $key => $page) {
if (!$this->accept($page)) {
unset($result[$key]);
}
}
return count($result) == 1 ? $result[0] : $result;
}
}
return null;
}
/**
* Finds relations of given $rel=$type for $page by using the helper to
* search for the relation in the root container
*
* @param Zend_Navigation_Page $page page to find relations for
* @param string $rel relation, 'rel' or 'rev'
* @param string $type link type, e.g. 'start', 'next', etc
* @return array|null array of pages, or null if not found
*/
protected function _findFromSearch(Zend_Navigation_Page $page, $rel, $type)
{
$found = null;
$method = 'search' . ucfirst($rel) . ucfirst($type);
if (method_exists($this, $method)) {
$found = $this->$method($page);
}
return $found;
}
// Search methods:
/**
* Searches the root container for the forward 'start' relation of the given
* $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to the first document in a collection of documents. This link type
* tells search engines which document is considered by the author to be the
* starting point of the collection.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|null page or null
*/
public function searchRelStart(Zend_Navigation_Page $page)
{
$found = $this->_findRoot($page);
if (!$found instanceof Zend_Navigation_Page) {
$found->rewind();
$found = $found->current();
}
if ($found === $page || !$this->accept($found)) {
$found = null;
}
return $found;
}
/**
* Searches the root container for the forward 'next' relation of the given
* $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to the next document in a linear sequence of documents. User
* agents may choose to preload the "next" document, to reduce the perceived
* load time.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|null page(s) or null
*/
public function searchRelNext(Zend_Navigation_Page $page)
{
$found = null;
$break = false;
$iterator = new RecursiveIteratorIterator($this->_findRoot($page),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $intermediate) {
if ($intermediate === $page) {
// current page; break at next accepted page
$break = true;
continue;
}
if ($break && $this->accept($intermediate)) {
$found = $intermediate;
break;
}
}
return $found;
}
/**
* Searches the root container for the forward 'prev' relation of the given
* $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to the previous document in an ordered series of documents. Some
* user agents also support the synonym "Previous".
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|null page or null
*/
public function searchRelPrev(Zend_Navigation_Page $page)
{
$found = null;
$prev = null;
$iterator = new RecursiveIteratorIterator(
$this->_findRoot($page),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $intermediate) {
if (!$this->accept($intermediate)) {
continue;
}
if ($intermediate === $page) {
$found = $prev;
break;
}
$prev = $intermediate;
}
return $found;
}
/**
* Searches the root container for forward 'chapter' relations of the given
* $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to a document serving as a chapter in a collection of documents.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|array|null page(s) or null
*/
public function searchRelChapter(Zend_Navigation_Page $page)
{
$found = array();
// find first level of pages
$root = $this->_findRoot($page);
// find start page(s)
$start = $this->findRelation($page, 'rel', 'start');
if (!is_array($start)) {
$start = array($start);
}
foreach ($root as $chapter) {
// exclude self and start page from chapters
if ($chapter !== $page &&
!in_array($chapter, $start) &&
$this->accept($chapter)) {
$found[] = $chapter;
}
}
switch (count($found)) {
case 0:
return null;
case 1:
return $found[0];
default:
return $found;
}
}
/**
* Searches the root container for forward 'section' relations of the given
* $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to a document serving as a section in a collection of documents.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|array|null page(s) or null
*/
public function searchRelSection(Zend_Navigation_Page $page)
{
$found = array();
// check if given page has pages and is a chapter page
if ($page->hasPages() && $this->_findRoot($page)->hasPage($page)) {
foreach ($page as $section) {
if ($this->accept($section)) {
$found[] = $section;
}
}
}
switch (count($found)) {
case 0:
return null;
case 1:
return $found[0];
default:
return $found;
}
}
/**
* Searches the root container for forward 'subsection' relations of the
* given $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to a document serving as a subsection in a collection of
* documents.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|array|null page(s) or null
*/
public function searchRelSubsection(Zend_Navigation_Page $page)
{
$found = array();
if ($page->hasPages()) {
// given page has child pages, loop chapters
foreach ($this->_findRoot($page) as $chapter) {
// is page a section?
if ($chapter->hasPage($page)) {
foreach ($page as $subsection) {
if ($this->accept($subsection)) {
$found[] = $subsection;
}
}
}
}
}
switch (count($found)) {
case 0:
return null;
case 1:
return $found[0];
default:
return $found;
}
}
/**
* Searches the root container for the reverse 'section' relation of the
* given $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to a document serving as a section in a collection of documents.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|null page(s) or null
*/
public function searchRevSection(Zend_Navigation_Page $page)
{
$found = null;
if ($parent = $page->getParent()) {
if ($parent instanceof Zend_Navigation_Page &&
$this->_findRoot($page)->hasPage($parent)) {
$found = $parent;
}
}
return $found;
}
/**
* Searches the root container for the reverse 'section' relation of the
* given $page
*
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
* Refers to a document serving as a subsection in a collection of
* documents.
*
* @param Zend_Navigation_Page $page page to find relation for
* @return Zend_Navigation_Page|null page(s) or null
*/
public function searchRevSubsection(Zend_Navigation_Page $page)
{
$found = null;
if ($parent = $page->getParent()) {
if ($parent instanceof Zend_Navigation_Page) {
$root = $this->_findRoot($page);
foreach ($root as $chapter) {
if ($chapter->hasPage($parent)) {
$found = $parent;
break;
}
}
}
}
return $found;
}
// Util methods:
/**
* Returns the root container of the given page
*
* When rendering a container, the render method still store the given
* container as the root container, and unset it when done rendering. This
* makes sure finder methods will not traverse above the container given
* to the render method.
*
* @param Zend_Navigaiton_Page $page page to find root for
* @return Zend_Navigation_Container the root container of the given page
*/
protected function _findRoot(Zend_Navigation_Page $page)
{
if ($this->_root) {
return $this->_root;
}
$root = $page;
while ($parent = $page->getParent()) {
$root = $parent;
if ($parent instanceof Zend_Navigation_Page) {
$page = $parent;
} else {
break;
}
}
return $root;
}
/**
* 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 Zend_Navigation_Page|array|null empty if unable to convert
*/
protected function _convertToPages($mixed, $recursive = true)
{
if (is_object($mixed)) {
if ($mixed instanceof Zend_Navigation_Page) {
// value is a page instance; return directly
return $mixed;
} elseif ($mixed instanceof Zend_Navigation_Container) {
// value is a container; return pages in it
$pages = array();
foreach ($mixed as $page) {
$pages[] = $page;
}
return $pages;
} elseif ($mixed instanceof Zend_Config) {
// convert config object to array and extract
return $this->_convertToPages($mixed->toArray(), $recursive);
}
} elseif (is_string($mixed)) {
// value is a string; make an URI page
return Zend_Navigation_Page::factory(array(
'type' => 'uri',
'uri' => $mixed
));
} elseif (is_array($mixed) && !empty($mixed)) {
if ($recursive && is_numeric(key($mixed))) {
// first key is numeric; assume several pages
$pages = array();
foreach ($mixed as $value) {
if ($value = $this->_convertToPages($value, false)) {
$pages[] = $value;
}
}
return $pages;
} else {
// pass array to factory directly
try {
$page = Zend_Navigation_Page::factory($mixed);
return $page;
} catch (Exception $e) {
}
}
}
// nothing found
return null;
}
// Render methods:
/**
* 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 '_htmlAttribs($attribs) .
$this->getClosingBracket();
}
// Zend_View_Helper_Navigation_Helper:
/**
* Renders helper
*
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
*/
public function render(Zend_Navigation_Container $container = null)
{
if (null === $container) {
$container = $this->getContainer();
}
if ($active = $this->findActive($container)) {
$active = $active['page'];
} else {
// no active page
return '';
}
$output = '';
$indent = $this->getIndent();
$this->_root = $container;
$result = $this->findAllRelations($active, $this->getRenderFlag());
foreach ($result as $attrib => $types) {
foreach ($types as $relation => $pages) {
foreach ($pages as $page) {
if ($r = $this->renderLink($page, $attrib, $relation)) {
$output .= $indent . $r . $this->getEOL();
}
}
}
}
$this->_root = null;
// return output (trim last newline by spec)
return strlen($output) ? rtrim($output, self::EOL) : '';
}
}
Helper/Navigation/Menu.php 0000644 00000114234 15210162401 0011474 0 ustar 00 setContainer($container);
}
return $this;
}
// Accessors:
/**
* Sets CSS class to use for the first 'ul' element when rendering
*
* @param string $ulClass CSS class to set
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setUlClass($ulClass)
{
if (is_string($ulClass)) {
$this->_ulClass = $ulClass;
}
return $this;
}
/**
* Returns CSS class to use for the first 'ul' element when rendering
*
* @return string CSS class
*/
public function getUlClass()
{
return $this->_ulClass;
}
/**
* Sets unique identifier (id) to use for the first 'ul' element when
* rendering
*
* @param string|null $ulId Unique identifier (id) to set
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setUlId($ulId)
{
if (is_string($ulId)) {
$this->_ulId = $ulId;
}
return $this;
}
/**
* Returns unique identifier (id) to use for the first 'ul' element when
* rendering
*
* @return string|null Unique identifier (id); Default is 'null'
*/
public function getUlId()
{
return $this->_ulId;
}
/**
* Sets CSS class to use for the active elements when rendering
*
* @param string $activeClass CSS class to set
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setActiveClass($activeClass)
{
if (is_string($activeClass)) {
$this->_activeClass = $activeClass;
}
return $this;
}
/**
* Returns CSS class to use for the active elements when rendering
*
* @return string CSS class
*/
public function getActiveClass()
{
return $this->_activeClass;
}
/**
* Sets CSS class to use for the parent li elements when rendering
*
* @param string $parentClass CSS class to set to parents
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setParentClass($parentClass)
{
if (is_string($parentClass)) {
$this->_parentClass = $parentClass;
}
return $this;
}
/**
* Returns CSS class to use for the parent lie elements when rendering
*
* @return string CSS class
*/
public function getParentClass()
{
return $this->_parentClass;
}
/**
* Enables/disables rendering of parent class to the li element
*
* @param bool $flag [optional] render with parent
* class. Default is true.
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setRenderParentClass($flag = true)
{
$this->_renderParentClass = (bool) $flag;
return $this;
}
/**
* Returns flag indicating whether parent class should be rendered to the li
* element
*
* @return bool whether parent class should be rendered
*/
public function getRenderParentClass()
{
return $this->_renderParentClass;
}
/**
* Sets a flag indicating whether only active branch should be rendered
*
* @param bool $flag [optional] render only active
* branch. Default is true.
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setOnlyActiveBranch($flag = true)
{
$this->_onlyActiveBranch = (bool) $flag;
return $this;
}
/**
* Returns a flag indicating whether only active branch should be rendered
*
* By default, this value is false, meaning the entire menu will be
* be rendered.
*
* @return bool whether only active branch should be rendered
*/
public function getOnlyActiveBranch()
{
return $this->_onlyActiveBranch;
}
/**
* Sets a flag indicating whether to expand all sibling nodes of the active branch
*
* @param bool $flag [optional] expand all siblings of
* nodes in the active branch. Default is true.
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setExpandSiblingNodesOfActiveBranch($flag = true)
{
$this->_expandSiblingNodesOfActiveBranch = (bool) $flag;
return $this;
}
/**
* Returns a flag indicating whether to expand all sibling nodes of the active branch
*
* By default, this value is false, meaning the entire menu will be
* be rendered.
*
* @return bool whether siblings of nodes in the active branch should be expanded
*/
public function getExpandSiblingNodesOfActiveBranch()
{
return $this->_expandSiblingNodesOfActiveBranch;
}
/**
* Enables/disables rendering of parents when only rendering active branch
*
* See {@link setOnlyActiveBranch()} for more information.
*
* @param bool $flag [optional] render parents when
* rendering active branch.
* Default is true.
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setRenderParents($flag = true)
{
$this->_renderParents = (bool) $flag;
return $this;
}
/**
* Returns flag indicating whether parents should be rendered when rendering
* only the active branch
*
* By default, this value is true.
*
* @return bool whether parents should be rendered
*/
public function getRenderParents()
{
return $this->_renderParents;
}
/**
* Sets which partial view script to use for rendering menu
*
* @param string|array $partial partial view script or null. 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 Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function setPartial($partial)
{
if (null === $partial || is_string($partial) || is_array($partial)) {
$this->_partial = $partial;
}
return $this;
}
/**
* Returns partial view script to use for rendering menu
*
* @return string|array|null
*/
public function getPartial()
{
return $this->_partial;
}
/**
* Adds CSS class from page to li element
*
* Before:
*
*
* Bar
*
*
*
* After:
*
*
* Bar
*
*
*
* @param bool $flag [optional] adds CSS class from
* page to li element
*
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
*/
public function addPageClassToLi($flag = true)
{
$this->_addPageClassToLi = (bool) $flag;
return $this;
}
/**
* Returns a flag indicating whether the CSS class from page to be added to
* li element
*
* @return bool
*/
public function getAddPageClassToLi()
{
return $this->_addPageClassToLi;
}
/**
* 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:
/**
* 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 . '>';
}
/**
* Normalizes given render options
*
* @param array $options [optional] options to normalize
* @return array normalized options
*/
protected function _normalizeOptions(array $options = array())
{
// Ident
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();
}
// UL id
if (isset($options['ulId']) && $options['ulId'] !== null) {
$options['ulId'] = (string) $options['ulId'];
} else {
$options['ulId'] = $this->getUlId();
}
// Active class
if (isset($options['activeClass']) && $options['activeClass'] !== null
) {
$options['activeClass'] = (string) $options['activeClass'];
} else {
$options['activeClass'] = $this->getActiveClass();
}
// Parent class
if (isset($options['parentClass']) && $options['parentClass'] !== null) {
$options['parentClass'] = (string) $options['parentClass'];
} else {
$options['parentClass'] = $this->getParentClass();
}
// Minimum depth
if (array_key_exists('minDepth', $options)) {
if (null !== $options['minDepth']) {
$options['minDepth'] = (int) $options['minDepth'];
}
} else {
$options['minDepth'] = $this->getMinDepth();
}
if ($options['minDepth'] < 0 || $options['minDepth'] === null) {
$options['minDepth'] = 0;
}
// Maximum depth
if (array_key_exists('maxDepth', $options)) {
if (null !== $options['maxDepth']) {
$options['maxDepth'] = (int) $options['maxDepth'];
}
} else {
$options['maxDepth'] = $this->getMaxDepth();
}
// Only active branch
if (!isset($options['onlyActiveBranch'])) {
$options['onlyActiveBranch'] = $this->getOnlyActiveBranch();
}
// Expand sibling nodes of active branch
if (!isset($options['expandSiblingNodesOfActiveBranch'])) {
$options['expandSiblingNodesOfActiveBranch'] = $this->getExpandSiblingNodesOfActiveBranch();
}
// Render parents?
if (!isset($options['renderParents'])) {
$options['renderParents'] = $this->getRenderParents();
}
// Render parent class?
if (!isset($options['renderParentClass'])) {
$options['renderParentClass'] = $this->getRenderParentClass();
}
// Add page CSS class to LI element
if (!isset($options['addPageClassToLi'])) {
$options['addPageClassToLi'] = $this->getAddPageClassToLi();
}
return $options;
}
// Render methods:
/**
* Renders the deepest active menu within [$minDepth, $maxDeth], (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 string $innerIndent inner indentation
* @param int|null $minDepth minimum depth
* @param int|null $maxDepth maximum depth
* @param string|null $ulId unique identifier (id)
* for first UL
* @param bool $addPageClassToLi adds CSS class from
* page to li element
* @param string|null $activeClass CSS class for active
* element
* @param string $parentClass CSS class for parent
* li's
* @param bool $renderParentClass Render parent class?
* @return string rendered menu (HTML)
*/
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$innerIndent,
$minDepth,
$maxDepth,
$ulId,
$addPageClassToLi,
$activeClass,
$parentClass,
$renderParentClass)
{
if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) {
return '';
}
// special case if active page is one below minDepth
if ($active['depth'] < $minDepth) {
if (!$active['page']->hasPages()) {
return '';
}
} else if (!$active['page']->hasPages()) {
// found pages has no children; render siblings
$active['page'] = $active['page']->getParent();
} else if (is_int($maxDepth) && $active['depth'] + 1 > $maxDepth) {
// children are below max depth; render siblings
$active['page'] = $active['page']->getParent();
}
$attribs = array(
'class' => $ulClass,
'id' => $ulId,
);
// We don't need a prefix for the menu ID (backup)
$skipValue = $this->_skipPrefixForId;
$this->skipPrefixForId();
$html = $indent . '
* renderMenu($container, array(
* 'indent' => $indent,
* 'ulClass' => $ulClass,
* 'minDepth' => null,
* 'maxDepth' => null,
* 'onlyActiveBranch' => true,
* 'renderParents' => false
* ));
*
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to render
* the container registered in
* the helper.
* @param string|null $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|null $ulId [optional] Unique identifier
* (id) use for UL element
* @param bool $addPageClassToLi adds CSS class from
* page to li element
* @param string|int $innerIndent [optional] inner
* indentation as a string
* or number of spaces.
* Default is to use the
* {@link getInnerIndent()}.
* @return string rendered content
*/
public function renderSubMenu(Zend_Navigation_Container $container = null,
$ulClass = null,
$indent = null,
$ulId = null,
$addPageClassToLi = false,
$innerIndent = null)
{
return $this->renderMenu($container, array(
'indent' => $indent,
'innerIndent' => $innerIndent,
'ulClass' => $ulClass,
'minDepth' => null,
'maxDepth' => null,
'onlyActiveBranch' => true,
'renderParents' => false,
'ulId' => $ulId,
'addPageClassToLi' => $addPageClassToLi,
));
}
/**
* 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.
* echo 'Number of pages: ', count($this->container);.
*
* @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
*
* @throws Zend_View_Exception When no partial script is set
*/
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;
}
$model = array(
'container' => $container
);
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);
}
// Zend_View_Helper_Navigation_Helper:
/**
* Renders menu
*
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
*
* If a partial view is registered in the helper, the menu will be rendered
* using the given partial script. If no partial is registered, the menu
* will be rendered as an 'ul' element by the helper's internal method.
*
* @see renderPartial()
* @see renderMenu()
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
*/
public function render(Zend_Navigation_Container $container = null)
{
if ($partial = $this->getPartial()) {
return $this->renderPartial($container, $partial);
} else {
return $this->renderMenu($container);
}
}
}
Helper/Navigation/HelperAbstract.php 0000644 00000074431 15210162401 0013477 0 ustar 00 _container = $container;
return $this;
}
/**
* Returns the navigation container helper operates on by default
*
* Implements {@link Zend_View_Helper_Navigation_Interface::getContainer()}.
*
* If a helper is not explicitly set in this helper instance by calling
* {@link setContainer()} or by passing it through the helper entry point,
* this method will look in {@link Zend_Registry} for a container by using
* the key 'Zend_Navigation'.
*
* If no container is set, and nothing is found in Zend_Registry, a new
* container will be instantiated and stored in the helper.
*
* @return Zend_Navigation_Container navigation container
*/
public function getContainer()
{
if (null === $this->_container) {
// try to fetch from registry first
//--//require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Navigation')) {
$nav = Zend_Registry::get('Zend_Navigation');
if ($nav instanceof Zend_Navigation_Container) {
return $this->_container = $nav;
}
}
// nothing found in registry, create new container
//--//require_once 'Zend/Navigation.php';
$this->_container = new Zend_Navigation();
}
return $this->_container;
}
/**
* Sets the minimum depth a page must have to be included when rendering
*
* @param int $minDepth [optional] minimum
* depth. Default is
* null, which sets
* no minimum depth.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setMinDepth($minDepth = null)
{
if (null === $minDepth || is_int($minDepth)) {
$this->_minDepth = $minDepth;
} else {
$this->_minDepth = (int) $minDepth;
}
return $this;
}
/**
* Returns minimum depth a page must have to be included when rendering
*
* @return int|null minimum depth or null
*/
public function getMinDepth()
{
if (!is_int($this->_minDepth) || $this->_minDepth < 0) {
return 0;
}
return $this->_minDepth;
}
/**
* Sets the maximum depth a page can have to be included when rendering
*
* @param int $maxDepth [optional] maximum
* depth. Default is
* null, which sets no
* maximum depth.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setMaxDepth($maxDepth = null)
{
if (null === $maxDepth || is_int($maxDepth)) {
$this->_maxDepth = $maxDepth;
} else {
$this->_maxDepth = (int) $maxDepth;
}
return $this;
}
/**
* Returns maximum depth a page can have to be included when rendering
*
* @return int|null maximum depth or null
*/
public function getMaxDepth()
{
return $this->_maxDepth;
}
/**
* Set the 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 setIndent($indent)
{
$this->_indent = $this->_getWhitespace($indent);
return $this;
}
/**
* Returns indentation (format output is respected)
*
* @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 prefix for IDs when they are normalized
*
* @param string $prefix Prefix for IDs
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface, returns self
*/
public function setPrefixForId($prefix)
{
if (is_string($prefix)) {
$this->_prefixForId = trim($prefix);
}
return $this;
}
/**
* Returns prefix for IDs when they are normalized
*
* @return string Prefix for
*/
public function getPrefixForId()
{
if (null === $this->_prefixForId) {
$prefix = get_class($this);
$this->_prefixForId = strtolower(
trim(substr($prefix, strrpos($prefix, '_')), '_')
) . '-';
}
return $this->_prefixForId;
}
/**
* Skip the current prefix for IDs when they are normalized
*
* @param bool $flag
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface, returns self
*/
public function skipPrefixForId($flag = true)
{
$this->_skipPrefixForId = (bool) $flag;
return $this;
}
/**
* Sets translator to use in helper
*
* Implements {@link Zend_View_Helper_Navigation_Helper::setTranslator()}.
*
* @param mixed $translator [optional] translator.
* Expects an object of
* type
* {@link Zend_Translate_Adapter}
* or {@link Zend_Translate},
* or null. Default is
* null, which sets no
* translator.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setTranslator($translator = null)
{
if (null == $translator ||
$translator instanceof Zend_Translate_Adapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
}
return $this;
}
/**
* Returns translator used in helper
*
* Implements {@link Zend_View_Helper_Navigation_Helper::getTranslator()}.
*
* @return Zend_Translate_Adapter|null translator or null
*/
public function getTranslator()
{
if (null === $this->_translator) {
//--//require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Translate')) {
$this->setTranslator(Zend_Registry::get('Zend_Translate'));
}
}
return $this->_translator;
}
/**
* Sets ACL to use when iterating pages
*
* Implements {@link Zend_View_Helper_Navigation_Helper::setAcl()}.
*
* @param Zend_Acl $acl [optional] ACL object.
* Default is null.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setAcl(Zend_Acl $acl = null)
{
$this->_acl = $acl;
return $this;
}
/**
* Returns ACL or null if it isn't set using {@link setAcl()} or
* {@link setDefaultAcl()}
*
* Implements {@link Zend_View_Helper_Navigation_Helper::getAcl()}.
*
* @return Zend_Acl|null ACL object or null
*/
public function getAcl()
{
if ($this->_acl === null && self::$_defaultAcl !== null) {
return self::$_defaultAcl;
}
return $this->_acl;
}
/**
* 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;
}
/**
* Returns ACL role to use when iterating pages, or null if it isn't set
* using {@link setRole()} or {@link setDefaultRole()}
*
* Implements {@link Zend_View_Helper_Navigation_Helper::getRole()}.
*
* @return string|Zend_Acl_Role_Interface|null role or null
*/
public function getRole()
{
if ($this->_role === null && self::$_defaultRole !== null) {
return self::$_defaultRole;
}
return $this->_role;
}
/**
* Sets whether ACL should be used
*
* Implements {@link Zend_View_Helper_Navigation_Helper::setUseAcl()}.
*
* @param bool $useAcl [optional] whether ACL
* should be used.
* Default is true.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setUseAcl($useAcl = true)
{
$this->_useAcl = (bool) $useAcl;
return $this;
}
/**
* Returns whether ACL should be used
*
* Implements {@link Zend_View_Helper_Navigation_Helper::getUseAcl()}.
*
* @return bool whether ACL should be used
*/
public function getUseAcl()
{
return $this->_useAcl;
}
/**
* Return renderInvisible flag
*
* @return bool
*/
public function getRenderInvisible()
{
return $this->_renderInvisible;
}
/**
* Render invisible items?
*
* @param bool $renderInvisible [optional] boolean flag
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface
* returns self
*/
public function setRenderInvisible($renderInvisible = true)
{
$this->_renderInvisible = (bool) $renderInvisible;
return $this;
}
/**
* Sets whether translator should be used
*
* Implements {@link Zend_View_Helper_Navigation_Helper::setUseTranslator()}.
*
* @param bool $useTranslator [optional] whether
* translator should be
* used. Default is true.
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
* returns self
*/
public function setUseTranslator($useTranslator = true)
{
$this->_useTranslator = (bool) $useTranslator;
return $this;
}
/**
* Returns whether translator should be used
*
* Implements {@link Zend_View_Helper_Navigation_Helper::getUseTranslator()}.
*
* @return bool whether translator should be used
*/
public function getUseTranslator()
{
return $this->_useTranslator;
}
// Magic overloads:
/**
* Magic overload: Proxy calls to the navigation container
*
* @param string $method method name in container
* @param array $arguments [optional] arguments to pass
* @return mixed returns what the container returns
* @throws Zend_Navigation_Exception if method does not exist in container
*/
public function __call($method, array $arguments = array())
{
return call_user_func_array(
array($this->getContainer(), $method),
$arguments);
}
/**
* Magic overload: Proxy to {@link render()}.
*
* This method will trigger an E_USER_ERROR if rendering the helper causes
* an exception to be thrown.
*
* Implements {@link Zend_View_Helper_Navigation_Helper::__toString()}.
*
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
$msg = get_class($e) . ': ' . $e->getMessage();
trigger_error($msg, E_USER_ERROR);
return '';
}
}
// Public methods:
/**
* Finds the deepest active page in the given container
*
* @param Zend_Navigation_Container $container container to search
* @param int|null $minDepth [optional] minimum depth
* required for page to be
* valid. Default is to use
* {@link getMinDepth()}. A
* null value means no minimum
* depth required.
* @param int|null $minDepth [optional] maximum depth
* a page can have to be
* valid. Default is to use
* {@link getMaxDepth()}. A
* null value means no maximum
* depth required.
* @return array an associative array with
* the values 'depth' and
* 'page', or an empty array
* if not found
*/
public function findActive(Zend_Navigation_Container $container,
$minDepth = null,
$maxDepth = -1)
{
if (!is_int($minDepth)) {
$minDepth = $this->getMinDepth();
}
if ((!is_int($maxDepth) || $maxDepth < 0) && null !== $maxDepth) {
$maxDepth = $this->getMaxDepth();
}
$found = null;
$foundDepth = -1;
$iterator = new RecursiveIteratorIterator($container,
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $page) {
$currDepth = $iterator->getDepth();
if ($currDepth < $minDepth || !$this->accept($page)) {
// page is not accepted
continue;
}
if ($page->isActive(false) && $currDepth > $foundDepth) {
// found an active page at a deeper level than before
$found = $page;
$foundDepth = $currDepth;
}
}
if (is_int($maxDepth) && $foundDepth > $maxDepth) {
while ($foundDepth > $maxDepth) {
if (--$foundDepth < $minDepth) {
$found = null;
break;
}
$found = $found->getParent();
if (!$found instanceof Zend_Navigation_Page) {
$found = null;
break;
}
}
}
if ($found) {
return array('page' => $found, 'depth' => $foundDepth);
} else {
return array();
}
}
/**
* Checks if the helper has a container
*
* Implements {@link Zend_View_Helper_Navigation_Helper::hasContainer()}.
*
* @return bool whether the helper has a container or not
*/
public function hasContainer()
{
return null !== $this->_container;
}
/**
* Checks if the helper has an ACL instance
*
* Implements {@link Zend_View_Helper_Navigation_Helper::hasAcl()}.
*
* @return bool whether the helper has a an ACL instance or not
*/
public function hasAcl()
{
return null !== $this->_acl;
}
/**
* Checks if the helper has an ACL role
*
* Implements {@link Zend_View_Helper_Navigation_Helper::hasRole()}.
*
* @return bool whether the helper has a an ACL role or not
*/
public function hasRole()
{
return null !== $this->_role;
}
/**
* Checks if the helper has a translator
*
* Implements {@link Zend_View_Helper_Navigation_Helper::hasTranslator()}.
*
* @return bool whether the helper has a translator or not
*/
public function hasTranslator()
{
return null !== $this->_translator;
}
/**
* Returns an HTML string containing an 'a' element for the given page
*
* @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();
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 anchor element
$attribs = array_merge(
array(
'id' => $page->getId(),
'title' => $title,
'class' => $page->getClass(),
'href' => $page->getHref(),
'target' => $page->getTarget()
),
$page->getCustomHtmlAttribs()
);
return '_htmlAttribs($attribs) . '>'
. $this->view->escape($label)
. '';
}
// Iterator filter methods:
/**
* Determines whether a page should be accepted when iterating
*
* Rules:
* - If a page is not visible it is not accepted, unless RenderInvisible has
* been set to true.
* - If helper has no ACL, page is accepted
* - If helper has ACL, but no role, page is not accepted
* - If helper has ACL and role:
* - Page is accepted if it has no resource or privilege
* - Page is accepted if ACL allows page's resource or privilege
* - If page is accepted by the rules above and $recursive is true, the page
* will not be accepted if it is the descendant of a non-accepted page.
*
* @param Zend_Navigation_Page $page page to check
* @param bool $recursive [optional] if true, page will not
* be accepted if it is the
* descendant of a page that is not
* accepted. Default is true.
* @return bool whether page should be accepted
*/
public function accept(Zend_Navigation_Page $page, $recursive = true)
{
// accept by default
$accept = true;
if (!$page->isVisible(false) && !$this->getRenderInvisible()) {
// don't accept invisible pages
$accept = false;
} elseif ($this->getUseAcl() && !$this->_acceptAcl($page)) {
// acl is not amused
$accept = false;
}
if ($accept && $recursive) {
$parent = $page->getParent();
if ($parent instanceof Zend_Navigation_Page) {
$accept = $this->accept($parent, true);
}
}
return $accept;
}
/**
* 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;
}
// Util methods:
/**
* Retrieve whitespace representation of $indent
*
* @param int|string $indent
* @return string
*/
protected function _getWhitespace($indent)
{
if (is_int($indent)) {
$indent = str_repeat(' ', $indent);
}
return (string) $indent;
}
/**
* Converts an associative array to a string of tag attributes.
*
* Overloads {@link Zend_View_Helper_HtmlElement::_htmlAttribs()}.
*
* @param array $attribs an array where each key-value pair is converted
* to an attribute name and value
* @return string an attribute string
*/
protected function _htmlAttribs($attribs)
{
// filter out null values and empty string values
foreach ($attribs as $key => $value) {
if ($value === null || (is_string($value) && !strlen($value))) {
unset($attribs[$key]);
}
}
return parent::_htmlAttribs($attribs);
}
/**
* Normalize an ID
*
* Extends {@link Zend_View_Helper_HtmlElement::_normalizeId()}.
*
* @param string $value ID
* @return string Normalized ID
*/
protected function _normalizeId($value)
{
if (false === $this->_skipPrefixForId) {
$prefix = $this->getPrefixForId();
if (strlen($prefix)) {
return $prefix . $value;
}
}
return parent::_normalizeId($value);
}
// Static methods:
/**
* Sets default ACL to use if another ACL is not explicitly set
*
* @param Zend_Acl $acl [optional] ACL object. Default is null, which
* sets no ACL object.
* @return void
*/
public static function setDefaultAcl(Zend_Acl $acl = null)
{
self::$_defaultAcl = $acl;
}
/**
* Sets default ACL role(s) to use when iterating pages if not explicitly
* set later with {@link setRole()}
*
* @param midex $role [optional] role to set. Expects null,
* string, or an instance of
* {@link Zend_Acl_Role_Interface}.
* Default is null, which sets no default
* role.
* @throws Zend_View_Exception if role is invalid
* @return void
*/
public static function setDefaultRole($role = null)
{
if (null === $role ||
is_string($role) ||
$role instanceof Zend_Acl_Role_Interface) {
self::$_defaultRole = $role;
} else {
//--//require_once 'Zend/View/Exception.php';
throw new Zend_View_Exception(
'$role must be null|string|Zend_Acl_Role_Interface'
);
}
}
}
Helper/Navigation/Helper.php 0000644 00000016356 15210162401 0012015 0 ustar 00 setContainer($container);
}
return $this;
}
// Accessors:
/**
* Sets breadcrumb separator
*
* @param string $separator separator string
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
* returns self
*/
public function setSeparator($separator)
{
if (is_string($separator)) {
$this->_separator = $separator;
}
return $this;
}
/**
* Returns breadcrumb separator
*
* @return string breadcrumb separator
*/
public function getSeparator()
{
return $this->_separator;
}
/**
* Sets whether last page in breadcrumbs should be hyperlinked
*
* @param bool $linkLast whether last page should
* be hyperlinked
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
* returns self
*/
public function setLinkLast($linkLast)
{
$this->_linkLast = (bool) $linkLast;
return $this;
}
/**
* Returns whether last page in breadcrumbs should be hyperlinked
*
* @return bool whether last page in breadcrumbs should be hyperlinked
*/
public function getLinkLast()
{
return $this->_linkLast;
}
/**
* Sets which partial view script to use for rendering menu
*
* @param string|array $partial partial view script or
* null. 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 Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
* returns self
*/
public function setPartial($partial)
{
if (null === $partial || is_string($partial) || is_array($partial)) {
$this->_partial = $partial;
}
return $this;
}
/**
* Returns partial view script to use for rendering menu
*
* @return string|array|null
*/
public function getPartial()
{
return $this->_partial;
}
// Render methods:
/**
* Renders breadcrumbs by chaining 'a' elements with the separator
* registered in the helper
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
*/
public function renderStraight(Zend_Navigation_Container $container = null)
{
if (null === $container) {
$container = $this->getContainer();
}
// find deepest active
if (!$active = $this->findActive($container)) {
return '';
}
$active = $active['page'];
// put the deepest active page last in breadcrumbs
if ($this->getLinkLast()) {
$html = $this->htmlify($active);
} else {
$html = $active->getLabel();
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
$html = $t->translate($html);
}
$html = $this->view->escape($html);
}
// walk back to root
while ($parent = $active->getParent()) {
if ($parent instanceof Zend_Navigation_Page) {
// prepend crumb to html
$html = $this->htmlify($parent)
. $this->getSeparator()
. $html;
}
if ($parent === $container) {
// at the root of the given container
break;
}
$active = $parent;
}
return strlen($html) ? $this->getIndent() . $html : '';
}
/**
* 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 $this->container.
*
* @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);
}
// Zend_View_Helper_Navigation_Helper:
/**
* Renders helper
*
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
*
* @param Zend_Navigation_Container $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
* @return string helper output
*/
public function render(Zend_Navigation_Container $container = null)
{
if ($partial = $this->getPartial()) {
return $this->renderPartial($container, $partial);
} else {
return $this->renderStraight($container);
}
}
}
Helper/FormText.php 0000644 00000004472 15210162401 0010243 0 ustar 00 _getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
// build the element
$disabled = '';
if ($disable) {
// disabled
$disabled = ' disabled="disabled"';
}
$xhtml = '_htmlAttribs($attribs)
. $this->getClosingBracket();
return $xhtml;
}
}
Helper/RenderToPlaceholder.php 0000644 00000003346 15210162401 0012357 0 ustar 00 view->placeholder($placeholder)->captureStart();
echo $this->view->render($script);
$this->view->placeholder($placeholder)->captureEnd();
}
}
Helper/HeadTitle.php 0000644 00000014450 15210162401 0010333 0 ustar 00 getDefaultAttachOrder())
? Zend_View_Helper_Placeholder_Container_Abstract::APPEND
: $this->getDefaultAttachOrder();
}
$title = (string) $title;
if ($title !== '') {
if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {
$this->set($title);
} elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {
$this->prepend($title);
} else {
$this->append($title);
}
}
return $this;
}
/**
* Set a default order to add titles
*
* @param string $setType
*/
public function setDefaultAttachOrder($setType)
{
if (!in_array($setType, array(
Zend_View_Helper_Placeholder_Container_Abstract::APPEND,
Zend_View_Helper_Placeholder_Container_Abstract::SET,
Zend_View_Helper_Placeholder_Container_Abstract::PREPEND
))) {
//--//require_once 'Zend/View/Exception.php';
throw new Zend_View_Exception("You must use a valid attach order: 'PREPEND', 'APPEND' or 'SET'");
}
$this->_defaultAttachOrder = $setType;
return $this;
}
/**
* Get the default attach order, if any.
*
* @return mixed
*/
public function getDefaultAttachOrder()
{
return $this->_defaultAttachOrder;
}
/**
* 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;
}
/**
* Retrieve translation object
*
* If none is currently registered, attempts to pull it from the registry
* using the key 'Zend_Translate'.
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if (null === $this->_translator) {
//--//require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Translate')) {
$this->setTranslator(Zend_Registry::get('Zend_Translate'));
}
}
return $this->_translator;
}
/**
* Enables translation
*
* @return Zend_View_Helper_HeadTitle
*/
public function enableTranslation()
{
$this->_translate = true;
return $this;
}
/**
* Disables translation
*
* @return Zend_View_Helper_HeadTitle
*/
public function disableTranslation()
{
$this->_translate = false;
return $this;
}
/**
* Turn helper into string
*
* @param string|null $indent
* @param string|null $locale
* @return string
*/
public function toString($indent = null, $locale = null)
{
$indent = (null !== $indent)
? $this->getWhitespace($indent)
: $this->getIndent();
$items = array();
if($this->_translate && $translator = $this->getTranslator()) {
foreach ($this as $item) {
$items[] = $translator->translate($item, $locale);
}
} else {
foreach ($this as $item) {
$items[] = $item;
}
}
$separator = $this->getSeparator();
$output = '';
if(($prefix = $this->getPrefix())) {
$output .= $prefix;
}
$output .= implode($separator, $items);
if(($postfix = $this->getPostfix())) {
$output .= $postfix;
}
$output = ($this->_autoEscape) ? $this->_escape($output) : $output;
return $indent . '
* basePath/
* scripts/
* helpers/
* filters/
*
*
* @param string $path
* @param string $prefix Prefix to use for helper and filter paths
* @return Zend_View_Abstract
*/
public function setBasePath($path, $classPrefix = 'Zend_View')
{
$path = rtrim($path, '/');
$path = rtrim($path, '\\');
$path .= DIRECTORY_SEPARATOR;
$classPrefix = rtrim($classPrefix, '_') . '_';
$this->setScriptPath($path . 'scripts');
$this->setHelperPath($path . 'helpers', $classPrefix . 'Helper');
$this->setFilterPath($path . 'filters', $classPrefix . 'Filter');
return $this;
}
/**
* Given a base path, add script, helper, and filter paths relative to it
*
* Assumes a directory structure of:
*
* basePath/
* scripts/
* helpers/
* filters/
*
*
* @param string $path
* @param string $prefix Prefix to use for helper and filter paths
* @return Zend_View_Abstract
*/
public function addBasePath($path, $classPrefix = 'Zend_View')
{
$path = rtrim($path, '/');
$path = rtrim($path, '\\');
$path .= DIRECTORY_SEPARATOR;
$classPrefix = rtrim($classPrefix, '_') . '_';
$this->addScriptPath($path . 'scripts');
$this->addHelperPath($path . 'helpers', $classPrefix . 'Helper');
$this->addFilterPath($path . 'filters', $classPrefix . 'Filter');
return $this;
}
/**
* Adds to the stack of view script paths in LIFO order.
*
* @param string|array The directory (-ies) to add.
* @return Zend_View_Abstract
*/
public function addScriptPath($path)
{
$this->_addPath('script', $path);
return $this;
}
/**
* Resets the stack of view script paths.
*
* To clear all paths, use Zend_View::setScriptPath(null).
*
* @param string|array The directory (-ies) to set as the path.
* @return Zend_View_Abstract
*/
public function setScriptPath($path)
{
$this->_path['script'] = array();
$this->_addPath('script', $path);
return $this;
}
/**
* Return full path to a view script specified by $name
*
* @param string $name
* @return false|string False if script not found
* @throws Zend_View_Exception if no script directory set
*/
public function getScriptPath($name)
{
try {
$path = $this->_script($name);
return $path;
} catch (Zend_View_Exception $e) {
if (strstr($e->getMessage(), 'no view script directory set')) {
throw $e;
}
return false;
}
}
/**
* Returns an array of all currently set script paths
*
* @return array
*/
public function getScriptPaths()
{
return $this->_getPaths('script');
}
/**
* Set plugin loader for a particular plugin type
*
* @param Zend_Loader_PluginLoader $loader
* @param string $type
* @return Zend_View_Abstract
*/
public function setPluginLoader(Zend_Loader_PluginLoader $loader, $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"', $type));
$e->setView($this);
throw $e;
}
$this->_loaders[$type] = $loader;
return $this;
}
/**
* 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 Zend_Loader_PluginLoader(array(
$prefix => $pathPrefix
));
$this->_loaders[$type] = $loader;
break;
}
}
return $this->_loaders[$type];
}
/**
* Adds to the stack of helper paths in LIFO order.
*
* @param string|array The directory (-ies) to add.
* @param string $classPrefix Class prefix to use with classes in this
* directory; defaults to Zend_View_Helper
* @return Zend_View_Abstract
*/
public function addHelperPath($path, $classPrefix = 'Zend_View_Helper_')
{
return $this->_addPluginPath('helper', $classPrefix, (array) $path);
}
/**
* Resets the stack of helper paths.
*
* To clear all paths, use Zend_View::setHelperPath(null).
*
* @param string|array $path The directory (-ies) to set as the path.
* @param string $classPrefix The class prefix to apply to all elements in
* $path; defaults to Zend_View_Helper
* @return Zend_View_Abstract
*/
public function setHelperPath($path, $classPrefix = 'Zend_View_Helper_')
{
unset($this->_loaders['helper']);
return $this->addHelperPath($path, $classPrefix);
}
/**
* Get full path to a helper class file specified by $name
*
* @param string $name
* @return string|false False on failure, path on success
*/
public function getHelperPath($name)
{
return $this->_getPluginPath('helper', $name);
}
/**
* Returns an array of all currently set helper paths
*
* @return array
*/
public function getHelperPaths()
{
return $this->getPluginLoader('helper')->getPaths();
}
/**
* 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;
}
/**
* Get a helper by name
*
* @param string $name
* @return object
*/
public function getHelper($name)
{
return $this->_getPlugin('helper', $name);
}
/**
* Get array of all active helpers
*
* Only returns those that have already been instantiated.
*
* @return array
*/
public function getHelpers()
{
return $this->_helper;
}
/**
* Adds to the stack of filter paths in LIFO order.
*
* @param string|array The directory (-ies) to add.
* @param string $classPrefix Class prefix to use with classes in this
* directory; defaults to Zend_View_Filter
* @return Zend_View_Abstract
*/
public function addFilterPath($path, $classPrefix = 'Zend_View_Filter_')
{
return $this->_addPluginPath('filter', $classPrefix, (array) $path);
}
/**
* Resets the stack of filter paths.
*
* To clear all paths, use Zend_View::setFilterPath(null).
*
* @param string|array The directory (-ies) to set as the path.
* @param string $classPrefix The class prefix to apply to all elements in
* $path; defaults to Zend_View_Filter
* @return Zend_View_Abstract
*/
public function setFilterPath($path, $classPrefix = 'Zend_View_Filter_')
{
unset($this->_loaders['filter']);
return $this->addFilterPath($path, $classPrefix);
}
/**
* Get full path to a filter class file specified by $name
*
* @param string $name
* @return string|false False on failure, path on success
*/
public function getFilterPath($name)
{
return $this->_getPluginPath('filter', $name);
}
/**
* Get a filter object by name
*
* @param string $name
* @return object
*/
public function getFilter($name)
{
return $this->_getPlugin('filter', $name);
}
/**
* Return array of all currently active filters
*
* Only returns those that have already been instantiated.
*
* @return array
*/
public function getFilters()
{
return $this->_filter;
}
/**
* Returns an array of all currently set filter paths
*
* @return array
*/
public function getFilterPaths()
{
return $this->getPluginLoader('filter')->getPaths();
}
/**
* Return associative array of path types => paths
*
* @return array
*/
public function getAllPaths()
{
$paths = $this->_path;
$paths['helper'] = $this->getHelperPaths();
$paths['filter'] = $this->getFilterPaths();
return $paths;
}
/**
* Add one or more filters to the stack in FIFO order.
*
* @param string|array One or more filters to add.
* @return Zend_View_Abstract
*/
public function addFilter($name)
{
foreach ((array) $name as $val) {
$this->_filter[] = $val;
}
return $this;
}
/**
* Resets the filter stack.
*
* To clear all filters, use Zend_View::setFilter(null).
*
* @param string|array One or more filters to set.
* @return Zend_View_Abstract
*/
public function setFilter($name)
{
$this->_filter = array();
$this->addFilter($name);
return $this;
}
/**
* Sets the _escape() callback.
*
* @param mixed $spec The callback for _escape() to use.
* @return Zend_View_Abstract
*/
public function setEscape($spec)
{
$this->_escape = $spec;
return $this;
}
/**
* Set LFI protection flag
*
* @param bool $flag
* @return Zend_View_Abstract
*/
public function setLfiProtection($flag)
{
$this->_lfiProtectionOn = (bool) $flag;
return $this;
}
/**
* Return status of LFI protection flag
*
* @return bool
*/
public function isLfiProtectionOn()
{
return $this->_lfiProtectionOn;
}
/**
* Assigns variables to the view script via differing strategies.
*
* Zend_View::assign('name', $value) assigns a variable called 'name'
* with the corresponding $value.
*
* Zend_View::assign($array) assigns the array keys as variable
* names (with the corresponding array values).
*
* @see __set()
* @param string|array The assignment strategy to use.
* @param mixed (Optional) If assigning a named variable, use this
* as the value.
* @return Zend_View_Abstract Fluent interface
* @throws Zend_View_Exception if $spec is neither a string nor an array,
* or if an attempt to set a private or protected member is detected
*/
public function assign($spec, $value = null)
{
// which strategy to use?
if (is_string($spec)) {
// assign by name and value
if ('_' == substr($spec, 0, 1)) {
//--//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;
}
$this->$spec = $value;
} elseif (is_array($spec)) {
// assign from associative array
$error = false;
foreach ($spec as $key => $val) {
if ('_' == substr($key, 0, 1)) {
$error = true;
break;
}
$this->$key = $val;
}
if ($error) {
//--//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;
}
} else {
//--//require_once 'Zend/View/Exception.php';
$e = new Zend_View_Exception('assign() expects a string or array, received ' . gettype($spec));
$e->setView($this);
throw $e;
}
return $this;
}
/**
* Return list of all assigned variables
*
* Returns all public properties of the object. Reflection is not used
* here as testing reflection properties for visibility is buggy.
*
* @return array
*/
public function getVars()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if ('_' == substr($key, 0, 1)) {
unset($vars[$key]);
}
}
return $vars;
}
/**
* Clear all assigned variables
*
* Clears all variables assigned to Zend_View either via {@link assign()} or
* property overloading ({@link __set()}).
*
* @return void
*/
public function clearVars()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if ('_' != substr($key, 0, 1)) {
unset($this->$key);
}
}
}
/**
* Processes a view script and returns the output.
*
* @param string $name The script name to process.
* @return string The script output.
*/
public function render($name)
{
// find the script file name using the parent private method
$this->_file = $this->_script($name);
unset($name); // remove $name from local scope
ob_start();
$this->_run($this->_file);
return $this->_filter(ob_get_clean()); // filter output
}
/**
* Escapes a value for output in a view script.
*
* If escaping mechanism is one of htmlspecialchars or htmlentities, uses
* {@link $_encoding} setting.
*
* @param mixed $var The output to escape.
* @return mixed The escaped value.
*/
public function escape($var)
{
if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) {
return call_user_func($this->_escape, $var, ENT_COMPAT, $this->_encoding);
}
if (1 == func_num_args()) {
return call_user_func($this->_escape, $var);
}
$args = func_get_args();
return call_user_func_array($this->_escape, $args);
}
/**
* Set encoding to use with htmlentities() and htmlspecialchars()
*
* @param string $encoding
* @return Zend_View_Abstract
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
return $this;
}
/**
* Return current escape encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Enable or disable strict vars
*
* If strict variables are enabled, {@link __get()} will raise a notice
* when a variable is not defined.
*
* Use in conjunction with {@link Zend_View_Helper_DeclareVars the declareVars() helper}
* to enforce strict variable handling in your view scripts.
*
* @param boolean $flag
* @return Zend_View_Abstract
*/
public function strictVars($flag = true)
{
$this->_strictVars = ($flag) ? true : false;
return $this;
}
/**
* 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;
}
foreach ($this->_path['script'] as $dir) {
if (is_readable($dir . $name)) {
return $dir . $name;
}
}
//--//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;
}
/**
* Applies the filter callback to a buffer.
*
* @param string $buffer The buffer contents.
* @return string The filtered buffer.
*/
private function _filter($buffer)
{
// loop through each filter class
foreach ($this->_filter as $name) {
// load and apply the filter class
$filter = $this->getFilter($name);
$buffer = call_user_func(array($filter, 'filter'), $buffer);
}
// done!
return $buffer;
}
/**
* Adds paths to the path stack in LIFO order.
*
* Zend_View::_addPath($type, 'dirname') adds one directory
* to the path stack.
*
* Zend_View::_addPath($type, $array) adds one directory for
* each array element value.
*
* In the case of filter and helper paths, $prefix should be used to
* specify what class prefix to use with the given path.
*
* @param string $type The path type ('script', 'helper', or 'filter').
* @param string|array $path The path specification.
* @param string $prefix Class prefix to use with path (helpers and filters
* only)
* @return void
*/
private function _addPath($type, $path, $prefix = null)
{
foreach ((array) $path as $dir) {
// attempt to strip any possible separator and
// append the system directory separator
$dir = rtrim($dir, '/');
$dir = rtrim($dir, '\\');
$dir .= '/';
switch ($type) {
case 'script':
// add to the top of the stack.
array_unshift($this->_path[$type], $dir);
break;
case 'filter':
case 'helper':
default:
// add as array with prefix and dir keys
array_unshift($this->_path[$type], array('prefix' => $prefix, 'dir' => $dir));
break;
}
}
}
/**
* Resets the path stack for helpers and filters.
*
* @param string $type The path type ('helper' or 'filter').
* @param string|array $path The directory (-ies) to set as the path.
* @param string $classPrefix Class prefix to apply to elements of $path
*/
private function _setPath($type, $path, $classPrefix = null)
{
$dir = DIRECTORY_SEPARATOR . ucfirst($type) . DIRECTORY_SEPARATOR;
switch ($type) {
case 'script':
$this->_path[$type] = array(dirname(__FILE__) . $dir);
$this->_addPath($type, $path);
break;
case 'filter':
case 'helper':
default:
$this->_path[$type] = array(array(
'prefix' => 'Zend_View_' . ucfirst($type) . '_',
'dir' => dirname(__FILE__) . $dir
));
$this->_addPath($type, $path, $classPrefix);
break;
}
}
/**
* Return all paths for a given path type
*
* @param string $type The path type ('helper', 'filter', 'script')
* @return array
*/
private function _getPaths($type)
{
return $this->_path[$type];
}
/**
* Register helper class as loaded
*
* @param string $name
* @param string $class
* @param string $file path to class file
* @return void
*/
private function _setHelperClass($name, $class, $file)
{
$this->_helperLoadedDir[$name] = $file;
$this->_helperLoaded[$name] = $class;
}
/**
* Register filter class as loaded
*
* @param string $name
* @param string $class
* @param string $file path to class file
* @return void
*/
private function _setFilterClass($name, $class, $file)
{
$this->_filterLoadedDir[$name] = $file;
$this->_filterLoaded[$name] = $class;
}
/**
* Add a prefixPath for a plugin type
*
* @param string $type
* @param string $classPrefix
* @param array $paths
* @return Zend_View_Abstract
*/
private function _addPluginPath($type, $classPrefix, array $paths)
{
$loader = $this->getPluginLoader($type);
foreach ($paths as $path) {
$loader->addPrefixPath($classPrefix, $path);
}
return $this;
}
/**
* Get a path to a given plugin class of a given type
*
* @param string $type
* @param string $name
* @return string|false
*/
private function _getPluginPath($type, $name)
{
$loader = $this->getPluginLoader($type);
if ($loader->isLoaded($name)) {
return $loader->getClassPath($name);
}
try {
$loader->load($name);
return $loader->getClassPath($name);
} catch (Zend_Loader_Exception $e) {
return false;
}
}
/**
* Retrieve a plugin object
*
* @param string $type
* @param string $name
* @return object
*/
private function _getPlugin($type, $name)
{
$name = ucfirst($name);
switch ($type) {
case 'filter':
$storeVar = '_filterClass';
$store = $this->_filterClass;
break;
case 'helper':
$storeVar = '_helper';
$store = $this->_helper;
break;
}
if (!isset($store[$name])) {
$class = $this->getPluginLoader($type)->load($name);
$store[$name] = new $class();
if (method_exists($store[$name], 'setView')) {
$store[$name]->setView($this);
}
}
$this->$storeVar = $store;
return $store[$name];
}
/**
* Use to include the view script in a scope that only allows public
* members.
*
* @return mixed
*/
abstract protected function _run();
}
Interface.php 0000644 00000007377 15210162401 0007163 0 ustar 00 value pairs to set en
* masse.
*
* @see __set()
* @param string|array $spec The assignment strategy to use (key or array of key
* => value pairs)
* @param mixed $value (Optional) If assigning a named variable, use this
* as the value.
* @return void
*/
public function assign($spec, $value = null);
/**
* Clear all assigned variables
*
* Clears all variables assigned to Zend_View either via {@link assign()} or
* property overloading ({@link __get()}/{@link __set()}).
*
* @return void
*/
public function clearVars();
/**
* Processes a view script and returns the output.
*
* @param string $name The script name to process.
* @return string The script output.
*/
public function render($name);
}
Stream.php 0000644 00000011054 15210162401 0006501 0 ustar 00 _data = file_get_contents($path);
/**
* If reading the file failed, update our local stat store
* to reflect the real stat of the file, then return on failure
*/
if ($this->_data === false) {
$this->_stat = stat($path);
return false;
}
/**
* Convert = ?> to long-form and ?> to
*
*/
$this->_data = preg_replace('/\<\?\=/', "_data);
$this->_data = preg_replace('/<\?(?!xml|php)/s', '_data);
/**
* file_get_contents() won't update PHP's stat cache, so we grab a stat
* of the file to prevent additional reads should the script be
* requested again, which will make include() happy.
*/
$this->_stat = stat($path);
return true;
}
/**
* Included so that __FILE__ returns the appropriate info
*
* @return array
*/
public function url_stat()
{
return $this->_stat;
}
/**
* Reads from the stream.
*/
public function stream_read($count)
{
$ret = substr($this->_data, $this->_pos, $count);
$this->_pos += strlen($ret);
return $ret;
}
/**
* Tells the current position in the stream.
*/
public function stream_tell()
{
return $this->_pos;
}
/**
* Tells if we are at the end of the stream.
*/
public function stream_eof()
{
return $this->_pos >= strlen($this->_data);
}
/**
* Stream statistics.
*/
public function stream_stat()
{
return $this->_stat;
}
/**
* Seek to a specific point in the stream.
*/
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_pos = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->_pos += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_pos = strlen($this->_data) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}
Exception.php 0000644 00000002425 15210162401 0007206 0 ustar 00 view = $view;
return $this;
}
public function getView()
{
return $this->view;
}
}