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