You are here

download_file.inc in DownloadFile 6

Insert support for DownloadFile module.

File

download_file.inc
View source
<?php

/**
 * @file
 * Insert support for DownloadFile module.
 */

/**
 * Implementation of hook_insert_styles().
 */
function download_file_insert_styles() {
  $insert_styles = array(
    'direct_download' => array(
      'label' => t('Direct download file'),
      'weight' => 40,
    ),
    'direct_download_icon' => array(
      'label' => t('Direct download file with the type icon'),
      'weight' => 50,
    ),
    'direct_download_accessible' => array(
      'label' => t('Direct download file accessible'),
      'weight' => 60,
    ),
    'direct_download_accessible_icon' => array(
      'label' => t('Direct download file accessible with the type icon'),
      'weight' => 70,
    ),
  );
  return $insert_styles;
}

/**
 * Implementation of hook_insert_content().
 */
function download_file_insert_content($item, $style, $widget) {
  $style_name = $style['name'];
  switch ($style_name) {
    case 'direct_download':
      return theme('download_file_insert_direct_download_item', $item, $widget);
    case 'direct_download_icon':
      return theme('download_file_insert_direct_download_icon_item', $item, $widget);
    case 'direct_download_accessible':
      return theme('download_file_insert_direct_download_item_accessible', $item, $widget);
    case 'direct_download_accessible_icon':
      return theme('download_file_insert_direct_download_icon_item_accessible', $item, $widget);
    default:
      return theme('insert_link', $item, $widget);
  }
}

/**
 * Theme function for the 'direct_download' file via the Insert module.
 *
 * @param $file
 *   File to format.
 * @param $widget
 *   Widget for Insert module.
 * @return
 *   A string containing the HTML ouput.
 */
function theme_download_file_insert_direct_download_item($file, $widget) {

  // Views may call this function with a NULL value, return an empty string.
  if (empty($file['fid'])) {
    return '';
  }
  $item = array(
    'url' => download_file_url($file['fid']),
  );

  // Use the description as the link text if available.
  if (empty($file['data']['description'])) {
    $item['link_text'] = $file['filename'];
  }
  else {
    $item['link_text'] = $file['data']['description'];
    $item['title'] = $file['filename'];
  }
  return theme('download_file_insert_link', $item, $widget);
}

/**
 * Theme function for the 'direct_download_icon' file via the Insert module.
 *
 * @param $file
 *   File to format.
 * @param $widget
 *   Widget for Insert module.
 * @return
 *   A string containing the HTML ouput.
 */
function theme_download_file_insert_direct_download_icon_item($file, $widget) {

  // Views may call this function with a NULL value, return an empty string.
  if (empty($file['fid'])) {
    return '';
  }
  $item = array(
    'url' => download_file_url($file['fid']),
    'icon' => theme('filefield_icon', $file),
  );

  // Use the description as the link text if available.
  if (empty($file['data']['description'])) {
    $item['link_text'] = $file['filename'];
  }
  else {
    $item['link_text'] = $file['data']['description'];
    $item['title'] = $file['filename'];
  }
  return theme('download_file_insert_link', $item, $widget);
}

/**
 * Theme function for the 'direct_download_accessible' file via the Insert 
 * module.
 *
 * @param $file
 *   File to format.
 * @param $widget
 *   Widget for Insert module.
 * @return
 *   A string containing the HTML ouput.
 */
function theme_download_file_insert_direct_download_item_accessible($file, $widget) {

  // Views may call this function with a NULL value, return an empty string.
  if (empty($file['fid'])) {
    return '';
  }
  $item = array(
    'url' => download_file_url($file['fid']),
  );
  $accessibility = theme('download_file_detail_accessible', $file);

  // Use the description as the link text if available.
  if (empty($file['data']['description'])) {
    $item['link_text'] = $file['filename'];
  }
  else {
    $item['link_text'] = $file['data']['description'];
    $item['title'] = $file['filename'];
  }
  $item['link_text'] .= ' ' . $accessibility;
  return theme('download_file_insert_link', $item, $widget);
}

/**
 * Theme function for the 'direct_download_accessible_icon' file via the 
 * Insert module.
 *
 * @param $file
 *   File to format.
 * @param $widget
 *   Widget for Insert module.
 * @return
 *   A string containing the HTML ouput.
 */
function theme_download_file_insert_direct_download_icon_item_accessible($file, $widget) {

  // Views may call this function with a NULL value, return an empty string.
  if (empty($file['fid'])) {
    return '';
  }
  $item = array(
    'url' => download_file_url($file['fid']),
    'icon' => theme('filefield_icon', $file),
  );
  $accessibility = theme('download_file_detail_accessible', $file);

  // Use the description as the link text if available.
  if (empty($file['data']['description'])) {
    $item['link_text'] = $file['filename'];
  }
  else {
    $item['link_text'] = $file['data']['description'];
    $item['title'] = $file['filename'];
  }
  $item['link_text'] .= ' ' . $accessibility;
  return theme('download_file_insert_link', $item, $widget);
}

/**
 * Preprocess variables for the download-file-insert-link.tpl.php file.
 */
function template_preprocess_download_file_insert_link(&$vars) {
  $vars['icon'] = $vars['item']['icon'];
  $vars['url'] = $vars['item']['url'];
  $vars['class'] = '';
  $vars['title'] = '';
  $vars['name'] = $vars['item']['link_text'];
  if (!empty($vars['widget']['insert_class'])) {
    $vars['class'] = $vars['widget']['insert_class'];
  }
  if (!empty($vars['title'])) {
    $vars['title'] = $vars['title'];
  }
}

Functions

Namesort descending Description
download_file_insert_content Implementation of hook_insert_content().
download_file_insert_styles Implementation of hook_insert_styles().
template_preprocess_download_file_insert_link Preprocess variables for the download-file-insert-link.tpl.php file.
theme_download_file_insert_direct_download_icon_item Theme function for the 'direct_download_icon' file via the Insert module.
theme_download_file_insert_direct_download_icon_item_accessible Theme function for the 'direct_download_accessible_icon' file via the Insert module.
theme_download_file_insert_direct_download_item Theme function for the 'direct_download' file via the Insert module.
theme_download_file_insert_direct_download_item_accessible Theme function for the 'direct_download_accessible' file via the Insert module.