diff --git a/link.module b/link.module index 9e52de5..9d3069f 100644 --- a/link.module +++ b/link.module @@ -286,9 +286,32 @@ function _link_load($field, $item, $instance) { * Prepares the item attributes and url for storage. */ function _link_process(&$item, $delta = 0, $field, $entity) { + global $base_url, $base_secure_url, $base_insecure_url; + // Trim whitespace from URL. $item['url'] = trim($item['url']); + // Store system paths. + // Work out the correct base_path to use based on the HTTPS settings. + if (variable_get('https', FALSE)) { + $base_url = $base_secure_url; + } + elseif (!empty($base_insecure_url) && $base_insecure_url != $base_url) { + $base_url = $base_insecure_url; + } + // Strip the system $base_url and the base_path(). + $raw_path = str_replace($base_url . base_path(), '', $item['url']); + $normal_path = drupal_get_normal_path($raw_path); + if ($item['url'] != $normal_path) { + $item['url'] = $normal_path; + } + else { + $normal_path = drupal_get_normal_path($item['url']); + if ($item['url'] != $normal_path) { + $item['url'] = $normal_path; + } + } + // if no attributes are set then make sure $item['attributes'] is an empty array - this lets $field['attributes'] override it. if (empty($item['attributes'])) { $item['attributes'] = array();