diff -r 000000000000 -r 4eba9c11703f web/Zend/View/Helper/BaseUrl.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/Zend/View/Helper/BaseUrl.php Mon Dec 13 18:29:26 2010 +0100 @@ -0,0 +1,116 @@ +getBaseUrl(); + + // 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; + } +}