function test_is_root_relative_url() { $this->assertTrue(is_root_relative_url('/img/logo.png')); $this->assertFalse(is_root_relative_url('//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js')); $this->assertFalse(is_root_relative_url('ajax/libs/jquery/1.4.2/jquery.js')); $this->assertFalse(is_root_relative_url('http://ajax.googleapis.comajax/libs/jquery/1.4.2/jquery.js')); }
/** * Builds a valid \<img /\> HTML tag. * * @param string $source * The source path to the image. * @param string|array $attributes * (optional) A single HTML attribute or an array of HTML attributes to be * added to the rendered tag. * @return @e string * A valid \<img /\> HTML tag. * * @ingroup helperfunc * * @see TagHelper::content_tag() * */ public function image_tag($source, $attributes = NULL) { if (!(is_absolute_url($source) || is_root_relative_url($source))) { $source = image_url($source); } $info = pathinfo($source); $extension = isset($info['extension']) ? $info['extension'] : ''; $options = array("src" => $this->asset_version($source), "alt" => capitalize(basename($source, '.' . $extension))); if (is_array($attributes)) { $options = array_merge($options, $attributes); } return content_tag("img", NULL, $options); }
/** * Check if an URL is relative * URL are considered relative if they are not absolute and don't begin with a / * * @param string $url * The url to check. * @return boolean * Either true if the URL is relative or false if it is not. * * @ingroup helperfunc */ function is_relative_url($url) { return !(is_absolute_url($url) || is_root_relative_url($url)); }