From 10b8a26d749a372dc75cdea4a280b67ecc33a404 Mon Sep 17 00:00:00 2001 From: Fabio Varesano Date: Wed, 3 Jan 2007 17:46:19 +0000 Subject: Patch #75359 by jrbeeman (http://drupal.org/user/16734): Add Views module support --- INSTALL.txt | 16 ++++- video.module | 12 ++++ views_video.inc | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 views_video.inc diff --git a/INSTALL.txt b/INSTALL.txt index e328a58..91adf77 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -1,5 +1,12 @@ // $Id$ +REQUIREMENTS +------------------------------------ +Optional: + Views support requires the Views module to be activated. + video_image module require image module to be activated. + + INSTALL INSTRUCTIONS FOR VIDEO.MODULE ------------------------------------- @@ -9,6 +16,13 @@ INSTALL INSTRUCTIONS FOR VIDEO.MODULE - Activate optional plugin modules (called video_something) - Set access control as you like (administer->access control) - (optional) Activate video.module blocks (administer->blocks) +- (optional) Activate video views using views.module + * If you are upgrading from a previous version of the video module, + go to admin -> modules and choose "Save". This will flush the + views cache to ensure you can see the views. + * Go to admin -> views. You will see a default view supplied for + video. You can also create a new one by choosing "Add." In the + "Fields" section, you should see selections for "Video: (node info)". UPGRADING FROM DRUPAL 4.7 to CVS @@ -187,4 +201,4 @@ VIDEO UPDATE.PHP VERSION 6 custom_field_6 text NULL default NULL, serialized_data text NULL default NULL, PRIMARY KEY (vid) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */; \ No newline at end of file + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */; diff --git a/video.module b/video.module index c906261..2c066e8 100644 --- a/video.module +++ b/video.module @@ -132,6 +132,18 @@ function video_menu($may_cache) { return $items; } + +/** + * Implementation of hook_init() + * Currently just does a check for whether the views module exists and, + * if it does loads the video views module. + */ +function video_init() { + if (module_exist('views')) { + include(drupal_get_path('module', 'video') .'/views_video.inc'); + } +} + /** * Internal Drupal links hook * 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 @@ + '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 -- cgit v1.2.3