function link_validate_url in Link 7
Same name and namespace in other branches
- 5 link.module \link_validate_url()
- 6.2 link.inc \link_validate_url()
- 6 link.module \link_validate_url()
Validates a URL.
Parameters
string $text: Url to be validated.
string $langcode: An optional language code to look up the path in.
Return value
bool True if a valid link, FALSE otherwise.
13 calls to link_validate_url()
- LinkValidationApiTest::testInvalidExternalLinks in tests/
LinkValidationApiTest.test - Check Invalid External Links.
- LinkValidationApiTest::testValidateBadNewsgroupLink in tests/
LinkValidationApiTest.test - Validate Bad Newsgroup Link.
- LinkValidationApiTest::testValidateEmailLink in tests/
LinkValidationApiTest.test - Validate Email Link.
- LinkValidationApiTest::testValidateEmailLinkBad in tests/
LinkValidationApiTest.test - Validate Email Link Bad.
- LinkValidationApiTest::testValidateExternalLinks in tests/
LinkValidationApiTest.test - Validate External Links.
File
- ./
link.module, line 1622 - Defines simple link field types.
Code
function link_validate_url($text, $langcode = NULL) {
$text = _link_clean_relative($text);
$text = link_cleanup_url($text);
$type = link_url_type($text);
if ($type && ($type == LINK_INTERNAL || $type == LINK_EXTERNAL)) {
$flag = valid_url($text, $type == LINK_EXTERNAL);
if (!$flag) {
$normal_path = drupal_get_normal_path($text, $langcode);
$parsed_link = parse_url($normal_path, PHP_URL_PATH);
if ($normal_path != $parsed_link) {
$normal_path = $parsed_link;
}
$flag = drupal_valid_path($normal_path);
}
if (!$flag) {
$flag = file_exists($normal_path);
}
if (!$flag) {
$uri = file_build_uri($normal_path);
$flag = file_exists($uri);
}
}
else {
$flag = (bool) $type;
}
return $flag;
}