1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
<?php
/**
*
* @file
* Theme functions for the video module.
*
*/
function theme_video_thumbnails($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
$file = (array) $file;
// return $file['filepath'];
if (!is_file($file['filepath'])) {
return '<!-- File not found: ' . $file['filepath'] . ' -->';
}
if ($getsize) {
// Use cached width and height if available.
if (!empty($file['data']['width']) && !empty($file['data']['height'])) {
$attributes['width'] = $file['data']['width'];
$attributes['height'] = $file['data']['height'];
}
// Otherwise pull the width and height from the file.
elseif (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])) {
$attributes['width'] = $width;
$attributes['height'] = $height;
}
}
if (!empty($title)) {
$attributes['title'] = $title;
}
// Alt text should be added even if it is an empty string.
$attributes['alt'] = $alt;
// Add a timestamp to the URL to ensure it is immediately updated after editing.
$query_string = '';
if (isset($file['timestamp'])) {
$query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?';
$query_string = $query_character . $file['timestamp'];
}
$url = file_create_url($file['filepath']) . $query_string;
$attributes['src'] = $url;
$attributes = drupal_attributes($attributes);
return '<span></span><img ' . $attributes . ' />';
}
function theme_video_widget_preview($item) {
$output .= '<div class="image-preview">';
$output .= drupal_render($item['preview']);
$output .= '</div>';
return $item;
}
function theme_video_widget_video_thumb($item = NULL) {
return '<div class="video-thumb">' . theme('video_image', $item, '', '', '', FALSE) . '</div>';
}
/**
* @defgroup "Theme Callbacks"
* @{
* @see uploadfield_theme().
*/
function theme_video_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE, $imagecache = FALSE) {
$file = (array) $file;
//if this is imagecache skip this as the file might not be created yet
if (!$imagecache && !is_file($file['filepath'])) {
return '<!-- File not found: ' . str_replace("--", "-", $file['filepath']) . '" -->';
}
if ($getsize && $imagecache && ($image = image_get_info($file['filepath']))) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
} elseif ($getsize) {
// Use cached width and height if available.
if (!empty($file['data']['width']) && !empty($file['data']['height'])) {
$attributes['width'] = $file['data']['width'];
$attributes['height'] = $file['data']['height'];
}
// Otherwise pull the width and height from the file.
elseif (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])) {
$attributes['width'] = $width;
$attributes['height'] = $height;
}
}
if (!empty($title)) {
$attributes['title'] = $title;
}
// Alt text should be added even if it is an empty string.
$attributes['alt'] = $alt;
// Add a timestamp to the URL to ensure it is immediately updated after editing.
$query_string = '';
if (isset($file['timestamp'])) {
$query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?';
$query_string = $query_character . $file['timestamp'];
}
$url = file_create_url($file['filepath']) . $query_string;
$attributes['src'] = $url;
$attributes = drupal_attributes($attributes);
return '<img ' . $attributes . ' />';
}
/**
* Returns HTML for an video field widget.
*
* @param $variables
* An associative array containing:
* - element: A render element representing the image field widget.
*
* @ingroup themeable
*/
function theme_video_widget($variables) {
$element = $variables['element'];
$output = '';
$output .= '<div class="video-widget form-managed-file clearfix">';
if (isset($element['preview'])) {
$output .= '<div class="video-preview">';
$output .= drupal_render($element['preview']);
$output .= '</div>';
}
$output .= '<div class="video-widget-data">';
if ($element['fid']['#value'] != 0) {
$element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
$output .= '</div>';
return $output;
}
/**
* Returns HTML for an image using a specific image style.
*
* @param $variables
* An associative array containing:
* - style_name: The name of the style to be used to alter the original image.
* - path: The path of the image file relative to the Drupal files directory.
* This function does not work with images outside the files directory nor
* with remotely hosted images.
* - alt: The alternative text for text-based browsers.
* - title: The title text is displayed when the image is hovered in some
* popular browsers.
* - attributes: Associative array of attributes to be placed in the img tag.
* - getsize: If set to TRUE, the image's dimension are fetched and added as
* width/height attributes.
*
* @ingroup themeable
*/
function theme_video_thumb_style($variables) {
$style_name = $variables['style_name'];
$path = $variables['path'];
// theme_image() can only honor the $getsize parameter with local file paths.
// The derivative image is not created until it has been requested so the file
// may not yet exist, in this case we just fallback to the URL.
$style_path = image_style_path($style_name, $path);
if (!file_exists($style_path)) {
$style_path = image_style_url($style_name, $path);
}
$variables['path'] = $style_path;
return theme('image', $variables);
}
|