You are here

function theme_filefield_formatter_url_plain in FileField 6.3

Theme function for the 'url_plain' formatter.

File

./filefield_formatter.inc, line 47
FileField: Defines a CCK file field type.

Code

function theme_filefield_formatter_url_plain($element) {

  // Inside a View this function may be called with null data. In that case,
  // just return.
  if (empty($element['#item'])) {
    return '';
  }
  $field = content_fields($element['#field_name']);
  $item = $element['#item'];

  // If there is no image on the database, use default.
  if (empty($item['fid']) && $field['use_default_file']) {
    $item = $field['default_file'];
  }
  if (empty($item['filepath']) && !empty($item['fid'])) {
    $item = array_merge($item, field_file_load($item['fid']));
  }
  if (empty($item['filepath'])) {
    return '';
  }

  // Check for remote filepath, if so return the raw path with protocol prefix
  if (strpos($item['filepath'], 'http://') === 0 || strpos($item['filepath'], 'https://' === 0)) {
    return l($file['filepath'], $item['filepath']);
  }
  else {
    return file_create_url(field_file_urlencode_path($item['filepath']));
  }
}