You are here

function iframe_cleanup_url in Iframe 6

Forms a valid URL if possible from an entered address. Trims whitespace and automatically adds an http:// to addresses without a protocol specified

Parameters

string $url:

string $protocol The protocol to be prepended to the url if one is not specified:

1 call to iframe_cleanup_url()
_iframe_sanitize in ./iframe.module
Cleanup user-entered values for a iframe field according to field settings.

File

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

Code

function iframe_cleanup_url($url, $protocol = "http") {
  dmsg(3, 'func iframe_cleanup_url');
  $url = trim($url);
  $type = iframe_validate_url($url);
  if ($type == iframe_EXTERNAL) {

    // Check if there is no protocol specified.
    $protocol_match = preg_match("/^([a-z0-9][a-z0-9\\.\\-_äöü]*:\\/\\/)/i", $url);
    if (empty($protocol_match)) {

      // But should there be? Add an automatic http:// if it starts with a domain name.
      $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\\-_äöü]*\\.)+)(' . iframe_DOMAINS . '|[a-z]{2}))/i', $url);
      if (!empty($domain_match)) {
        $url = $protocol . '://' . $url;
      }
    }
  }
  return $url;
}