function test_is_absolute_url() { $this->assertTrue(is_absolute_url('http://www.google.com')); $this->assertTrue(is_absolute_url('//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js')); $this->assertFalse(is_absolute_url('/ajax/libs/jquery/1.4.2/jquery.js')); // ftp is not supported $this->assertFalse(is_absolute_url('ftp://ajax/libs/jquery/1.4.2/jquery.js')); }
function test_is_absolute_url() { $this->assertTrue(is_absolute_url('http://www.google.com')); $this->assertTrue(is_absolute_url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7')); $this->assertTrue(is_absolute_url('//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js')); $this->assertFalse(is_absolute_url('/ajax/libs/jquery/1.4.2/jquery.js')); // ftp is not supported $this->assertFalse(is_absolute_url('ftp://ajax/libs/jquery/1.4.2/jquery.js')); }
param('renamedFiles', 'array', array(), true); $renamedMessages = array(); // Process files we want to get from an URL: param('uploadfile_url', 'array', array()); param('uploadfile_source', 'array', array()); if ($action != 'switchtab' && $uploadfile_url) { // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('file'); foreach ($uploadfile_url as $k => $url) { if (!isset($uploadfile_source[$k]) || $uploadfile_source[$k] != 'upload') { // upload by URL has not been selected continue; } if (strlen($url)) { // Validate URL and parse it for the file name if (!is_absolute_url($url) || !($parsed_url = parse_url($url)) || empty($parsed_url['scheme']) || empty($parsed_url['host']) || empty($parsed_url['path']) || $parsed_url['path'] == '/') { // Includes forbidding getting the root of a server $failedFiles[$k] = T_('The URL must start with <code>http://</code> or <code>https://</code> and point to a valid file!'); continue; } $file_contents = fetch_remote_page($url, $info, NULL, $Settings->get('upload_maxkb')); if ($file_contents !== false) { // Create temporary file and insert contents into it. $tmpfile_name = tempnam(sys_get_temp_dir(), 'fmupload'); if (!$tmpfile_name) { $failedFiles[$k] = 'Failed to find temporary directory.'; // no trans: very unlikely continue; } if (!save_to_file($file_contents, $tmpfile_name, 'w')) { unlink($tmpfile_name);
/** * Returns an HTML script tag for each of the sources provided as arguments. * Sources may be paths to JavaScript files. Relative paths are assumed to be * relative to assets/javascripts. When passing paths, the ".js" extension is * optional. * If the last argument is an array, it will be used as tag attributes. * * @return @e string * A valid \<script /\> HTML tag. * * @ingroup helperfunc * * @see TagHelper::content_tag() * */ function javascript_include_tag() { $sources = func_get_args(); $attributes = NULL; if (is_array($sources[count($sources) - 1])) { $attributes = array_pop($sources); } $tags = array(); foreach ($sources as $source) { // only http[s] or // (leading double slash to inherit the protocol) // are treated as absolute url if (!is_absolute_url($source)) { $source = javascript_url($source); if (!preg_match("/\\.js\$/", $source)) { $source .= ".js"; } $source = $this->asset_version($source); } $options = array("src" => $source, "type" => "text/javascript"); if (is_array($attributes)) { $options = array_merge($options, $attributes); } $tags[] = content_tag("script", "", $options); } return join("\n", $tags); }
/** * Make an $url absolute according to $host, if it is not absolute yet. * * @param string URL * @param string Base (including protocol, e.g. 'http://example.com'); autodedected * @return string */ function url_absolute($url, $base = NULL) { load_funcs('_ext/_url_rel2abs.php'); if (is_absolute_url($url)) { // URL is already absolute return $url; } if (empty($base)) { // Detect current page base global $Blog, $ReqHost, $base_tag_set, $baseurl; if ($base_tag_set) { // <base> tag is set $base = $base_tag_set; } else { if (!empty($Blog)) { // Get original blog skin, not passed with 'tempskin' param $SkinCache =& get_SkinCache(); if (($Skin = $SkinCache->get_by_ID($Blog->get_skin_ID(), false)) !== false) { $base = $Blog->get_local_skins_url() . $Skin->folder . '/'; } else { // Skin not set: $base = $Blog->gen_baseurl(); } } else { // We are displaying a general page that is not specific to a blog: $base = $ReqHost; } } } if (($absurl = url_to_absolute($url, $base)) === false) { // Return relative URL in case of error $absurl = $url; } return $absurl; }
/** * 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)); }