Mercurial > hg > rr-repo
comparison sites/all/modules/insert/includes/image.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 ImageField module. | |
6 */ | |
7 | |
8 /** | |
9 * Implementation of hook_insert_widgets(). | |
10 */ | |
11 function image_insert_widgets() { | |
12 return array( | |
13 'image_image' => array( | |
14 'element_type' => 'managed_file', | |
15 'wrapper' => '.image-widget', | |
16 'fields' => array( | |
17 'alt' => 'input[name$="[alt]"], textarea[name$="[alt]"]', | |
18 'title' => 'input[name$="[title]"], textarea[name$="[title]"]', | |
19 'description' => 'input[name$="[description]"], textarea[name$="[description]"]', | |
20 ), | |
21 ), | |
22 ); | |
23 } | |
24 | |
25 /** | |
26 * Implementation of hook_insert_styles(). | |
27 */ | |
28 function image_insert_styles() { | |
29 $image_styles = image_styles(); | |
30 $insert_styles = array(); | |
31 foreach ($image_styles as $style) { | |
32 $insert_styles['image_' . $style['name']] = array( | |
33 'label' => t($style['name']), | |
34 ); | |
35 } | |
36 return $insert_styles; | |
37 } | |
38 | |
39 /** | |
40 * Implementation of hook_insert_content(). | |
41 */ | |
42 function image_insert_content($item, $style, $widget) { | |
43 $style_name = preg_replace('/^image_/', '', $style['name']); | |
44 return theme(array('image_insert_image__' . str_replace('-', '_', $style_name), 'image_insert_image'), array('item' => $item, 'widget' => $widget, 'style_name' => $style_name)); | |
45 } | |
46 | |
47 /** | |
48 * Theme the content that will be inserted for Image styles. | |
49 */ | |
50 function template_preprocess_image_insert_image(&$vars) { | |
51 $vars['file'] = file_load($vars['item']['fid']); | |
52 | |
53 // Determine dimensions of the image after the image style transformations. | |
54 $image_info = @image_get_info($vars['file']->uri); | |
55 $vars['width'] = isset($image_info['width']) ? $image_info['width'] : NULL; | |
56 $vars['height'] = isset($image_info['height']) ? $image_info['height'] : NULL; | |
57 image_style_transform_dimensions($vars['style_name'], $vars); | |
58 | |
59 $vars['uri'] = image_style_path($vars['style_name'], $vars['file']->uri); | |
60 $absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL; | |
61 $vars['url'] = insert_create_url($vars['uri'], $absolute, variable_get('clean_url')); | |
62 | |
63 // http://drupal.org/node/1923336 | |
64 if (function_exists('image_style_path_token')) { | |
65 $token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($vars['style_name'], $vars['file']->uri)); | |
66 $vars['url'] .= (strpos($vars['url'], '?') !== FALSE ? '&' : '?') . drupal_http_build_query($token_query); | |
67 } | |
68 | |
69 $vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : ''; | |
70 } |