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 Url.php000064400000003514152101625640006024 0ustar00getRouter(); return $router->assemble($urlOptions, $name, $reset, $encode); } } BaseUrl.php000064400000005623152101637650006626 0ustar00getBaseUrl(); // Remove trailing slashes if (null !== $file) { $file = '/' . ltrim($file, '/\\'); } return $baseUrl . $file; } /** * Set BaseUrl * * @param string $base * @return Zend_View_Helper_BaseUrl */ public function setBaseUrl($base) { $this->_baseUrl = rtrim($base, '/\\'); return $this; } /** * Get BaseUrl * * @return string */ public function getBaseUrl() { if ($this->_baseUrl === null) { /** @see Zend_Controller_Front */ //--//require_once 'Zend/Controller/Front.php'; $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); // Remove scriptname, eg. index.php from baseUrl $baseUrl = $this->_removeScriptName($baseUrl); $this->setBaseUrl($baseUrl); } return $this->_baseUrl; } /** * Remove Script filename from baseurl * * @param string $url * @return string */ protected function _removeScriptName($url) { if (!isset($_SERVER['SCRIPT_NAME'])) { // We can't do much now can we? (Well, we could parse out by ".") return $url; } if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) { $url = substr($url, 0, $pos); } return $url; } } HeadScript.php000064400000036520152101637650007317 0ustar00setSeparator(PHP_EOL); } /** * Return headScript object * * Returns headScript helper object; optionally, allows specifying a script * or script file to include. * * @param string $mode Script or file * @param string $spec Script/url * @param string $placement Append, prepend, or set * @param array $attrs Array of script attributes * @param string $type Script type and/or array of script attributes * @return Zend_View_Helper_HeadScript */ public function headScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript') { if ((null !== $spec) && is_string($spec)) { $action = ucfirst(strtolower($mode)); $placement = strtolower($placement); switch ($placement) { case 'set': case 'prepend': case 'append': $action = $placement . $action; break; default: $action = 'append' . $action; break; } $this->$action($spec, $type, $attrs); } return $this; } /** * Start capture action * * @param mixed $captureType * @param string $typeOrAttrs * @return void */ public function captureStart($captureType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $type = 'text/javascript', $attrs = array()) { if ($this->_captureLock) { //--//require_once 'Zend/View/Helper/Placeholder/Container/Exception.php'; $e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headScript captures'); $e->setView($this->view); throw $e; } $this->_captureLock = true; $this->_captureType = $captureType; $this->_captureScriptType = $type; $this->_captureScriptAttrs = $attrs; ob_start(); } /** * End capture action and store * * @return void */ public function captureEnd() { $content = ob_get_clean(); $type = $this->_captureScriptType; $attrs = $this->_captureScriptAttrs; $this->_captureScriptType = null; $this->_captureScriptAttrs = null; $this->_captureLock = false; switch ($this->_captureType) { case Zend_View_Helper_Placeholder_Container_Abstract::SET: case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND: case Zend_View_Helper_Placeholder_Container_Abstract::APPEND: $action = strtolower($this->_captureType) . 'Script'; break; default: $action = 'appendScript'; break; } $this->$action($content, $type, $attrs); } /** * Overload method access * * Allows the following method calls: * - appendFile($src, $type = 'text/javascript', $attrs = array()) * - offsetSetFile($index, $src, $type = 'text/javascript', $attrs = array()) * - prependFile($src, $type = 'text/javascript', $attrs = array()) * - setFile($src, $type = 'text/javascript', $attrs = array()) * - appendScript($script, $type = 'text/javascript', $attrs = array()) * - offsetSetScript($index, $src, $type = 'text/javascript', $attrs = array()) * - prependScript($script, $type = 'text/javascript', $attrs = array()) * - setScript($script, $type = 'text/javascript', $attrs = array()) * * @param string $method * @param array $args * @return Zend_View_Helper_HeadScript * @throws Zend_View_Exception if too few arguments or invalid method */ public function __call($method, $args) { if (preg_match('/^(?Pset|(ap|pre)pend|offsetSet)(?PFile|Script)$/', $method, $matches)) { if (1 > count($args)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Method "%s" requires at least one argument', $method)); $e->setView($this->view); throw $e; } $action = $matches['action']; $mode = strtolower($matches['mode']); $type = 'text/javascript'; $attrs = array(); if ('offsetSet' == $action) { $index = array_shift($args); if (1 > count($args)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Method "%s" requires at least two arguments, an index and source', $method)); $e->setView($this->view); throw $e; } } $content = $args[0]; if (isset($args[1])) { $type = (string) $args[1]; } if (isset($args[2])) { $attrs = (array) $args[2]; } switch ($mode) { case 'script': $item = $this->createData($type, $attrs, $content); if ('offsetSet' == $action) { $this->offsetSet($index, $item); } else { $this->$action($item); } break; case 'file': default: if (!$this->_isDuplicate($content) || $action=='set') { $attrs['src'] = $content; $item = $this->createData($type, $attrs); if ('offsetSet' == $action) { $this->offsetSet($index, $item); } else { $this->$action($item); } } break; } return $this; } return parent::__call($method, $args); } /** * Is the file specified a duplicate? * * @param string $file * @return bool */ protected function _isDuplicate($file) { foreach ($this->getContainer() as $item) { if (($item->source === null) && array_key_exists('src', $item->attributes) && ($file == $item->attributes['src'])) { return true; } } return false; } /** * Is the script provided valid? * * @param mixed $value * @param string $method * @return bool */ protected function _isValid($value) { if ((!$value instanceof stdClass) || !isset($value->type) || (!isset($value->source) && !isset($value->attributes))) { return false; } return true; } /** * Override append * * @param string $value * @return void */ public function append($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid argument passed to append(); please use one of the helper methods, appendScript() or appendFile()'); $e->setView($this->view); throw $e; } return $this->getContainer()->append($value); } /** * Override prepend * * @param string $value * @return void */ public function prepend($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid argument passed to prepend(); please use one of the helper methods, prependScript() or prependFile()'); $e->setView($this->view); throw $e; } return $this->getContainer()->prepend($value); } /** * Override set * * @param string $value * @return void */ public function set($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid argument passed to set(); please use one of the helper methods, setScript() or setFile()'); $e->setView($this->view); throw $e; } return $this->getContainer()->set($value); } /** * Override offsetSet * * @param string|int $index * @param mixed $value * @return void */ public function offsetSet($index, $value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()'); $e->setView($this->view); throw $e; } return $this->getContainer()->offsetSet($index, $value); } /** * Set flag indicating if arbitrary attributes are allowed * * @param bool $flag * @return Zend_View_Helper_HeadScript */ public function setAllowArbitraryAttributes($flag) { $this->_arbitraryAttributes = (bool) $flag; return $this; } /** * Are arbitrary attributes allowed? * * @return bool */ public function arbitraryAttributesAllowed() { return $this->_arbitraryAttributes; } /** * Create script HTML * * @param string $type * @param array $attributes * @param string $content * @param string|int $indent * @return string */ public function itemToString($item, $indent, $escapeStart, $escapeEnd) { $attrString = ''; if (!empty($item->attributes)) { foreach ($item->attributes as $key => $value) { if ((!$this->arbitraryAttributesAllowed() && !in_array($key, $this->_optionalAttributes)) || in_array($key, array('conditional', 'noescape'))) { continue; } if ('defer' == $key) { $value = 'defer'; } $attrString .= sprintf(' %s="%s"', $key, ($this->_autoEscape) ? $this->_escape($value) : $value); } } $addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN)); $type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type; $html = ''; if (isset($item->attributes['conditional']) && !empty($item->attributes['conditional']) && is_string($item->attributes['conditional'])) { $html = $indent . ''; } else { $html = $indent . $html; } return $html; } /** * Retrieve string representation * * @param string|int $indent * @return string */ public function toString($indent = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) : $this->getIndent(); if ($this->view) { $useCdata = $this->view->doctype()->isXhtml() ? true : false; } else { $useCdata = $this->useCdata ? true : false; } $escapeStart = ($useCdata) ? '//' : '//-->'; $items = array(); $this->getContainer()->ksort(); foreach ($this as $item) { if (!$this->_isValid($item)) { continue; } $items[] = $this->itemToString($item, $indent, $escapeStart, $escapeEnd); } $return = implode($this->getSeparator(), $items); return $return; } /** * Create data item containing all necessary components of script * * @param string $type * @param array $attributes * @param string $content * @return stdClass */ public function createData($type, array $attributes, $content = null) { $data = new stdClass(); $data->type = $type; $data->attributes = $attributes; $data->source = $content; return $data; } } HeadLink.php000064400000033131152101637650006743 0ustar00setSeparator(PHP_EOL); } /** * headLink() - View Helper Method * * Returns current object instance. Optionally, allows passing array of * values to build link. * * @return Zend_View_Helper_HeadLink */ public function headLink(array $attributes = null, $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND) { if (null !== $attributes) { $item = $this->createData($attributes); switch ($placement) { case Zend_View_Helper_Placeholder_Container_Abstract::SET: $this->set($item); break; case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND: $this->prepend($item); break; case Zend_View_Helper_Placeholder_Container_Abstract::APPEND: default: $this->append($item); break; } } return $this; } /** * Overload method access * * Creates the following virtual methods: * - appendStylesheet($href, $media, $conditionalStylesheet, $extras) * - offsetSetStylesheet($index, $href, $media, $conditionalStylesheet, $extras) * - prependStylesheet($href, $media, $conditionalStylesheet, $extras) * - setStylesheet($href, $media, $conditionalStylesheet, $extras) * - appendAlternate($href, $type, $title, $extras) * - offsetSetAlternate($index, $href, $type, $title, $extras) * - prependAlternate($href, $type, $title, $extras) * - setAlternate($href, $type, $title, $extras) * * Items that may be added in the future: * - Navigation? need to find docs on this * - public function appendStart() * - public function appendContents() * - public function appendPrev() * - public function appendNext() * - public function appendIndex() * - public function appendEnd() * - public function appendGlossary() * - public function appendAppendix() * - public function appendHelp() * - public function appendBookmark() * - Other? * - public function appendCopyright() * - public function appendChapter() * - public function appendSection() * - public function appendSubsection() * * @param mixed $method * @param mixed $args * @return void */ public function __call($method, $args) { if (preg_match('/^(?Pset|(ap|pre)pend|offsetSet)(?PStylesheet|Alternate)$/', $method, $matches)) { $argc = count($args); $action = $matches['action']; $type = $matches['type']; $index = null; if ('offsetSet' == $action) { if (0 < $argc) { $index = array_shift($args); --$argc; } } if (1 > $argc) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('%s requires at least one argument', $method)); $e->setView($this->view); throw $e; } if (is_array($args[0])) { $item = $this->createData($args[0]); } else { $dataMethod = 'createData' . $type; $item = $this->$dataMethod($args); } if ($item) { if ('offsetSet' == $action) { $this->offsetSet($index, $item); } else { $this->$action($item); } } return $this; } return parent::__call($method, $args); } /** * Check if value is valid * * @param mixed $value * @return boolean */ protected function _isValid($value) { if (!$value instanceof stdClass) { return false; } $vars = get_object_vars($value); $keys = array_keys($vars); $intersection = array_intersect($this->_itemKeys, $keys); if (empty($intersection)) { return false; } return true; } /** * append() * * @param array $value * @return void */ public function append($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('append() expects a data token; please use one of the custom append*() methods'); $e->setView($this->view); throw $e; } return $this->getContainer()->append($value); } /** * offsetSet() * * @param string|int $index * @param array $value * @return void */ public function offsetSet($index, $value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('offsetSet() expects a data token; please use one of the custom offsetSet*() methods'); $e->setView($this->view); throw $e; } return $this->getContainer()->offsetSet($index, $value); } /** * prepend() * * @param array $value * @return Zend_Layout_ViewHelper_HeadLink */ public function prepend($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('prepend() expects a data token; please use one of the custom prepend*() methods'); $e->setView($this->view); throw $e; } return $this->getContainer()->prepend($value); } /** * set() * * @param array $value * @return Zend_Layout_ViewHelper_HeadLink */ public function set($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('set() expects a data token; please use one of the custom set*() methods'); $e->setView($this->view); throw $e; } return $this->getContainer()->set($value); } /** * Create HTML link element from data item * * @param stdClass $item * @return string */ public function itemToString(stdClass $item) { $attributes = (array) $item; $link = '_itemKeys as $itemKey) { if (isset($attributes[$itemKey])) { if(is_array($attributes[$itemKey])) { foreach($attributes[$itemKey] as $key => $value) { $link .= sprintf('%s="%s" ', $key, ($this->_autoEscape) ? $this->_escape($value) : $value); } } else { $link .= sprintf('%s="%s" ', $itemKey, ($this->_autoEscape) ? $this->_escape($attributes[$itemKey]) : $attributes[$itemKey]); } } } if ($this->view instanceof Zend_View_Abstract) { $link .= ($this->view->doctype()->isXhtml()) ? '/>' : '>'; } else { $link .= '/>'; } if (($link == '') || ($link == '')) { return ''; } if (isset($attributes['conditionalStylesheet']) && !empty($attributes['conditionalStylesheet']) && is_string($attributes['conditionalStylesheet'])) { $link = ''; } return $link; } /** * Render link elements as string * * @param string|int $indent * @return string */ public function toString($indent = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) : $this->getIndent(); $items = array(); $this->getContainer()->ksort(); foreach ($this as $item) { $items[] = $this->itemToString($item); } return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items); } /** * Create data item for stack * * @param array $attributes * @return stdClass */ public function createData(array $attributes) { $data = (object) $attributes; return $data; } /** * Create item for stylesheet link item * * @param array $args * @return stdClass|false Returns fals if stylesheet is a duplicate */ public function createDataStylesheet(array $args) { $rel = 'stylesheet'; $type = 'text/css'; $media = 'screen'; $conditionalStylesheet = false; $href = array_shift($args); if ($this->_isDuplicateStylesheet($href)) { return false; } if (0 < count($args)) { $media = array_shift($args); if(is_array($media)) { $media = implode(',', $media); } else { $media = (string) $media; } } if (0 < count($args)) { $conditionalStylesheet = array_shift($args); if(!empty($conditionalStylesheet) && is_string($conditionalStylesheet)) { $conditionalStylesheet = (string) $conditionalStylesheet; } else { $conditionalStylesheet = null; } } if(0 < count($args) && is_array($args[0])) { $extras = array_shift($args); $extras = (array) $extras; } $attributes = compact('rel', 'type', 'href', 'media', 'conditionalStylesheet', 'extras'); return $this->createData($this->_applyExtras($attributes)); } /** * Is the linked stylesheet a duplicate? * * @param string $uri * @return bool */ protected function _isDuplicateStylesheet($uri) { foreach ($this->getContainer() as $item) { if (($item->rel == 'stylesheet') && ($item->href == $uri)) { return true; } } return false; } /** * Create item for alternate link item * * @param array $args * @return stdClass */ public function createDataAlternate(array $args) { if (3 > count($args)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Alternate tags require 3 arguments; %s provided', count($args))); $e->setView($this->view); throw $e; } $rel = 'alternate'; $href = array_shift($args); $type = array_shift($args); $title = array_shift($args); if(0 < count($args) && is_array($args[0])) { $extras = array_shift($args); $extras = (array) $extras; if(isset($extras['media']) && is_array($extras['media'])) { $extras['media'] = implode(',', $extras['media']); } } $href = (string) $href; $type = (string) $type; $title = (string) $title; $attributes = compact('rel', 'href', 'type', 'title', 'extras'); return $this->createData($this->_applyExtras($attributes)); } /** * Apply any overrides specified in the 'extras' array * @param array $attributes * @return array */ protected function _applyExtras($attributes) { if (isset($attributes['extras'])) { foreach ($attributes['extras'] as $eKey=>$eVal) { if (isset($attributes[$eKey])) { $attributes[$eKey] = $eVal; unset($attributes['extras'][$eKey]); } } } return $attributes; } } Json.php000064400000005763152101637650006207 0ustar00true|false * this array can contains a 'keepLayout'=>true|false and/or 'encodeData'=>true|false * that will not be passed to Zend_Json::encode method but will be used here * @param bool $encodeData * @return string|void */ public function json($data, $keepLayouts = false, $encodeData = true) { $options = array(); if (is_array($keepLayouts)) { $options = $keepLayouts; $keepLayouts = false; if (array_key_exists('keepLayouts', $options)) { $keepLayouts = $options['keepLayouts']; unset($options['keepLayouts']); } if (array_key_exists('encodeData', $options)) { $encodeData = $options['encodeData']; unset($options['encodeData']); } } if ($encodeData) { $data = Zend_Json::encode($data, null, $options); } if (!$keepLayouts) { //--//require_once 'Zend/Layout.php'; $layout = Zend_Layout::getMvcInstance(); if ($layout instanceof Zend_Layout) { $layout->disableLayout(); } } $response = Zend_Controller_Front::getInstance()->getResponse(); $response->setHeader('Content-Type', 'application/json', true); return $data; } } Navigation.php000064400000026207152101637650007371 0ustar00setContainer($container); } return $this; } /** * Magic overload: Proxy to other navigation helpers or the container * * Examples of usage from a view script or layout: * * // 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); } } FormSelect.php000064400000015405152101637650007333 0ustar00\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 = '_htmlAttribs($attribs) . ">\n "; // build the list of options $list = array(); $translator = $this->getTranslator(); foreach ((array) $options as $opt_value => $opt_label) { if (is_array($opt_label)) { $opt_disable = ''; if (is_array($disable) && in_array($opt_value, $disable)) { $opt_disable = ' disabled="disabled"'; } if (null !== $translator) { $opt_value = $translator->translate($opt_value); } $opt_id = ' id="' . $this->view->escape($id) . '-optgroup-' . $this->view->escape($opt_value) . '"'; $list[] = ''; foreach ($opt_label as $val => $lab) { $list[] = $this->_build($val, $lab, $value, $disable, $optionClasses); } $list[] = ''; } else { $list[] = $this->_build($opt_value, $opt_label, $value, $disable, $optionClasses); } } // add the options to the xhtml and close the select $xhtml .= implode("\n ", $list) . "\n"; return $xhtml; } /** * Builds the actual "; return $opt; } } HtmlList.php000064400000005430152101637650007025 0ustar00setView($this->view); throw $e; } $list = ''; foreach ($items as $item) { if (!is_array($item)) { if ($escape) { $item = $this->view->escape($item); } $list .= '
  • ' . $item . '
  • ' . self::EOL; } else { if (6 < strlen($list)) { $list = substr($list, 0, strlen($list) - 6) . $this->htmlList($item, $ordered, $attribs, $escape) . '' . self::EOL; } else { $list .= '
  • ' . $this->htmlList($item, $ordered, $attribs, $escape) . '
  • ' . self::EOL; } } } if ($attribs) { $attribs = $this->_htmlAttribs($attribs); } else { $attribs = ''; } $tag = 'ul'; if ($ordered) { $tag = 'ol'; } return '<' . $tag . $attribs . '>' . self::EOL . $list . '' . self::EOL; } } Partial.php000064400000011412152101637650006656 0ustar00cloneView(); if (isset($this->partialCounter)) { $view->partialCounter = $this->partialCounter; } if (isset($this->partialTotalCount)) { $view->partialTotalCount = $this->partialTotalCount; } if ((null !== $module) && is_string($module)) { //--//require_once 'Zend/Controller/Front.php'; $moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module); if (null === $moduleDir) { //--//require_once 'Zend/View/Helper/Partial/Exception.php'; $e = new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist'); $e->setView($this->view); throw $e; } $viewsDir = dirname($moduleDir) . '/views'; $view->addBasePath($viewsDir); } elseif ((null == $model) && (null !== $module) && (is_array($module) || is_object($module))) { $model = $module; } if (!empty($model)) { if (is_array($model)) { $view->assign($model); } elseif (is_object($model)) { if (null !== ($objectKey = $this->getObjectKey())) { $view->assign($objectKey, $model); } elseif (method_exists($model, 'toArray')) { $view->assign($model->toArray()); } else { $view->assign(get_object_vars($model)); } } } return $view->render($name); } /** * Clone the current View * * @return Zend_View_Interface */ public function cloneView() { $view = clone $this->view; $view->clearVars(); return $view; } /** * Set object key * * @param string $key * @return Zend_View_Helper_Partial */ public function setObjectKey($key) { if (null === $key) { $this->_objectKey = null; } else { $this->_objectKey = (string) $key; } return $this; } /** * Retrieve object key * * The objectKey is the variable to which an object in the iterator will be * assigned. * * @return null|string */ public function getObjectKey() { return $this->_objectKey; } } Abstract.php000064400000003125152101637650007027 0ustar00view = $view; return $this; } /** * Strategy pattern: currently unutilized * * @return void */ public function direct() { } } HeadMeta.php000064400000031776152101637650006751 0ustar00setSeparator(PHP_EOL); } /** * Retrieve object instance; optionally add meta tag * * @param string $content * @param string $keyValue * @param string $keyType * @param array $modifiers * @param string $placement * @return Zend_View_Helper_HeadMeta */ public function headMeta($content = null, $keyValue = null, $keyType = 'name', $modifiers = array(), $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND) { if ((null !== $content) && (null !== $keyValue)) { $item = $this->createData($keyType, $keyValue, $content, $modifiers); $action = strtolower($placement); switch ($action) { case 'append': case 'prepend': case 'set': $this->$action($item); break; default: $this->append($item); break; } } return $this; } protected function _normalizeType($type) { switch ($type) { case 'Name': return 'name'; case 'HttpEquiv': return 'http-equiv'; case 'Property': return 'property'; default: //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Invalid type "%s" passed to _normalizeType', $type)); $e->setView($this->view); throw $e; } } /** * Overload method access * * Allows the following 'virtual' methods: * - appendName($keyValue, $content, $modifiers = array()) * - offsetGetName($index, $keyValue, $content, $modifers = array()) * - prependName($keyValue, $content, $modifiers = array()) * - setName($keyValue, $content, $modifiers = array()) * - appendHttpEquiv($keyValue, $content, $modifiers = array()) * - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array()) * - prependHttpEquiv($keyValue, $content, $modifiers = array()) * - setHttpEquiv($keyValue, $content, $modifiers = array()) * - appendProperty($keyValue, $content, $modifiers = array()) * - offsetGetProperty($index, $keyValue, $content, $modifiers = array()) * - prependProperty($keyValue, $content, $modifiers = array()) * - setProperty($keyValue, $content, $modifiers = array()) * * @param string $method * @param array $args * @return Zend_View_Helper_HeadMeta */ public function __call($method, $args) { if (preg_match('/^(?Pset|(pre|ap)pend|offsetSet)(?PName|HttpEquiv|Property)$/', $method, $matches)) { $action = $matches['action']; $type = $this->_normalizeType($matches['type']); $argc = count($args); $index = null; if ('offsetSet' == $action) { if (0 < $argc) { $index = array_shift($args); --$argc; } } if (2 > $argc) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Too few arguments provided; requires key value, and content'); $e->setView($this->view); throw $e; } if (3 > $argc) { $args[] = array(); } $item = $this->createData($type, $args[0], $args[1], $args[2]); if ('offsetSet' == $action) { return $this->offsetSet($index, $item); } $this->$action($item); return $this; } return parent::__call($method, $args); } /** * Create an HTML5-style meta charset tag. Something like * * Not valid in a non-HTML5 doctype * * @param string $charset * @return Zend_View_Helper_HeadMeta Provides a fluent interface */ public function setCharset($charset) { $item = new stdClass; $item->type = 'charset'; $item->charset = $charset; $item->content = null; $item->modifiers = array(); $this->set($item); return $this; } /** * Determine if item is valid * * @param mixed $item * @return boolean */ protected function _isValid($item) { if ((!$item instanceof stdClass) || !isset($item->type) || !isset($item->modifiers)) { return false; } $isHtml5 = is_null($this->view) ? false : $this->view->doctype()->isHtml5(); if (!isset($item->content) && (! $isHtml5 || (! $isHtml5 && $item->type !== 'charset'))) { return false; } // is only supported with doctype RDFa if ( !is_null($this->view) && !$this->view->doctype()->isRdfa() && $item->type === 'property') { return false; } return true; } /** * Append * * @param string $value * @return void * @throws Zend_View_Exception */ public function append($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to append; please use appendMeta()'); $e->setView($this->view); throw $e; } return $this->getContainer()->append($value); } /** * OffsetSet * * @param string|int $index * @param string $value * @return void * @throws Zend_View_Exception */ public function offsetSet($index, $value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to offsetSet; please use offsetSetName() or offsetSetHttpEquiv()'); $e->setView($this->view); throw $e; } return $this->getContainer()->offsetSet($index, $value); } /** * OffsetUnset * * @param string|int $index * @return void * @throws Zend_View_Exception */ public function offsetUnset($index) { if (!in_array($index, $this->getContainer()->getKeys())) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid index passed to offsetUnset()'); $e->setView($this->view); throw $e; } return $this->getContainer()->offsetUnset($index); } /** * Prepend * * @param string $value * @return void * @throws Zend_View_Exception */ public function prepend($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to prepend; please use prependMeta()'); $e->setView($this->view); throw $e; } return $this->getContainer()->prepend($value); } /** * Set * * @param string $value * @return void * @throws Zend_View_Exception */ public function set($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to set; please use setMeta()'); $e->setView($this->view); throw $e; } $container = $this->getContainer(); foreach ($container->getArrayCopy() as $index => $item) { if ($item->type == $value->type && $item->{$item->type} == $value->{$value->type}) { $this->offsetUnset($index); } } return $this->append($value); } /** * Build meta HTML string * * @param string $type * @param string $typeValue * @param string $content * @param array $modifiers * @return string */ public function itemToString(stdClass $item) { if (!in_array($item->type, $this->_typeKeys)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Invalid type "%s" provided for meta', $item->type)); $e->setView($this->view); throw $e; } $type = $item->type; $modifiersString = ''; foreach ($item->modifiers as $key => $value) { if (!is_null($this->view) && $this->view->doctype()->isHtml5() && $key == 'scheme') { //--//require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception('Invalid modifier ' . '"scheme" provided; not supported by HTML5'); } if (!in_array($key, $this->_modifierKeys)) { continue; } $modifiersString .= $key . '="' . $this->_escape($value) . '" '; } if ($this->view instanceof Zend_View_Abstract) { if ($this->view->doctype()->isHtml5() && $type == 'charset') { $tpl = ($this->view->doctype()->isXhtml()) ? '' : ''; } elseif ($this->view->doctype()->isXhtml()) { $tpl = ''; } else { $tpl = ''; } } else { $tpl = ''; } $meta = sprintf( $tpl, $type, $this->_escape($item->$type), $this->_escape($item->content), $modifiersString ); if (isset($item->modifiers['conditional']) && !empty($item->modifiers['conditional']) && is_string($item->modifiers['conditional'])) { $meta = ''; } return $meta; } /** * Render placeholder as string * * @param string|int $indent * @return string */ public function toString($indent = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) : $this->getIndent(); $items = array(); $this->getContainer()->ksort(); try { foreach ($this as $item) { $items[] = $this->itemToString($item); } } catch (Zend_View_Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); return ''; } return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items); } /** * Create data item for inserting into stack * * @param string $type * @param string $typeValue * @param string $content * @param array $modifiers * @return stdClass */ public function createData($type, $typeValue, $content, array $modifiers) { $data = new stdClass; $data->type = $type; $data->$type = $typeValue; $data->content = $content; $data->modifiers = $modifiers; return $data; } } Interface.php000064400000002442152101637650007165 0ustar00_closingBracket) { if ($this->_isXhtml()) { $this->_closingBracket = ' />'; } else { $this->_closingBracket = '>'; } } return $this->_closingBracket; } /** * Is doctype XHTML? * * @return boolean */ protected function _isXhtml() { $doctype = $this->view->doctype(); return $doctype->isXhtml(); } /** * Is doctype HTML5? * * @return boolean */ protected function _isHtml5() { $doctype = $this->view->doctype(); return $doctype->isHtml5(); } /** * Is doctype strict? * * @return boolean */ protected function _isStrictDoctype() { $doctype = $this->view->doctype(); return $doctype->isStrict(); } /** * Converts an associative array to a string of tag attributes. * * @access public * * @param array $attribs From this array, each key-value pair is * converted to an attribute name and value. * * @return string The XHTML for the attributes. */ protected function _htmlAttribs($attribs) { $xhtml = ''; foreach ((array) $attribs as $key => $val) { $key = $this->view->escape($key); if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) { // Don't escape event attributes; _do_ substitute double quotes with singles if (!is_scalar($val)) { // non-scalar data should be cast to JSON first //--//require_once 'Zend/Json.php'; $val = Zend_Json::encode($val); } // Escape single quotes inside event attribute values. // This will create html, where the attribute value has // single quotes around it, and escaped single quotes or // non-escaped double quotes inside of it $val = str_replace('\'', ''', $val); } else { if (is_array($val)) { $val = implode(' ', $val); } $val = $this->view->escape($val); } if ('id' == $key) { $val = $this->_normalizeId($val); } if (strpos($val, '"') !== false) { $xhtml .= " $key='$val'"; } else { $xhtml .= " $key=\"$val\""; } } return $xhtml; } /** * Normalize an ID * * @param string $value * @return string */ protected function _normalizeId($value) { if (strstr($value, '[')) { if ('[]' == substr($value, -2)) { $value = substr($value, 0, strlen($value) - 2); } $value = trim($value, ']'); $value = str_replace('][', '-', $value); $value = str_replace('[', '-', $value); } return $value; } } Placeholder/Registry/Exception.php000064400000002243152101637650013254 0ustar00_items[$key] = new $this->_containerClass($value); return $this->_items[$key]; } /** * Retrieve a placeholder container * * @param string $key * @return Zend_View_Helper_Placeholder_Container_Abstract */ public function getContainer($key) { $key = (string) $key; if (isset($this->_items[$key])) { return $this->_items[$key]; } $container = $this->createContainer($key); return $container; } /** * Does a particular container exist? * * @param string $key * @return bool */ public function containerExists($key) { $key = (string) $key; $return = array_key_exists($key, $this->_items); return $return; } /** * Set the container for an item in the registry * * @param string $key * @param Zend_View_Placeholder_Container_Abstract $container * @return Zend_View_Placeholder_Registry */ public function setContainer($key, Zend_View_Helper_Placeholder_Container_Abstract $container) { $key = (string) $key; $this->_items[$key] = $container; return $this; } /** * Delete a container * * @param string $key * @return bool */ public function deleteContainer($key) { $key = (string) $key; if (isset($this->_items[$key])) { unset($this->_items[$key]); return true; } return false; } /** * Set the container class to use * * @param string $name * @return Zend_View_Helper_Placeholder_Registry */ public function setContainerClass($name) { if (!class_exists($name)) { //--//require_once 'Zend/Loader.php'; Zend_Loader::loadClass($name); } $reflection = new ReflectionClass($name); if (!$reflection->isSubclassOf(new ReflectionClass('Zend_View_Helper_Placeholder_Container_Abstract'))) { //--//require_once 'Zend/View/Helper/Placeholder/Registry/Exception.php'; $e = new Zend_View_Helper_Placeholder_Registry_Exception('Invalid Container class specified'); $e->setView($this->view); throw $e; } $this->_containerClass = $name; return $this; } /** * Retrieve the container class * * @return string */ public function getContainerClass() { return $this->_containerClass; } } Placeholder/Container/Abstract.php000064400000022322152101637650013173 0ustar00exchangeArray(array($value)); } /** * Prepend a value to the top of the container * * @param mixed $value * @return void */ public function prepend($value) { $values = $this->getArrayCopy(); array_unshift($values, $value); $this->exchangeArray($values); } /** * Retrieve container value * * If single element registered, returns that element; otherwise, * serializes to array. * * @return mixed */ public function getValue() { if (1 == count($this)) { $keys = $this->getKeys(); $key = array_shift($keys); return $this[$key]; } return $this->getArrayCopy(); } /** * Set prefix for __toString() serialization * * @param string $prefix * @return Zend_View_Helper_Placeholder_Container */ public function setPrefix($prefix) { $this->_prefix = (string) $prefix; return $this; } /** * Retrieve prefix * * @return string */ public function getPrefix() { return $this->_prefix; } /** * Set postfix for __toString() serialization * * @param string $postfix * @return Zend_View_Helper_Placeholder_Container */ public function setPostfix($postfix) { $this->_postfix = (string) $postfix; return $this; } /** * Retrieve postfix * * @return string */ public function getPostfix() { return $this->_postfix; } /** * Set separator for __toString() serialization * * Used to implode elements in container * * @param string $separator * @return Zend_View_Helper_Placeholder_Container */ public function setSeparator($separator) { $this->_separator = (string) $separator; return $this; } /** * Retrieve separator * * @return string */ public function getSeparator() { return $this->_separator; } /** * Set the indentation string for __toString() serialization, * optionally, if a number is passed, it will be the number of spaces * * @param string|int $indent * @return Zend_View_Helper_Placeholder_Container_Abstract */ public function setIndent($indent) { $this->_indent = $this->getWhitespace($indent); return $this; } /** * Retrieve indentation * * @return string */ public function getIndent() { return $this->_indent; } /** * Retrieve whitespace representation of $indent * * @param int|string $indent * @return string */ public function getWhitespace($indent) { if (is_int($indent)) { $indent = str_repeat(' ', $indent); } return (string) $indent; } /** * Start capturing content to push into placeholder * * @param int|string $type How to capture content into placeholder; append, prepend, or set * @param null $key * @throws Zend_View_Helper_Placeholder_Container_Exception * @return void */ public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $key = null) { if ($this->_captureLock) { //--//require_once 'Zend/View/Helper/Placeholder/Container/Exception.php'; $e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest placeholder captures for the same placeholder'); $e->setView($this->view); throw $e; } $this->_captureLock = true; $this->_captureType = $type; if ((null !== $key) && is_scalar($key)) { $this->_captureKey = (string) $key; } ob_start(); } /** * End content capture * * @return void */ public function captureEnd() { $data = ob_get_clean(); $key = null; $this->_captureLock = false; if (null !== $this->_captureKey) { $key = $this->_captureKey; } switch ($this->_captureType) { case self::SET: if (null !== $key) { $this[$key] = $data; } else { $this->exchangeArray(array($data)); } break; case self::PREPEND: if (null !== $key) { $array = array($key => $data); $values = $this->getArrayCopy(); $final = $array + $values; $this->exchangeArray($final); } else { $this->prepend($data); } break; case self::APPEND: default: if (null !== $key) { if (empty($this[$key])) { $this[$key] = $data; } else { $this[$key] .= $data; } } else { $this[$this->nextIndex()] = $data; } break; } } /** * Get keys * * @return array */ public function getKeys() { $array = $this->getArrayCopy(); return array_keys($array); } /** * Next Index * * as defined by the PHP manual * @return int */ public function nextIndex() { $keys = $this->getKeys(); if (0 == count($keys)) { return 0; } return $nextIndex = max($keys) + 1; } /** * Render the placeholder * * @param null $indent * @return string */ public function toString($indent = null) { // Check items if (0 === $this->count()) { return ''; } $indent = ($indent !== null) ? $this->getWhitespace($indent) : $this->getIndent(); $items = $this->getArrayCopy(); $return = $indent . $this->getPrefix() . implode($this->getSeparator(), $items) . $this->getPostfix(); $return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return); return $return; } /** * Serialize object to string * * @return string */ public function __toString() { return $this->toString(); } } Placeholder/Container/Standalone.php000064400000017031152101637650013521 0ustar00setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry()); $this->setContainer($this->getRegistry()->getContainer($this->_regKey)); } /** * Retrieve registry * * @return Zend_View_Helper_Placeholder_Registry */ public function getRegistry() { return $this->_registry; } /** * Set registry object * * @param Zend_View_Helper_Placeholder_Registry $registry * @return Zend_View_Helper_Placeholder_Container_Standalone */ public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry) { $this->_registry = $registry; return $this; } /** * Set whether or not auto escaping should be used * * @param bool $autoEscape whether or not to auto escape output * @return Zend_View_Helper_Placeholder_Container_Standalone */ public function setAutoEscape($autoEscape = true) { $this->_autoEscape = ($autoEscape) ? true : false; return $this; } /** * Return whether autoEscaping is enabled or disabled * * return bool */ public function getAutoEscape() { return $this->_autoEscape; } /** * Escape a string * * @param string $string * @return string */ protected function _escape($string) { $enc = 'UTF-8'; if ($this->view instanceof Zend_View_Interface && method_exists($this->view, 'getEncoding') ) { $enc = $this->view->getEncoding(); } return htmlspecialchars((string) $string, ENT_COMPAT, $enc); } /** * Set container on which to operate * * @param Zend_View_Helper_Placeholder_Container_Abstract $container * @return Zend_View_Helper_Placeholder_Container_Standalone */ public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container) { $this->_container = $container; return $this; } /** * Retrieve placeholder container * * @return Zend_View_Helper_Placeholder_Container_Abstract */ public function getContainer() { return $this->_container; } /** * Overloading: set property value * * @param string $key * @param mixed $value * @return void */ public function __set($key, $value) { $container = $this->getContainer(); $container[$key] = $value; } /** * Overloading: retrieve property * * @param string $key * @return mixed */ public function __get($key) { $container = $this->getContainer(); if (isset($container[$key])) { return $container[$key]; } return null; } /** * Overloading: check if property is set * * @param string $key * @return bool */ public function __isset($key) { $container = $this->getContainer(); return isset($container[$key]); } /** * Overloading: unset property * * @param string $key * @return void */ public function __unset($key) { $container = $this->getContainer(); if (isset($container[$key])) { unset($container[$key]); } } /** * Overload * * Proxy to container methods * * @param string $method * @param array $args * @return mixed */ public function __call($method, $args) { $container = $this->getContainer(); if (method_exists($container, $method)) { $return = call_user_func_array(array($container, $method), $args); if ($return === $container) { // If the container is returned, we really want the current object return $this; } return $return; } //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Method "' . $method . '" does not exist'); $e->setView($this->view); throw $e; } /** * String representation * * @return string */ public function toString() { return $this->getContainer()->toString(); } /** * Cast to string representation * * @return string */ public function __toString() { return $this->toString(); } /** * Countable * * @return int */ public function count() { $container = $this->getContainer(); return count($container); } /** * ArrayAccess: offsetExists * * @param string|int $offset * @return bool */ public function offsetExists($offset) { return $this->getContainer()->offsetExists($offset); } /** * ArrayAccess: offsetGet * * @param string|int $offset * @return mixed */ public function offsetGet($offset) { return $this->getContainer()->offsetGet($offset); } /** * ArrayAccess: offsetSet * * @param string|int $offset * @param mixed $value * @return void */ public function offsetSet($offset, $value) { return $this->getContainer()->offsetSet($offset, $value); } /** * ArrayAccess: offsetUnset * * @param string|int $offset * @return void */ public function offsetUnset($offset) { return $this->getContainer()->offsetUnset($offset); } /** * IteratorAggregate: get Iterator * * @return Iterator */ public function getIterator() { return $this->getContainer()->getIterator(); } } Placeholder/Container/Exception.php000064400000002245152101637650013370 0ustar00 tag * * @var string */ const SITEMAP_NS = 'http://www.sitemaps.org/schemas/sitemap/0.9'; /** * Schema URL * * @var string */ const SITEMAP_XSD = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'; /** * Whether the XML declaration should be included in XML output * * @var bool */ protected $_useXmlDeclaration = true; /** * Whether sitemap should be validated using Zend_Validate_Sitemap_* * * @var bool */ protected $_useSitemapValidators = true; /** * Whether sitemap should be schema validated when generated * * @var bool */ protected $_useSchemaValidation = false; /** * Server url * * @var string */ protected $_serverUrl; /** * View helper entry point: * Retrieves helper and optionally sets container to operate on * * @param Zend_Navigation_Container $container [optional] container to * operate on * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns * self */ public function sitemap(Zend_Navigation_Container $container = null) { if (null !== $container) { $this->setContainer($container); } return $this; } // Accessors: /** * Sets whether the XML declaration should be used in output * * @param bool $useXmlDecl whether XML delcaration * should be rendered * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns * self */ public function setUseXmlDeclaration($useXmlDecl) { $this->_useXmlDeclaration = (bool) $useXmlDecl; return $this; } /** * Returns whether the XML declaration should be used in output * * @return bool whether the XML declaration should be used in output */ public function getUseXmlDeclaration() { return $this->_useXmlDeclaration; } /** * Sets whether sitemap should be validated using Zend_Validate_Sitemap_* * * @param bool $useSitemapValidators whether sitemap validators * should be used * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns * self */ public function setUseSitemapValidators($useSitemapValidators) { $this->_useSitemapValidators = (bool) $useSitemapValidators; return $this; } /** * Returns whether sitemap should be validated using Zend_Validate_Sitemap_* * * @return bool whether sitemap should be validated using validators */ public function getUseSitemapValidators() { return $this->_useSitemapValidators; } /** * Sets whether sitemap should be schema validated when generated * * @param bool $schemaValidation whether sitemap should * validated using XSD Schema * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns * self */ public function setUseSchemaValidation($schemaValidation) { $this->_useSchemaValidation = (bool) $schemaValidation; return $this; } /** * Returns true if sitemap should be schema validated when generated * * @return bool */ public function getUseSchemaValidation() { return $this->_useSchemaValidation; } /** * Sets server url (scheme and host-related stuff without request URI) * * E.g. http://www.example.com * * @param string $serverUrl server URL to set (only * scheme and host) * @throws Zend_Uri_Exception if invalid server URL * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns * self */ public function setServerUrl($serverUrl) { //--//require_once 'Zend/Uri.php'; $uri = Zend_Uri::factory($serverUrl); $uri->setFragment(''); $uri->setPath(''); $uri->setQuery(''); if ($uri->valid()) { $this->_serverUrl = $uri->getUri(); } else { //--//require_once 'Zend/Uri/Exception.php'; $e = new Zend_Uri_Exception(sprintf( 'Invalid server URL: "%s"', $serverUrl)); $e->setView($this->view); throw $e; } return $this; } /** * Returns server URL * * @return string server URL */ public function getServerUrl() { if (!isset($this->_serverUrl)) { $this->_serverUrl = $this->view->serverUrl(); } return $this->_serverUrl; } // Helper methods: /** * Escapes string for XML usage * * @param string $string string to escape * @return string escaped string */ protected function _xmlEscape($string) { $enc = 'UTF-8'; if ($this->view instanceof Zend_View_Interface && method_exists($this->view, 'getEncoding') ) { $enc = $this->view->getEncoding(); } // do not encode existing HTML entities return htmlspecialchars($string, ENT_QUOTES, $enc, false); } // Public methods: /** * Returns an escaped absolute URL for the given page * * @param Zend_Navigation_Page $page page to get URL from * @return string */ public function url(Zend_Navigation_Page $page) { $href = $page->getHref(); if (!isset($href{0})) { // no href return ''; } elseif ($href{0} == '/') { // href is relative to root; use serverUrl helper $url = $this->getServerUrl() . $href; } elseif (preg_match('/^[a-z]+:/im', (string) $href)) { // scheme is given in href; assume absolute URL already $url = (string) $href; } else { // href is relative to current document; use url helpers $url = $this->getServerUrl() . rtrim($this->view->url(), '/') . '/' . $href; } return $this->_xmlEscape($url); } /** * Returns a DOMDocument containing the Sitemap XML for the given container * * @param Zend_Navigation_Container $container [optional] container to get * breadcrumbs from, defaults * to what is registered in the * helper * @return DOMDocument DOM representation of the * container * @throws Zend_View_Exception if schema validation is on * and the sitemap is invalid * according to the sitemap * schema, or if sitemap * validators are used and the * loc element fails validation */ public function getDomSitemap(Zend_Navigation_Container $container = null) { if (null === $container) { $container = $this->getContainer(); } // check if we should validate using our own validators if ($this->getUseSitemapValidators()) { //--//require_once 'Zend/Validate/Sitemap/Changefreq.php'; //--//require_once 'Zend/Validate/Sitemap/Lastmod.php'; //--//require_once 'Zend/Validate/Sitemap/Loc.php'; //--//require_once 'Zend/Validate/Sitemap/Priority.php'; // create validators $locValidator = new Zend_Validate_Sitemap_Loc(); $lastmodValidator = new Zend_Validate_Sitemap_Lastmod(); $changefreqValidator = new Zend_Validate_Sitemap_Changefreq(); $priorityValidator = new Zend_Validate_Sitemap_Priority(); } // create document $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = $this->getFormatOutput(); // ...and urlset (root) element $urlSet = $dom->createElementNS(self::SITEMAP_NS, 'urlset'); $dom->appendChild($urlSet); // create iterator $iterator = new RecursiveIteratorIterator($container, RecursiveIteratorIterator::SELF_FIRST); $maxDepth = $this->getMaxDepth(); if (is_int($maxDepth)) { $iterator->setMaxDepth($maxDepth); } $minDepth = $this->getMinDepth(); if (!is_int($minDepth) || $minDepth < 0) { $minDepth = 0; } // iterate container foreach ($iterator as $page) { if ($iterator->getDepth() < $minDepth || !$this->accept($page)) { // page should not be included continue; } // get absolute url from page if (!$url = $this->url($page)) { // skip page if it has no url (rare case) continue; } // create url node for this page $urlNode = $dom->createElementNS(self::SITEMAP_NS, 'url'); $urlSet->appendChild($urlNode); if ($this->getUseSitemapValidators() && !$locValidator->isValid($url)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf( 'Encountered an invalid URL for Sitemap XML: "%s"', $url)); $e->setView($this->view); throw $e; } // put url in 'loc' element $urlNode->appendChild($dom->createElementNS(self::SITEMAP_NS, 'loc', $url)); // add 'lastmod' element if a valid lastmod is set in page if (isset($page->lastmod)) { $lastmod = strtotime((string) $page->lastmod); // prevent 1970-01-01... if ($lastmod !== false) { $lastmod = date('c', $lastmod); } if (!$this->getUseSitemapValidators() || $lastmodValidator->isValid($lastmod)) { $urlNode->appendChild( $dom->createElementNS(self::SITEMAP_NS, 'lastmod', $lastmod) ); } } // add 'changefreq' element if a valid changefreq is set in page if (isset($page->changefreq)) { $changefreq = $page->changefreq; if (!$this->getUseSitemapValidators() || $changefreqValidator->isValid($changefreq)) { $urlNode->appendChild( $dom->createElementNS(self::SITEMAP_NS, 'changefreq', $changefreq) ); } } // add 'priority' element if a valid priority is set in page if (isset($page->priority)) { $priority = $page->priority; if (!$this->getUseSitemapValidators() || $priorityValidator->isValid($priority)) { $urlNode->appendChild( $dom->createElementNS(self::SITEMAP_NS, 'priority', $priority) ); } } } // validate using schema if specified if ($this->getUseSchemaValidation()) { if (!@$dom->schemaValidate(self::SITEMAP_XSD)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf( 'Sitemap is invalid according to XML Schema at "%s"', self::SITEMAP_XSD)); $e->setView($this->view); throw $e; } } return $dom; } // 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) { $dom = $this->getDomSitemap($container); $xml = $this->getUseXmlDeclaration() ? $dom->saveXML() : $dom->saveXML($dom->documentElement); return rtrim($xml, self::EOL); } } Navigation/Links.php000064400000063000152101637650010441 0ustar00 elements * * @category Zend * @package Zend_View * @subpackage Helper * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_View_Helper_Navigation_Links extends Zend_View_Helper_Navigation_HelperAbstract { /**#@+ * Constants used for specifying which link types to find and render * * @var int */ const RENDER_ALTERNATE = 0x0001; const RENDER_STYLESHEET = 0x0002; const RENDER_START = 0x0004; const RENDER_NEXT = 0x0008; const RENDER_PREV = 0x0010; const RENDER_CONTENTS = 0x0020; const RENDER_INDEX = 0x0040; const RENDER_GLOSSARY = 0x0080; const RENDER_COPYRIGHT = 0x0100; const RENDER_CHAPTER = 0x0200; const RENDER_SECTION = 0x0400; const RENDER_SUBSECTION = 0x0800; const RENDER_APPENDIX = 0x1000; const RENDER_HELP = 0x2000; const RENDER_BOOKMARK = 0x4000; const RENDER_CUSTOM = 0x8000; const RENDER_ALL = 0xffff; /**#@+**/ /** * Maps render constants to W3C link types * * @var array */ protected static $_RELATIONS = array( self::RENDER_ALTERNATE => 'alternate', self::RENDER_STYLESHEET => 'stylesheet', self::RENDER_START => 'start', self::RENDER_NEXT => 'next', self::RENDER_PREV => 'prev', self::RENDER_CONTENTS => 'contents', self::RENDER_INDEX => 'index', self::RENDER_GLOSSARY => 'glossary', self::RENDER_COPYRIGHT => 'copyright', self::RENDER_CHAPTER => 'chapter', self::RENDER_SECTION => 'section', self::RENDER_SUBSECTION => 'subsection', self::RENDER_APPENDIX => 'appendix', self::RENDER_HELP => 'help', self::RENDER_BOOKMARK => 'bookmark' ); /** * The helper's render flag * * @see render() * @see setRenderFlag() * @var int */ protected $_renderFlag = self::RENDER_ALL; /** * Root container * * Used for preventing methods to traverse above the container given to * the {@link render()} method. * * @see _findRoot() * * @var Zend_Navigation_Container */ protected $_root; /** * View helper entry point: * Retrieves helper and optionally sets container to operate on * * @param Zend_Navigation_Container $container [optional] container to * operate on * @return Zend_View_Helper_Navigation_Links fluent interface, returns * self */ public function links(Zend_Navigation_Container $container = null) { if (null !== $container) { $this->setContainer($container); } return $this; } /** * Magic overload: Proxy calls to {@link findRelation()} or container * * Examples of finder calls: * * // 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) : ''; } } Navigation/Menu.php000064400000114234152101637650010273 0ustar00setContainer($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) . ''; } /** * 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 . '_htmlAttribs($attribs) . '>' . $this->getEOL(); // Reset prefix for IDs $this->_skipPrefixForId = $skipValue; foreach ($active['page'] as $subPage) { if (!$this->accept($subPage)) { continue; } $liClass = ''; if ($subPage->isActive(true) && $addPageClassToLi) { $liClass = $this->_htmlAttribs( array('class' => $activeClass . ' ' . $subPage->getClass()) ); } else if ($subPage->isActive(true)) { $liClass = $this->_htmlAttribs(array('class' => $activeClass)); } else if ($addPageClassToLi) { $liClass = $this->_htmlAttribs( array('class' => $subPage->getClass()) ); } $html .= $indent . $innerIndent . '' . $this->getEOL(); $html .= $indent . str_repeat($innerIndent, 2) . $this->htmlify($subPage) . $this->getEOL(); $html .= $indent . $innerIndent . '' . $this->getEOL(); } $html .= $indent . ''; return $html; } /** * Renders a normal menu (called from {@link renderMenu()}) * * @param Zend_Navigation_Container $container container to render * @param string $ulClass CSS class for first UL * @param string $indent initial indentation * @param string $innerIndent inner indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth * @param bool $onlyActive render only active branch? * @param bool $expandSibs render siblings of active * branch nodes? * @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 _renderMenu(Zend_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 ($expandSibs && $depth > $minDepth) { // 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 ($page->getParent()->isActive(true)) { // page is a sibling of the active branch... $accept = true; } } if (!$isActive && !$accept) { 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($innerIndent, $depth * 2); if ($depth > $prevDepth) { $attribs = array(); // start new ul tag if (0 == $depth) { $attribs = array( 'class' => $ulClass, 'id' => $ulId, ); } // We don't need a prefix for the menu ID (backup) $skipValue = $this->_skipPrefixForId; $this->skipPrefixForId(); $html .= $myIndent . '_htmlAttribs($attribs) . '>' . $this->getEOL(); // Reset prefix for IDs $this->_skipPrefixForId = $skipValue; } else if ($prevDepth > $depth) { // close li/ul tags until we're at current depth for ($i = $prevDepth; $i > $depth; $i--) { $ind = $indent . str_repeat($innerIndent, $i * 2); $html .= $ind . $innerIndent . '' . $this->getEOL(); $html .= $ind . '' . $this->getEOL(); } // close previous li tag $html .= $myIndent . $innerIndent . '' . $this->getEOL(); } else { // close previous li tag $html .= $myIndent . $innerIndent . '' . $this->getEOL(); } // render li tag and page $liClasses = array(); // Is page active? if ($isActive) { $liClasses[] = $activeClass; } // Add CSS class from page to LI? if ($addPageClassToLi) { $liClasses[] = $page->getClass(); } // Add CSS class for parents to LI? if ($renderParentClass && $page->hasChildren()) { // Check max depth if ((is_int($maxDepth) && ($depth + 1 < $maxDepth)) || !is_int($maxDepth) ) { $liClasses[] = $parentClass; } } $html .= $myIndent . $innerIndent . '_htmlAttribs(array('class' => implode(' ', $liClasses))) . '>' . $this->getEOL() . $myIndent . str_repeat($innerIndent, 2) . $this->htmlify($page) . $this->getEOL(); // store as previous depth for next iteration $prevDepth = $depth; } if ($html) { // done iterating container; close open ul/li tags for ($i = $prevDepth+1; $i > 0; $i--) { $myIndent = $indent . str_repeat($innerIndent . $innerIndent, $i - 1); $html .= $myIndent . $innerIndent . '' . $this->getEOL() . $myIndent . '' . $this->getEOL(); } $html = rtrim($html, $this->getEOL()); } return $html; } /** * Renders helper * * Renders a HTML 'ul' for the given $container. If $container is not given, * the container registered in the helper will be used. * * Available $options: * * * @param Zend_Navigation_Container $container [optional] container to * create menu from. Default * is to use the container * retrieved from * {@link getContainer()}. * @param array $options [optional] options for * controlling rendering * @return string rendered menu */ public function renderMenu(Zend_Navigation_Container $container = null, array $options = array()) { if (null === $container) { $container = $this->getContainer(); } $options = $this->_normalizeOptions($options); if ($options['onlyActiveBranch'] && !$options['renderParents']) { $html = $this->_renderDeepestMenu( $container, $options['ulClass'], $options['indent'], $options['innerIndent'], $options['minDepth'], $options['maxDepth'], $options['ulId'], $options['addPageClassToLi'], $options['activeClass'], $options['parentClass'], $options['renderParentClass'] ); } else { $html = $this->_renderMenu( $container, $options['ulClass'], $options['indent'], $options['innerIndent'], $options['minDepth'], $options['maxDepth'], $options['onlyActiveBranch'], $options['expandSiblingNodesOfActiveBranch'], $options['ulId'], $options['addPageClassToLi'], $options['activeClass'], $options['parentClass'], $options['renderParentClass'] ); } return $html; } /** * Renders the inner-most sub menu for the active page in the $container * * This is a convenience method which is equivalent to the following call: * * 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); } } } Navigation/HelperAbstract.php000064400000074431152101637650012276 0ustar00_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' ); } } } Navigation/Helper.php000064400000016356152101637650010614 0ustar00setContainer($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); } } } FormText.php000064400000004472152101637650007042 0ustar00_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; } } RenderToPlaceholder.php000064400000003346152101637650011156 0ustar00view->placeholder($placeholder)->captureStart(); echo $this->view->render($script); $this->view->placeholder($placeholder)->captureEnd(); } } HeadTitle.php000064400000014450152101637650007132 0ustar00getDefaultAttachOrder()) ? 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 . '' . $output . ''; } } FormErrors.php000064400000010261152101637650007363 0ustar00'; protected $_htmlElementStart = '
  • '; protected $_htmlElementSeparator = '
  • '; /**#@-*/ /** * Render form errors * * @param string|array $errors Error(s) to render * @param array $options * @return string */ public function formErrors($errors, array $options = null) { $escape = true; if (isset($options['escape'])) { $escape = (bool) $options['escape']; unset($options['escape']); } if (empty($options['class'])) { $options['class'] = 'errors'; } if (isset($options['elementStart'])) { $this->setElementStart($options['elementStart']); } if (isset($options['elementEnd'])) { $this->setElementEnd($options['elementEnd']); } if (isset($options['elementSeparator'])) { $this->setElementSeparator($options['elementSeparator']); } $start = $this->getElementStart(); if (strstr($start, '%s')) { $attribs = $this->_htmlAttribs($options); $start = sprintf($start, $attribs); } if ($escape) { foreach ($errors as $key => $error) { $errors[$key] = $this->view->escape($error); } } $html = $start . implode($this->getElementSeparator(), (array) $errors) . $this->getElementEnd(); return $html; } /** * Set end string for displaying errors * * @param string $string * @return Zend_View_Helper_FormErrors */ public function setElementEnd($string) { $this->_htmlElementEnd = (string) $string; return $this; } /** * Retrieve end string for displaying errors * * @return string */ public function getElementEnd() { return $this->_htmlElementEnd; } /** * Set separator string for displaying errors * * @param string $string * @return Zend_View_Helper_FormErrors */ public function setElementSeparator($string) { $this->_htmlElementSeparator = (string) $string; return $this; } /** * Retrieve separator string for displaying errors * * @return string */ public function getElementSeparator() { return $this->_htmlElementSeparator; } /** * Set start string for displaying errors * * @param string $string * @return Zend_View_Helper_FormErrors */ public function setElementStart($string) { $this->_htmlElementStart = (string) $string; return $this; } /** * Retrieve start string for displaying errors * * @return string */ public function getElementStart() { return $this->_htmlElementStart; } } Translate.php000064400000012614152101637650007224 0ustar00setTranslator($translate); } } /** * Translate a message * You can give multiple params or an array of params. * If you want to output another locale just set it as last single parameter * Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale); * Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale); * * @param string $messageid Id of the message to be translated * @return string|Zend_View_Helper_Translate Translated message */ public function translate($messageid = null) { if ($messageid === null) { return $this; } $translate = $this->getTranslator(); $options = func_get_args(); array_shift($options); $count = count($options); $locale = null; if ($count > 0) { if (Zend_Locale::isLocale($options[($count - 1)], null, false) !== false) { $locale = array_pop($options); } } if ((count($options) === 1) and (is_array($options[0]) === true)) { $options = $options[0]; } if ($translate !== null) { $messageid = $translate->translate($messageid, $locale); } if (count($options) === 0) { return $messageid; } return vsprintf($messageid, $options); } /** * Sets a translation Adapter for translation * * @param Zend_Translate|Zend_Translate_Adapter $translate Instance of Zend_Translate * @throws Zend_View_Exception When no or a false instance was set * @return Zend_View_Helper_Translate */ public function setTranslator($translate) { if ($translate instanceof Zend_Translate_Adapter) { $this->_translator = $translate; } else if ($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 * * @return Zend_Translate_Adapter|null */ public function getTranslator() { if ($this->_translator === null) { //--//require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Translate')) { $this->setTranslator(Zend_Registry::get('Zend_Translate')); } } return $this->_translator; } /** * Set's an new locale for all further translations * * @param string|Zend_Locale $locale New locale to set * @throws Zend_View_Exception When no Zend_Translate instance was set * @return Zend_View_Helper_Translate */ public function setLocale($locale = null) { $translate = $this->getTranslator(); if ($translate === null) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter'); $e->setView($this->view); throw $e; } $translate->setLocale($locale); return $this; } /** * Returns the set locale for translations * * @throws Zend_View_Exception When no Zend_Translate instance was set * @return string|Zend_Locale */ public function getLocale() { $translate = $this->getTranslator(); if ($translate === null) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter'); $e->setView($this->view); throw $e; } return $translate->getLocale(); } } Action.php000064400000011312152101637650006476 0ustar00getControllerDirectory(); if (empty($modules)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Action helper depends on valid front controller instance'); $e->setView($this->view); throw $e; } $request = $front->getRequest(); $response = $front->getResponse(); if (empty($request) || empty($response)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Action view helper requires both a registered request and response object in the front controller instance'); $e->setView($this->view); throw $e; } $this->request = clone $request; $this->response = clone $response; $this->dispatcher = clone $front->getDispatcher(); $this->defaultModule = $front->getDefaultModule(); } /** * Reset object states * * @return void */ public function resetObjects() { $params = $this->request->getUserParams(); foreach (array_keys($params) as $key) { $this->request->setParam($key, null); } $this->response->clearBody(); $this->response->clearHeaders() ->clearRawHeaders(); } /** * Retrieve rendered contents of a controller action * * If the action results in a forward or redirect, returns empty string. * * @param string $action * @param string $controller * @param string $module Defaults to default module * @param array $params * @return string */ public function action($action, $controller, $module = null, array $params = array()) { $this->resetObjects(); if (null === $module) { $module = $this->defaultModule; } // clone the view object to prevent over-writing of view variables $viewRendererObj = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj); $this->request->setParams($params) ->setModuleName($module) ->setControllerName($controller) ->setActionName($action) ->setDispatched(true); $this->dispatcher->dispatch($this->request, $this->response); // reset the viewRenderer object to it's original state Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj); if (!$this->request->isDispatched() || $this->response->isRedirect()) { // forwards and redirects render nothing return ''; } $return = $this->response->getBody(); $this->resetObjects(); return $return; } /** * Clone the current View * * @return Zend_View_Interface */ public function cloneView() { $view = clone $this->view; $view->clearVars(); return $view; } } HeadStyle.php000064400000030553152101637650007153 0ustar00setSeparator(PHP_EOL); } /** * Return headStyle object * * Returns headStyle helper object; optionally, allows specifying * * @param string $content Stylesheet contents * @param string $placement Append, prepend, or set * @param string|array $attributes Optional attributes to utilize * @return Zend_View_Helper_HeadStyle */ public function headStyle($content = null, $placement = 'APPEND', $attributes = array()) { if ((null !== $content) && is_string($content)) { switch (strtoupper($placement)) { case 'SET': $action = 'setStyle'; break; case 'PREPEND': $action = 'prependStyle'; break; case 'APPEND': default: $action = 'appendStyle'; break; } $this->$action($content, $attributes); } return $this; } /** * Overload method calls * * Allows the following method calls: * - appendStyle($content, $attributes = array()) * - offsetSetStyle($index, $content, $attributes = array()) * - prependStyle($content, $attributes = array()) * - setStyle($content, $attributes = array()) * * @param string $method * @param array $args * @return void * @throws Zend_View_Exception When no $content provided or invalid method */ public function __call($method, $args) { if (preg_match('/^(?Pset|(ap|pre)pend|offsetSet)(Style)$/', $method, $matches)) { $index = null; $argc = count($args); $action = $matches['action']; if ('offsetSet' == $action) { if (0 < $argc) { $index = array_shift($args); --$argc; } } if (1 > $argc) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception(sprintf('Method "%s" requires minimally content for the stylesheet', $method)); $e->setView($this->view); throw $e; } $content = $args[0]; $attrs = array(); if (isset($args[1])) { $attrs = (array) $args[1]; } $item = $this->createData($content, $attrs); if ('offsetSet' == $action) { $this->offsetSet($index, $item); } else { $this->$action($item); } return $this; } return parent::__call($method, $args); } /** * Determine if a value is a valid style tag * * @param mixed $value * @param string $method * @return boolean */ protected function _isValid($value) { if ((!$value instanceof stdClass) || !isset($value->content) || !isset($value->attributes)) { return false; } return true; } /** * Override append to enforce style creation * * @param mixed $value * @return void */ public function append($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to append; please use appendStyle()'); $e->setView($this->view); throw $e; } return $this->getContainer()->append($value); } /** * Override offsetSet to enforce style creation * * @param string|int $index * @param mixed $value * @return void */ public function offsetSet($index, $value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to offsetSet; please use offsetSetStyle()'); $e->setView($this->view); throw $e; } return $this->getContainer()->offsetSet($index, $value); } /** * Override prepend to enforce style creation * * @param mixed $value * @return void */ public function prepend($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to prepend; please use prependStyle()'); $e->setView($this->view); throw $e; } return $this->getContainer()->prepend($value); } /** * Override set to enforce style creation * * @param mixed $value * @return void */ public function set($value) { if (!$this->_isValid($value)) { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid value passed to set; please use setStyle()'); $e->setView($this->view); throw $e; } return $this->getContainer()->set($value); } /** * Start capture action * * @param mixed $captureType * @param string $typeOrAttrs * @return void */ public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $attrs = null) { if ($this->_captureLock) { //--//require_once 'Zend/View/Helper/Placeholder/Container/Exception.php'; $e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headStyle captures'); $e->setView($this->view); throw $e; } $this->_captureLock = true; $this->_captureAttrs = $attrs; $this->_captureType = $type; ob_start(); } /** * End capture action and store * * @return void */ public function captureEnd() { $content = ob_get_clean(); $attrs = $this->_captureAttrs; $this->_captureAttrs = null; $this->_captureLock = false; switch ($this->_captureType) { case Zend_View_Helper_Placeholder_Container_Abstract::SET: $this->setStyle($content, $attrs); break; case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND: $this->prependStyle($content, $attrs); break; case Zend_View_Helper_Placeholder_Container_Abstract::APPEND: default: $this->appendStyle($content, $attrs); break; } } /** * Convert content and attributes into valid style tag * * @param stdClass $item Item to render * @param string $indent Indentation to use * @return string */ public function itemToString(stdClass $item, $indent) { $attrString = ''; if (!empty($item->attributes)) { $enc = 'UTF-8'; if ($this->view instanceof Zend_View_Interface && method_exists($this->view, 'getEncoding') ) { $enc = $this->view->getEncoding(); } foreach ($item->attributes as $key => $value) { if (!in_array($key, $this->_optionalAttributes)) { continue; } if ('media' == $key) { if(false === strpos($value, ',')) { if (!in_array($value, $this->_mediaTypes)) { continue; } } else { $media_types = explode(',', $value); $value = ''; foreach($media_types as $type) { $type = trim($type); if (!in_array($type, $this->_mediaTypes)) { continue; } $value .= $type .','; } $value = substr($value, 0, -1); } } $attrString .= sprintf(' %s="%s"', $key, htmlspecialchars($value, ENT_COMPAT, $enc)); } } $escapeStart = $indent . ''. PHP_EOL; if (isset($item->attributes['conditional']) && !empty($item->attributes['conditional']) && is_string($item->attributes['conditional']) ) { $escapeStart = null; $escapeEnd = null; } $html = ''; if (null == $escapeStart && null == $escapeEnd) { $html = ''; } return $html; } /** * Create string representation of placeholder * * @param string|int $indent * @return string */ public function toString($indent = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) : $this->getIndent(); $items = array(); $this->getContainer()->ksort(); foreach ($this as $item) { if (!$this->_isValid($item)) { continue; } $items[] = $this->itemToString($item, $indent); } $return = $indent . implode($this->getSeparator() . $indent, $items); $return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return); return $return; } /** * Create data item for use in stack * * @param string $content * @param array $attributes * @return stdClass */ public function createData($content, array $attributes) { if (!isset($attributes['media'])) { $attributes['media'] = 'screen'; } else if(is_array($attributes['media'])) { $attributes['media'] = implode(',', $attributes['media']); } $data = new stdClass(); $data->content = $content; $data->attributes = $attributes; return $data; } } Partial/Exception.php000064400000002211152101637650010611 0ustar00setView($this->view); throw $e; } if (is_object($model) && (!$model instanceof Traversable) && method_exists($model, 'toArray') ) { $model = $model->toArray(); } $content = ''; // reset the counter if it's call again $this->partialCounter = 0; $this->partialTotalCount = count($model); foreach ($model as $item) { // increment the counter variable $this->partialCounter++; $content .= $this->partial($name, $module, $item); } return $content; } } ServerUrl.php000064400000010156152101637650007217 0ustar00setScheme($scheme); if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) { $this->setHost($_SERVER['HTTP_HOST']); } else if (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) { $name = $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; if (($scheme == 'http' && $port == 80) || ($scheme == 'https' && $port == 443)) { $this->setHost($name); } else { $this->setHost($name . ':' . $port); } } } /** * View helper entry point: * Returns the current host's URL like http://site.com * * @param string|boolean $requestUri [optional] if true, the request URI * found in $_SERVER will be appended * as a path. If a string is given, it * will be appended as a path. Default * is to not append any path. * @return string server url */ public function serverUrl($requestUri = null) { if ($requestUri === true) { $path = $_SERVER['REQUEST_URI']; } else if (is_string($requestUri)) { $path = $requestUri; } else { $path = ''; } return $this->getScheme() . '://' . $this->getHost() . $path; } /** * Returns host * * @return string host */ public function getHost() { return $this->_host; } /** * Sets host * * @param string $host new host * @return Zend_View_Helper_ServerUrl fluent interface, returns self */ public function setHost($host) { $this->_host = $host; return $this; } /** * Returns scheme (typically http or https) * * @return string scheme (typically http or https) */ public function getScheme() { return $this->_scheme; } /** * Sets scheme (typically http or https) * * @param string $scheme new scheme (typically http or https) * @return Zend_View_Helper_ServerUrl fluent interface, returns self */ public function setScheme($scheme) { $this->_scheme = $scheme; return $this; } } Fieldset.php000064400000004434152101637650007027 0ustar00_getInfo($name, $content, $attribs); extract($info); // get legend $legend = ''; if (isset($attribs['legend'])) { $legendString = trim($attribs['legend']); if (!empty($legendString)) { $legend = '' . (($escape) ? $this->view->escape($legendString) : $legendString) . '' . PHP_EOL; } unset($attribs['legend']); } // get id if (!empty($id)) { $id = ' id="' . $this->view->escape($id) . '"'; } else { $id = ''; } // render fieldset $xhtml = '_htmlAttribs($attribs) . '>' . $legend . $content . ''; return $xhtml; } } DeclareVars.php000064400000005624152101637650007465 0ustar00 * $this->declareVars( * 'varName1', * 'varName2', * array('varName3' => 'defaultValue', * 'varName4' => array() * ) * ); * * * @param string|array variable number of arguments, all string names of variables to test * @return void */ public function declareVars() { $args = func_get_args(); foreach($args as $key) { if (is_array($key)) { foreach ($key as $name => $value) { $this->_declareVar($name, $value); } } else if (!isset($view->$key)) { $this->_declareVar($key); } } } /** * Set a view variable * * Checks to see if a $key is set in the view object; if not, sets it to $value. * * @param string $key * @param string $value Defaults to an empty string * @return void */ protected function _declareVar($key, $value = '') { if (!isset($this->view->$key)) { $this->view->$key = $value; } } } FormElement.php000064400000014761152101637650007511 0ustar00_translator; } /** * Set translator * * @param Zend_Translate|Zend_Translate_Adapter|null $translator * @return Zend_View_Helper_FormElement */ public function setTranslator($translator = null) { if (null === $translator) { $this->_translator = null; } elseif ($translator instanceof Zend_Translate_Adapter) { $this->_translator = $translator; } elseif ($translator instanceof Zend_Translate) { $this->_translator = $translator->getAdapter(); } else { //--//require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('Invalid translator specified'); $e->setView($this->view); throw $e; } return $this; } /** * Converts parameter arguments to an element info array. * * E.g, formExample($name, $value, $attribs, $options, $listsep) is * the same thing as formExample(array('name' => ...)). * * Note that you cannot pass a 'disable' param; you need to pass * it as an 'attribs' key. * * @access protected * * @return array An element info array with keys for name, value, * attribs, options, listsep, disable, and escape. */ protected function _getInfo($name, $value = null, $attribs = null, $options = null, $listsep = null ) { // the baseline info. note that $name serves a dual purpose; // if an array, it's an element info array that will override // these baseline values. as such, ignore it for the 'name' // if it's an array. $info = array( 'name' => is_array($name) ? '' : $name, 'id' => is_array($name) ? '' : $name, 'value' => $value, 'attribs' => $attribs, 'options' => $options, 'listsep' => $listsep, 'disable' => false, 'escape' => true, ); // override with named args if (is_array($name)) { // only set keys that are already in info foreach ($info as $key => $val) { if (isset($name[$key])) { $info[$key] = $name[$key]; } } // If all helper options are passed as an array, attribs may have // been as well if (null === $attribs) { $attribs = $info['attribs']; } } $attribs = (array)$attribs; // Normalize readonly tag if (array_key_exists('readonly', $attribs)) { $attribs['readonly'] = 'readonly'; } // Disable attribute if (array_key_exists('disable', $attribs)) { if (is_scalar($attribs['disable'])) { // disable the element $info['disable'] = (bool)$attribs['disable']; } else if (is_array($attribs['disable'])) { $info['disable'] = $attribs['disable']; } } // Set ID for element if (array_key_exists('id', $attribs)) { $info['id'] = (string)$attribs['id']; } else if ('' !== $info['name']) { $info['id'] = trim(strtr($info['name'], array('[' => '-', ']' => '')), '-'); } // Remove NULL name attribute override if (array_key_exists('name', $attribs) && is_null($attribs['name'])) { unset($attribs['name']); } // Override name in info if specified in attribs if (array_key_exists('name', $attribs) && $attribs['name'] != $info['name']) { $info['name'] = $attribs['name']; } // Determine escaping from attributes if (array_key_exists('escape', $attribs)) { $info['escape'] = (bool)$attribs['escape']; } // Determine listsetp from attributes if (array_key_exists('listsep', $attribs)) { $info['listsep'] = (string)$attribs['listsep']; } // Remove attribs that might overwrite the other keys. We do this LAST // because we needed the other attribs values earlier. foreach ($info as $key => $val) { if (array_key_exists($key, $attribs)) { unset($attribs[$key]); } } $info['attribs'] = $attribs; // done! return $info; } /** * Creates a hidden element. * * We have this as a common method because other elements often * need hidden elements for their operation. * * @access protected * * @param string $name The element name. * @param string $value The element value. * @param array $attribs Attributes for the element. * * @return string A hidden element. */ protected function _hidden($name, $value = null, $attribs = null) { return '_htmlAttribs($attribs) . $this->getClosingBracket(); } } Cycle.php000064400000011353152101637650006325 0ustar00-1) ; /** * Array of values * * @var array */ protected $_data = array(self::DEFAULT_NAME=>array()); /** * Actual name of cycle * * @var string */ protected $_name = self::DEFAULT_NAME; /** * Add elements to alternate * * @param array $data * @param string $name * @return Zend_View_Helper_Cycle */ public function cycle(array $data = array(), $name = self::DEFAULT_NAME) { if(!empty($data)) $this->_data[$name] = $data; $this->setName($name); return $this; } /** * Add elements to alternate * * @param array $data * @param string $name * @return Zend_View_Helper_Cycle */ public function assign(Array $data , $name = self::DEFAULT_NAME) { $this->setName($name); $this->_data[$name] = $data; $this->rewind(); return $this; } /** * Sets actual name of cycle * * @param string $name * @return Zend_View_Helper_Cycle */ public function setName($name = self::DEFAULT_NAME) { $this->_name = $name; if(!isset($this->_data[$this->_name])) $this->_data[$this->_name] = array(); if(!isset($this->_pointers[$this->_name])) $this->rewind(); return $this; } /** * Gets actual name of cycle * * @return string */ public function getName() { return $this->_name; } /** * Return all elements * * @return array */ public function getAll() { return $this->_data[$this->_name]; } /** * Turn helper into string * * @return string */ public function toString() { return (string) $this->_data[$this->_name][$this->key()]; } /** * Cast to string * * @return string */ public function __toString() { return $this->toString(); } /** * Move to next value * * @return Zend_View_Helper_Cycle */ public function next() { $count = count($this->_data[$this->_name]); if ($this->_pointers[$this->_name] == ($count - 1)) $this->_pointers[$this->_name] = 0; else $this->_pointers[$this->_name] = ++$this->_pointers[$this->_name]; return $this; } /** * Move to previous value * * @return Zend_View_Helper_Cycle */ public function prev() { $count = count($this->_data[$this->_name]); if ($this->_pointers[$this->_name] <= 0) $this->_pointers[$this->_name] = $count - 1; else $this->_pointers[$this->_name] = --$this->_pointers[$this->_name]; return $this; } /** * Return iteration number * * @return int */ public function key() { if ($this->_pointers[$this->_name] < 0) return 0; else return $this->_pointers[$this->_name]; } /** * Rewind pointer * * @return Zend_View_Helper_Cycle */ public function rewind() { $this->_pointers[$this->_name] = -1; return $this; } /** * Check if element is valid * * @return bool */ public function valid() { return isset($this->_data[$this->_name][$this->key()]); } /** * Return current element * * @return mixed */ public function current() { return $this->_data[$this->_name][$this->key()]; } } Placeholder.php000064400000004633152101637650007513 0ustar00_registry = Zend_View_Helper_Placeholder_Registry::getRegistry(); } /** * Placeholder helper * * @param string $name * @return Zend_View_Helper_Placeholder_Container_Abstract */ public function placeholder($name) { $name = (string) $name; return $this->_registry->getContainer($name); } /** * Retrieve the registry * * @return Zend_View_Helper_Placeholder_Registry */ public function getRegistry() { return $this->_registry; } } InlineScript.php000064400000004106152101637650007667 0ustar00headScript($mode, $spec, $placement, $attrs, $type); } } Doctype.php000064400000017337152101637650006705 0ustar00_regKey)) { $this->_registry = new ArrayObject(array( 'doctypes' => array( self::XHTML11 => '', self::XHTML1_STRICT => '', self::XHTML1_TRANSITIONAL => '', self::XHTML1_FRAMESET => '', self::XHTML1_RDFA => '', self::XHTML1_RDFA11 => '', self::XHTML_BASIC1 => '', self::XHTML5 => '', self::HTML4_STRICT => '', self::HTML4_LOOSE => '', self::HTML4_FRAMESET => '', self::HTML5 => '', ) )); Zend_Registry::set($this->_regKey, $this->_registry); $this->setDoctype($this->_defaultDoctype); } else { $this->_registry = Zend_Registry::get($this->_regKey); } } /** * Set or retrieve doctype * * @param string $doctype * @return Zend_View_Helper_Doctype */ public function doctype($doctype = null) { if (null !== $doctype) { switch ($doctype) { case self::XHTML11: case self::XHTML1_STRICT: case self::XHTML1_TRANSITIONAL: case self::XHTML1_FRAMESET: case self::XHTML_BASIC1: case self::XHTML1_RDFA: case self::XHTML1_RDFA11: case self::XHTML5: case self::HTML4_STRICT: case self::HTML4_LOOSE: case self::HTML4_FRAMESET: case self::HTML5: $this->setDoctype($doctype); break; default: if (substr($doctype, 0, 9) != 'setView($this->view); throw $e; } if (stristr($doctype, 'xhtml')) { $type = self::CUSTOM_XHTML; } else { $type = self::CUSTOM; } $this->setDoctype($type); $this->_registry['doctypes'][$type] = $doctype; break; } } return $this; } /** * Set doctype * * @param string $doctype * @return Zend_View_Helper_Doctype */ public function setDoctype($doctype) { $this->_registry['doctype'] = $doctype; return $this; } /** * Retrieve doctype * * @return string */ public function getDoctype() { return $this->_registry['doctype']; } /** * Get doctype => string mappings * * @return array */ public function getDoctypes() { return $this->_registry['doctypes']; } /** * Is doctype XHTML? * * @return boolean */ public function isXhtml() { return (stristr($this->getDoctype(), 'xhtml') ? true : false); } /** * Is doctype strict? * * @return boolean */ public function isStrict() { switch ( $this->getDoctype() ) { case self::XHTML1_STRICT: case self::XHTML11: case self::HTML4_STRICT: return true; default: return false; } } /** * Is doctype HTML5? (HeadMeta uses this for validation) * * @return booleean */ public function isHtml5() { return (stristr($this->doctype(), '') ? true : false); } /** * Is doctype RDFa? * * @return booleean */ public function isRdfa() { return (stristr($this->getDoctype(), 'rdfa') ? true : false); } /** * String representation of doctype * * @return string */ public function __toString() { $doctypes = $this->getDoctypes(); return $doctypes[$this->getDoctype()]; } } SendFile.php000064400000022416152101671420006752 0ustar00getResponse(); $cacheControl = array(); if (isset($options['public']) && $options['public']) { $cacheControl[] = 'public'; } if (isset($options['no-cache']) && $options['no-cache']) { $cacheControl[] = 'no-cache'; } if (isset($options['no-store']) && $options['no-store']) { $cacheControl[] = 'no-store'; } if (isset($options['must-revalidate']) && $options['must-revalidate']) { $cacheControl[] = 'must-revalidate'; } if (isset($options['proxy-validation']) && $options['proxy-validation']) { $cacheControl[] = 'proxy-validation'; } if (isset($options['max-age'])) { $cacheControl[] = 'max-age=' . (int) $options['max-age']; $response->setHeader('Expires', gmdate('r', time() + $options['max-age']), true); } if (isset($options['s-maxage'])) { $cacheControl[] = 's-maxage=' . (int) $options['s-maxage']; } $response->setHeader('Cache-Control', implode(',', $cacheControl), true); $response->setHeader('Pragma', 'public', true); } /** * Validate the cache using the If-Modified-Since request header * * @param int $modified When the file was last modified as a unix timestamp * @return bool */ protected function notModifiedSince($modified) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { // Send a 304 Not Modified header $response = $this->getResponse(); $response->setHttpResponseCode(304); $response->sendHeaders(); return true; } return false; } /** * Check whether it is range request using the HTTP_RANGE request header * * @param int $modified When the file was last modified as a unix timestamp * @return bool */ protected function isRangeRequest() { return isset($_SERVER['HTTP_RANGE']); } /** * Send a file for download * * @param string $path Path to the file * @param string $type The mime-type of the file * @param array $options * @return bool Whether the headers and file were sent */ public function sendFile($path, $type, $options = array()) { while (@ob_end_clean()); Zend_Session::writeClose(); $response = $this->getResponse(); if (!is_readable($path)) throw new Am_Exception_InternalError("File [$path] does not exists"); if (!$response->canSendHeaders()) throw new Am_Exception_InternalError("Headers are already sent"); // Set the cache-control if (isset($options['cache'])) { $this->setCacheHeaders($options['cache']); } // Get the last modified time if (isset($options['modified'])) { $modified = (int) $options['modified']; } else { $modified = filemtime($path); } // Validate the cache if (!isset($options['cache']['no-store']) && $this->notModifiedSince($modified)) { return true; } // Set the file name if (isset($options['filename']) && !empty($options['filename'])) { $filename = $options['filename']; } else { $filename = basename($path); } // Set the content disposition if (isset($options['disposition']) && $options['disposition'] == 'inline') { $disposition = 'inline'; } else { $disposition = 'attachment'; } $response->setHeader('Content-Type', $type, true); $response->setHeader('Content-Disposition', $disposition . '; filename="' . $filename . '"', true); $response->setHeader('Last-Modified', gmdate('r', $modified), true); $response->setHeader('Accept-Ranges', 'bytes', true); // Do we want to use the X-Sendfile header or stream the file if (isset($options['xsendfile']) && $options['xsendfile']) { $response->setHeader('X-Sendfile', $path); $response->sendHeaders(); return true; } if ($this->isRangeRequest()) { return $this->sendFileRange($path); } $response->setHttpResponseCode(200); $response->setHeader('Content-Length', filesize($path), true); $response->sendHeaders(); readfile($path); exit(); } /** * Send file data as a download * * @param string $path Path to the file * @param string $type The mime-type of the file * @param string $filename The filename to send the file as, if null then use the base name of the path * @param array $options * @return bool Whether the headers and file were sent */ public function sendData($data, $type, $filename, $options = array()) { $response = $this->getResponse(); if (!$response->canSendHeaders()) { return false; } // Set the cache-control if (isset($options['cache'])) { $this->setCacheHeaders($options['cache']); } if (isset($options['modified'])) { // Validate the cache if (!isset($options['cache']['no-store']) && $this->notModifiedSince($options['modified'])) { return true; } $response->setHeader('Last-Modified', gmdate('r', $options['modified']), true); } // Set the content disposition if (isset($options['disposition']) && $options['disposition'] == 'inline') { $disposition = 'inline'; } else { $disposition = 'attachment'; } $response->setHttpResponseCode(200); $response->setHeader('Content-Type', $type, true); $response->setHeader('Content-Disposition', $disposition . '; filename="' . $filename . '"', true); $response->setHeader('Content-Length', strlen($data), true); $response->setBody($data); } /** * Proxy method for sendFile * * @param string $path Path to the file * @param string $type The mime-type of the file * @param array $options * @return bool Whether the headers and file were sent */ public function direct($path, $type, $options = array()) { return $this->sendFile($path, $type, $options); } /** * Send a file range for download * http://tools.ietf.org/html/rfc2616#section-14.35 * * @param string $path */ protected function sendFileRange($path) { $response = $this->getResponse(); $filesize = filesize($path); preg_match('/bytes=(.*)/', $_SERVER['HTTP_RANGE'], $matches); $ranges = $this->_parseRange($matches[1], $filesize); //we process only first range now foreach ($ranges as $first_byte => $last_byte) break; $length = $last_byte - $first_byte + 1; $file = fopen($path, 'r'); fseek($file, $first_byte); $response->setHttpResponseCode(206); $response->setHeader('Content-Range', 'bytes ' . $first_byte . '-' . $last_byte . '/' . $filesize, true); $response->setHeader('Content-Length', $length, true); $response->sendHeaders(); $chunk = 1024*1024; for($i=$first_byte; $i<$last_byte; $i+=$chunk) print fread($file, min($chunk,$last_byte-$i+1)); fclose($file); exit(); } public function _parseRange($range_spec, $filesize) { $ranges = array(); foreach (explode(',', $range_spec) as $range) { list($first_byte, $last_byte) = explode('-', $range); if ($first_byte == '') { //bytes=-500 *last 500 bytes $first_byte = $filesize - $last_byte; $last_byte = $filesize-1; } else { //bytes=500-999 *500 bytes range //bytes=9500- *from 9500 up to the end $first_byte = intval($first_byte); $last_byte = min(($filesize-1), (($last_byte == '') ? ($filesize-1) : intval($last_byte))); } if ($first_byte > $last_byte) continue; $ranges[$first_byte] = isset($ranges[$first_byte]) ? max($ranges[$first_byte], $last_byte) : $last_byte; } ksort($ranges); $collapsed = array(); $prev = -1000; //just value that is always less foreach ($ranges as $first => $last) { if ($first <= ($prev + 1)) { $prev = $last; } else { $collapsed[$first] = $last; $prev = & $collapsed[$first]; } } return $collapsed; } }