/**
  * Determines whether the root needs to be prepended to the given url.
  * If the url already has a domain, if it starts with an {@link
  * $anchor_delimiter} (assumes the link will be resolvable in page context).
  * or if it starts with a delimiter and the root does not have a domain, no
  * root can be prepended. If the url is empty, the root can be prepended.
  *
  * @see _finalize_url()
  *
  * @param string $url The url to resolve.
  * @param bool $root_override If null, no override is applied; if true, the root is applied; otherwise, no root is applied.
  * @return boolean
  *
  * @access private
  */
 protected function _needs_root($url, $root_override)
 {
     /* Check that there is a root and that it is desired. */
     $Result = $this->root_url && ($this->resolve_to_root || !empty($root_override)) && !(isset($root_override) && !$root_override);
     /* Check that the url is empty or does not begin with an anchor. */
     if ($Result) {
         $Result = !$url || $url[0] != $this->anchor_delimiter;
     }
     /* Check that the root is not already present. */
     if ($Result) {
         $Result = strpos($url, $this->root_url) !== 0;
     }
     /* Check that the url does not already have a domain. */
     if ($Result) {
         $Result = !has_domain($url, '', $this->_url_options);
     }
     /* Check that the root has a domain or that the url does not begin
      * with a delimiter.
      */
     if ($Result) {
         $Result = has_domain($this->root_url, '', $this->_url_options) || !begins_with_delimiter($url, $this->_url_options);
     }
     return $Result;
 }
 private function _test_delimiters()
 {
     $file_options = global_file_options();
     $delimiter = $file_options->path_delimiter;
     $this->_check_equal(false, begins_with_delimiter('path/to/the/folder/'));
     $this->_check_equal(true, begins_with_delimiter($delimiter . 'path/to/the/folder/'));
     $this->_check_equal(true, ends_with_delimiter('path/to/the/folder' . $file_options->path_delimiter));
     $this->_check_equal(false, ends_with_delimiter('path/to/the/folder'));
     $this->_check_equal(true, begins_with_delimiter(ensure_begins_with_delimiter('path/to/the/folder/')));
     $this->_check_equal(true, begins_with_delimiter(ensure_begins_with_delimiter('/path/to/the/folder/')));
     $this->_check_equal(true, ends_with_delimiter(ensure_ends_with_delimiter('path/to/the/folder/')));
     $this->_check_equal(true, ends_with_delimiter(ensure_ends_with_delimiter('path/to/the/folder')));
 }
Exemple #3
0
/**
 * Does the path include the root?
 * Returns <code>True</code> there is a Windows drive or if the name begins with
 * a delimiter and {@link FILE_OPTIONS:: path_starts_with_delimiter()} is true.
 * @param string $f The path to check.
 * @param FILE_OPTIONS $opts
 * @return boolean
 */
function has_root($f, $opts = null)
{
    if (!isset($opts)) {
        $opts = global_file_options();
    }
    $path_starts_with_delimiter = $opts->path_starts_with_delimiter();
    return $path_starts_with_delimiter && begins_with_delimiter($f, $opts) || !$path_starts_with_delimiter && strpos($f, ':') == 1;
}