Gregwar\RST\Environment::relativeUrl PHP Method

relativeUrl() public method

./" will be added to go to the upper directory
public relativeUrl ( $url )
    public function relativeUrl($url)
    {
        // If string contains ://, it is considered as absolute
        if (preg_match('/:\\/\\//mUsi', $url)) {
            return $url;
        }
        // If string begins with "/", the "/" is removed to resolve the
        // relative path
        if (strlen($url) && $url[0] == '/') {
            $url = substr($url, 1);
            if ($this->samePrefix($url)) {
                // If the prefix is the same, simply returns the file name
                $relative = basename($url);
            } else {
                // Else, returns enough ../ to get upper
                $relative = '';
                for ($k = 0; $k < $this->getDepth(); $k++) {
                    $relative .= '../';
                }
                $relative .= $url;
            }
        } else {
            $relative = $url;
        }
        return $relative;
    }

Usage Example

Example #1
0
File: Doc.php Project: cmsilex/rst
 public function resolve(Environment $environment, $data)
 {
     $metas = $environment->getMetas();
     $file = $environment->canonicalUrl($data);
     if ($metas) {
         $entry = $metas->get($file);
         $entry['url'] = $environment->relativeUrl('/' . $entry['url']);
     } else {
         $entry = array('title' => '(unresolved)', 'url' => '#');
     }
     return $entry;
 }
All Usage Examples Of Gregwar\RST\Environment::relativeUrl