diff options
Diffstat (limited to 'views_video.inc')
-rw-r--r-- | views_video.inc | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/views_video.inc b/views_video.inc new file mode 100644 index 0000000..77bce9c --- /dev/null +++ b/views_video.inc @@ -0,0 +1,214 @@ +<?php + + +/** +* Implementation of hook_views_tables +* +* @return +* array - Enables support in the video module for views integration +**/ +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'), + ), + ), + ); + + // Add video_image support only if the video_image module is enabled + if (module_exist('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", NULL); +} + + +/** +* 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", NULL); +} + + +/** +* 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 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); + $output = theme_video_image_body($node); + return $output; +}
\ No newline at end of file |