You are here

function insert_insert_content in Insert 7

Same name and namespace in other branches
  1. 6 includes/insert.inc \insert_insert_content()

Implementation of hook_insert_content().

File

includes/insert.inc, line 25
Insert support for generic files.

Code

function insert_insert_content($item, $style, $widget) {
  $style_name = $style['name'];
  if (empty($item['fid'])) {
    return '';
  }
  if ($style_name == 'auto') {
    $file = file_load($item['fid']);
    $info = @pathinfo($file->uri);
    $extension = isset($info['extension']) ? strtolower($info['extension']) : null;
    foreach (array_map(function ($value) {
      return variable_get($value, unserialize(INSERT_DEFAULT_CONFIG)[$value]);
    }, [
      'image' => 'insert_file_extensions_image',
      'audio' => 'insert_file_extensions_audio',
      'video' => 'insert_file_extensions_video',
    ]) as $fileType => $extensions) {
      if (in_array($extension, $extensions)) {
        $style_name = $fileType;
        break;
      }
    }
  }
  if ($style_name == 'image') {
    return theme('insert_image', array(
      'item' => $item,
      'widget' => $widget,
    ));
  }
  elseif ($style_name == 'icon_link') {
    return theme('insert_icon_link', array(
      'item' => $item,
      'widget' => $widget,
    ));
  }
  elseif ($style_name === 'video') {
    return theme('insert_video', array(
      'item' => $item,
      'widget' => $widget,
    ));
  }
  elseif ($style_name === 'audio') {
    return theme('insert_audio', array(
      'item' => $item,
      'widget' => $widget,
    ));
  }
  else {
    return theme('insert_link', array(
      'item' => $item,
      'widget' => $widget,
    ));
  }
}