00001 <?php
00024 require_once 'Zend/View/Helper/Abstract.php';
00025
00034 class Zend_View_Helper_BaseUrl extends Zend_View_Helper_Abstract
00035 {
00041 protected $_baseUrl;
00042
00051 public function baseUrl($file = null)
00052 {
00053
00054 $baseUrl = $this->getBaseUrl();
00055
00056
00057 if (null !== $file) {
00058 $file = '/' . ltrim($file, '/\\');
00059 }
00060
00061 return $baseUrl . $file;
00062 }
00063
00070 public function setBaseUrl($base)
00071 {
00072 $this->_baseUrl = rtrim($base, '/\\');
00073 return $this;
00074 }
00075
00081 public function getBaseUrl()
00082 {
00083 if ($this->_baseUrl === null) {
00085 require_once 'Zend/Controller/Front.php';
00086 $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
00087
00088
00089 $baseUrl = $this->_removeScriptName($baseUrl);
00090
00091 $this->setBaseUrl($baseUrl);
00092 }
00093
00094 return $this->_baseUrl;
00095 }
00096
00103 protected function _removeScriptName($url)
00104 {
00105 if (!isset($_SERVER['SCRIPT_NAME'])) {
00106
00107 return $url;
00108 }
00109
00110 if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
00111 $url = substr($url, 0, $pos);
00112 }
00113
00114 return $url;
00115 }
00116 }