insert.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Insert support for generic files.
  5. */
  6. /**
  7. * Implementation of hook_insert_styles().
  8. */
  9. function insert_insert_styles() {
  10. $insert_styles = array();
  11. $insert_styles['auto'] = array('label' => t('Automatic'), 'weight' => -20);
  12. $insert_styles['link'] = array('label' => t('Link to file'), 'weight' => -12);
  13. $insert_styles['icon_link'] = array('label' => t('Link to file (with icon)'), 'weight' => -11);
  14. $insert_styles['image'] = array('label' => t('Original image'), 'weight' => -10);
  15. return $insert_styles;
  16. }
  17. /**
  18. * Implementation of hook_insert_content().
  19. */
  20. function insert_insert_content($item, $style, $widget) {
  21. $style_name = $style['name'];
  22. if (empty($item['fid'])) {
  23. return '';
  24. }
  25. if ($style_name == 'auto') {
  26. $file = file_load($item['fid']);
  27. $info = @pathinfo($file->uri);
  28. if (in_array(strtolower($info['extension']), array('png', 'jpg', 'jpeg', 'gif'))) {
  29. $style_name = 'image';
  30. }
  31. }
  32. if ($style_name == 'image') {
  33. return theme('insert_image', array('item' => $item, 'widget' => $widget));
  34. }
  35. if ($style_name == 'icon_link') {
  36. return theme('insert_icon_link', array('item' => $item, 'widget' => $widget));
  37. }
  38. else {
  39. return theme('insert_link', array('item' => $item, 'widget' => $widget));
  40. }
  41. }
  42. /**
  43. * Preprocess variables for the insert-image.tpl.php file.
  44. */
  45. function template_preprocess_insert_image(&$vars) {
  46. $vars['file'] = file_load($vars['item']['fid']);
  47. $absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
  48. $vars['url'] = insert_create_url($vars['file']->uri, $absolute);
  49. $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
  50. $image_info = @image_get_info($vars['file']->uri);
  51. $vars['width'] = isset($image_info['width']) ? $image_info['width'] : '';
  52. $vars['height'] = isset($image_info['height']) ? $image_info['height'] : '';
  53. }
  54. /**
  55. * Preprocess variables for the insert-link.tpl.php file.
  56. */
  57. function template_preprocess_insert_link(&$vars) {
  58. $vars['file'] = file_load($vars['item']['fid']);
  59. $absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
  60. $vars['url'] = insert_create_url($vars['file']->uri, $absolute);
  61. $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
  62. $vars['name'] = $vars['file']->filename;
  63. }
  64. /**
  65. * Preprocess variables for the insert-icon-link.tpl.php file.
  66. */
  67. function template_preprocess_insert_icon_link(&$vars) {
  68. $vars['file'] = file_load($vars['item']['fid']);
  69. $absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
  70. $vars['url'] = insert_create_url($vars['file']->uri, $absolute);
  71. $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
  72. $vars['name'] = $vars['file']->filename;
  73. $vars['type'] = $vars['file']->filemime .'; length='. $vars['file']->filesize;
  74. $vars['icon'] = theme('file_icon', array('file' => $vars['file']));
  75. }