You are here

function _messaging_htmlmail_file in Messaging 7

Helper function to extract local files

Parameters

$url a URL to a file:

Return value

an absolute :

3 calls to _messaging_htmlmail_file()
Messaging_HTML_MailSystem::mimemail_extract_files in messaging_htmlmail/messaging_htmlmail.inc
Extracts links to local images from html documents.
Messaging_HTML_MailSystem::mimemail_html_body in messaging_htmlmail/messaging_htmlmail.inc
Generate a multipart message body with a text alternative for some html text
_messaging_htmlmail_replace_files in messaging_htmlmail/messaging_htmlmail.inc
Callback for preg_replace_callback()

File

messaging_htmlmail/messaging_htmlmail.inc, line 435
Drupal Messaging Framework - Send_Method class file

Code

function _messaging_htmlmail_file($url = NULL, $name = '', $type = '', $disposition = 'related') {
  static $files = array();
  static $filenames = array();
  if ($url) {
    $url = _messaging_htmlmail_url($url, 'TRUE');

    // If the $url is absolute, we're done here.
    if (strpos($url, '://') !== FALSE || preg_match('!mailto:!', $url)) {
      return $url;
    }
    else {

      // Download method is private, and the $url needs conversion.
      if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && strpos($url, 'system/files/') !== FALSE) {
        $file = file_create_path(drupal_substr($url, strpos($url, 'system/files/') + drupal_strlen('system/files/')));
      }
      else {
        $file = $url;
      }
    }
  }
  if (isset($file) && @file_exists($file)) {

    // Prevent duplicate items.
    if (isset($filenames[$file])) {
      return 'cid:' . $filenames[$file];
    }
    $content_id = md5($file) . '@' . $_SERVER['HTTP_HOST'];
    if (!$name) {
      $name = drupal_substr($file, strrpos($file, '/') + 1);
    }
    $new_file = array(
      'name' => $name,
      'file' => $file,
      'Content-ID' => $content_id,
      'Content-Disposition' => $disposition,
    );
    $new_file['Content-Type'] = !empty($name) ? file_get_mimetype($name) : file_get_mimetype($file);
    $files[] = $new_file;
    $filenames[$file] = $content_id;
    return 'cid:' . $content_id;
  }
  elseif ($url) {
    return $url;
  }
  $ret = $files;
  $files = array();
  $filenames = array();
  return $ret;
}