You are here

function iframe_validate_url in Iframe 6

Same name and namespace in other branches
  1. 7 iframe.module \iframe_validate_url()

A lenient verification for URLs. Accepts all URLs following RFC 1738 standard for URL formation and all email addresses following the RFC 2368 standard for mailto address formation.

Parameters

string $text:

Return value

mixed Returns boolean FALSE if the URL is not valid. On success, returns an object with the following attributes: protocol, hostname, ip, and port.

4 calls to iframe_validate_url()
iframe_cleanup_url in ./iframe.module
Forms a valid URL if possible from an entered address. Trims whitespace and automatically adds an http:// to addresses without a protocol specified
_iframe_process in ./iframe.module
_iframe_sanitize in ./iframe.module
Cleanup user-entered values for a iframe field according to field settings.
_iframe_validate in ./iframe.module

File

./iframe.module, line 753
Defines simple iframe field types. based on the cck-module "link" by quicksketch MODULE-Funtions

Code

function iframe_validate_url($text) {
  dmsg(3, 'func iframe_validate_url');
  $allowed_protocols = variable_get('filter_allowed_protocols', array(
    'http',
    'https',
    'ftp',
    'news',
    'nntp',
    'telnet',
    'mailto',
    'irc',
    'ssh',
    'sftp',
    'webcal',
  ));
  $protocol = '((' . implode("|", $allowed_protocols) . '):\\/\\/)';
  $authentication = '([a-z0-9]+(:[a-z0-9]+)?@)';
  $domain = '(([a-z0-9]([a-z0-9\\-_\\[\\]äöü])*)(\\.(([a-z0-9\\-_\\[\\]äöü])+\\.)*(' . iframe_DOMAINS . '|[a-z]{2}))?)';
  $ipv4 = '([0-9]{1,3}(\\.[0-9]{1,3}){3})';
  $ipv6 = '([0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})';
  $port = '(:([0-9]{1,5}))';

  // Pattern specific to external iframes.
  $external_pattern = '/^' . $protocol . '?' . $authentication . '?' . '(' . $domain . '|' . $ipv4 . '|' . $ipv6 . ' |localhost)' . $port . '?';

  // Pattern specific to internal iframes.
  $internal_pattern = "/^([a-z0-9_\\-+\\[\\]]+)";
  $directories = "(\\/[a-z0-9_\\-\\.~+%=&,\$'():;*@\\[\\]]*)*";

  // Yes, four backslashes == a single backslash.
  $query = "(\\/?\\?([?a-z0-9+_|\\-\\.\\!\\/\\\\%=&,\$'():;*@\\[\\]\\{\\}]*))";
  $anchor = "(#[a-z0-9_\\-\\.~+%=&,\$'():;*@\\[\\]]*)";

  // The rest of the path for a standard URL.
  $end = $directories . '?' . $query . '?' . $anchor . '?' . '$/i';
  $user = '[a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~\'\\[\\]]+';
  $email_pattern = '/^mailto:' . $user . '@' . '(' . $domain . '|' . $ipv4 . '|' . $ipv6 . '|localhost)' . $query . '?$/';
  if (strpos($text, '<front>') === 0) {
    return iframe_FRONT;
  }
  if (in_array('mailto', $allowed_protocols) && preg_match($email_pattern, $text)) {
    return iframe_EMAIL;
  }
  if (preg_match($internal_pattern . $end, $text)) {
    return iframe_INTERNAL;
  }
  if (preg_match($external_pattern . $end, $text)) {
    return iframe_EXTERNAL;
  }
  return FALSE;
}