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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
<?php
//$Id$
/**
* Implementation of hook_views_tables
*
* @return
* array - Enables support in the video module for views integration
* porting to Drupal 6
* @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
* @todo
**/
function video_views_tables() {
$tables['video'] = array(
'name' => 'video',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'vid'
),
'right' => array(
'field' => 'vid'
)
),
// Fields that can be inserted into a view
'fields' => array(
'play_counter' => array(
'name' => t('Video: Play count'),
'sortable' => true,
'help' => t('This will display the number of times this has been played.'),
),
'download_counter' => array(
'name' => t('Video: Download count'),
'sortable' => true,
'help' => t('This will display the number of times this has been downloaded.'),
),
'playtime_seconds' => array(
'name' => t('Video: Length'),
'handler' => 'video_views_handler_field_playtime_seconds',
'sortable' => true,
'help' => t('This will display the play length of the video.'),
),
'download_link' => array(
'name' => t('Video: Download link'),
'handler' => 'video_views_handler_field_download',
'notafield' => true,
'sortable' => false,
'help' => t('This will display a download link if the node allows it.'),
),
'play_link' => array(
'name' => t('Video: Play link'),
'handler' => 'video_views_handler_field_play',
'notafield' => true,
'sortable' => false,
'help' => t('This will display a play link if the node allows it.'),
),
'videox' => array(
'name' => t('Video: Width (x)'),
'sortable' => true,
'help' => t('This will display the width (x) of the video'),
),
'videoy' =>array(
'name' => t('Video: Height (y)'),
'sortable' => true,
'help' => t('This will display the height (y) of the video'),
),
),
'sorts' => array(
'play_counter' => array(
'name' => t('Video: Play count'),
'help' => t('Sort by the number of video plays.'),
),
'download_counter' => array(
'name' => t('Video: Download count'),
'help' => t('Sort by the number of video downloads.'),
),
'playtime_seconds' => array(
'name' => t('Video: Length'),
'help' => t('Sort by the video length.'),
)
)
);
// Add video_image support only if the video_image module is enabled
if (module_exists('video_image')) {
$tables['video']['fields']['video_image'] = array(
'name' => t('Video: Thumbnail'),
'notafield' => true,
'handler' => 'video_views_handler_field_video_image',
'sortable' => false,
'help' => t('This will display the thumbnail image for the video.'),
);
}
return $tables;
}
/**
* Provide a default view
*
* @return
array - of views
**/
function video_views_default_views() {
$views = array();
// recent video node activity view
$view = new stdClass();
$view->name = 'video_tracker';
$view->description = t('Shows all recent video activity (table format)');
$view->access = array ();
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = t('Recent video activity');
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = t('There is no recent video activity');
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'video/tracker';
$view->use_pager = TRUE;
$view->nodes_per_page = '20';
$view->sort = array ();
$view->argument = array ();
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => t('Title'),
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'changed',
'label' => t('Last Updated'),
'handler' => 'views_handler_field_date_small',
'sortable' => '1',
'defaultsort' => 'DESC',
),
array (
'tablename' => 'users',
'field' => 'name',
'label' => t('Author'),
),
array (
'tablename' => 'video',
'field' => 'video_image',
'label' => t('Preview / Play'),
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'video',
),
),
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->exposed_filter = array ();
$view->requires = array(node, users, video);
$views[$view->name] = $view;
return $views;
}
/**
* Handler to to render the "Download" link field
**/
function video_views_handler_field_download($fieldinfo, $fielddata, $value, $data) {
$nid = $data->nid;
return l(t('Download'), "node/$nid/download", array());
}
/**
* Handler to to render the "Play" link field
**/
function video_views_handler_field_play($fieldinfo, $fielddata, $value, $data) {
$nid = $data->nid;
return l(t('Play'), "node/$nid/play", array());
}
/**
* Handler to to render the correct playtime for the video in a field
**/
function video_views_handler_field_playtime_seconds($fieldinfo, $fielddata, $value, $data) {
$seconds = $value;
$hms = _video_sec2hms($seconds);
// Pad the minutes / seconds with a leading "0", if
// necessary
if ($hms['hours'] > 0) {
$hms['minutes'] = str_pad($hms['minutes'], 2, '0', STR_PAD_LEFT);
}
$hms['seconds'] = str_pad($hms['seconds'], 2, '0', STR_PAD_LEFT);
$out = '';
if ($hms['hours'] > 0) {
$out .= $hms['hours'].":";
}
$out .= $hms['minutes'].":".$hms['seconds'];
return t($out);
}
/**
* Handler to render the preview image associated with a video
**/
function video_views_handler_field_video_image($fieldinfo, $fielddata, $value, $data) {
$node = node_load($data->nid);
if($node->iid && $image = node_load($node->iid)) {
$output = theme('video_image_teaser', $image, $node);
}
return $output;
}
|