示例#1
0
 /**
  * @param     $path
  * @param int $type
  *
  * @return mixed|string
  */
 public function getUrlForPath($path, $type = self::RELATIVE_URL)
 {
     if (is_string($path)) {
         $uri = new RokUpdater_Uri($path);
     } else {
         if ($path instanceof RokUpdater_Uri) {
             $uri = $path;
         } else {
             return false;
         }
     }
     // if its external  just return the external url
     if ($this->isExternal($uri)) {
         return $path;
     }
     $clean_uri_path = preg_match('/^WIN/', PHP_OS) && preg_match('/^[a-zA-Z]:/', $uri->getPath()) ? '' : '/';
     $clean_uri_path .= self::cleanFilesystemPath($uri->getPath());
     $clean_site_uri_path = preg_match('/^WIN/', PHP_OS) && preg_match('/^[a-zA-Z]:/', $this->site_uri->getPath()) ? '' : '/';
     $clean_site_uri_path .= self::cleanFilesystemPath($this->site_uri->getPath());
     if (!@file_exists($clean_uri_path)) {
         return $clean_uri_path;
     }
     $return_uri = clone $this->site_uri;
     // check if the path seems to be in the instances  or  server path
     // leave it as is if not one of the two
     if (strpos($clean_uri_path, $this->site_root_path) === 0) {
         // its an instance path
         $return_uri->appendPath(str_replace($this->site_root_path, '', $clean_uri_path));
     } elseif (!is_null($this->server_root_path) && strpos($clean_uri_path, $this->server_root_path) === 0) {
         // its a server path
         $return_uri->setPath(str_replace($this->server_root_path, '', $clean_uri_path));
     } else {
         if (is_null($this->server_root_path) && !isset($_SERVER['DOCUMENT_ROOT'])) {
             trigger_error('No $_SERVER[\'DOCUMENT_ROOT\'] value is set.  Unable to find path to map to URL. Assuming root.', E_USER_NOTICE);
             $return_uri = $uri;
         } else {
             $return_uri = $uri;
         }
     }
     return $return_uri->getComponents($type);
 }
示例#2
0
 /**
  * @param  RokUpdater_Uri   $uri
  * @param  array $components
  * @param  bool  $esc
  *
  * @return string
  */
 private static function getRelativeComponents(RokUpdater_Uri $uri, $components, $esc)
 {
     $result = '';
     if ($components & RokUpdater_Uri_Components::PATH) {
         $cmp = $uri->getPath();
         $result .= '/';
         if ($esc) {
             foreach (explode('/', $cmp) as $key => $value) {
                 $result .= ($key === 0 ? '' : '/') . rawurlencode($value);
             }
         } else {
             $result .= $cmp;
         }
     }
     if ($components & RokUpdater_Uri_Components::QUERY) {
         $cmp = $uri->getQuery();
         if (!empty($cmp)) {
             if ($esc) {
                 parse_str($cmp, $cmp);
                 $result .= '?' . str_replace('+', '%20', http_build_query($cmp, null, '&'));
             } else {
                 $result .= "?{$cmp}";
             }
         }
     }
     //FRAGMENT:
     if ($components & RokUpdater_Uri_Components::FRAGMENT) {
         $cmp = $uri->getFragment();
         if (!empty($cmp)) {
             if ($esc) {
                 $result .= '#' . rawurlencode($cmp);
             } else {
                 $result .= "#{$cmp}";
             }
         }
     }
     //		RESULT:
     return $result;
 }