From b66f50d2ce11d0cc8bb53af94ad86278d3fe8e51 Mon Sep 17 00:00:00 2001 From: glen201 Date: Fri, 31 Jul 2009 02:01:53 +0000 Subject: #486064: by RobertOak "no video fields in views" Fixed, added Views 2 support .MPEG/MPG defaulted to play with Windows Media --- includes/common.inc | 17 +- includes/video.views.inc | 135 ++++++++++++ includes/video.views_default.inc | 233 +++++++++++++++++++++ includes/video_views_handler_field_download.inc | 37 ++++ includes/video_views_handler_field_image.inc | 74 +++++++ includes/video_views_handler_field_play.inc | 31 +++ .../video_views_handler_field_playtime_seconds.inc | 76 +++++++ po/video-module.pot | 92 ++++---- types/video_upload/video_upload.module | 3 +- video.module | 32 ++- views_video.inc | 232 -------------------- 11 files changed, 678 insertions(+), 284 deletions(-) create mode 100644 includes/video.views.inc create mode 100644 includes/video.views_default.inc create mode 100644 includes/video_views_handler_field_download.inc create mode 100644 includes/video_views_handler_field_image.inc create mode 100644 includes/video_views_handler_field_play.inc create mode 100644 includes/video_views_handler_field_playtime_seconds.inc delete mode 100644 views_video.inc diff --git a/includes/common.inc b/includes/common.inc index eeca72a..c70a7a5 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -8,13 +8,9 @@ * porting to Drupal 6 * @author Heshan Wanigasooriya * @author Glen Marianko Twitter@demoforum - * @todo + * @todo Configure default players by video filetype (user configurable?) */ - - - - /** * Get the object for the suitable player for the parameter resource */ @@ -23,10 +19,9 @@ function _video_common_get_player($node) { case 'divx': return theme('video_play_divx', $node); case 'mov': - case 'mp4': case '3gp': case '3g2': - case 'mpg': + case 'mp4': return theme('video_play_quicktime', $node); case 'rm': return theme('video_play_realmedia', $node); @@ -40,7 +35,9 @@ function _video_common_get_player($node) { case 'asf': case 'wmv': case 'avi': - return theme('video_play_windowsmedia', $node); + case 'mpg': + case 'mpeg': + return theme('video_play_windowsmedia', $node); case 'ogg': return theme('video_play_ogg_theora', $node); case 'youtube': @@ -246,9 +243,11 @@ data="'. $url .'"> ' . "\n"; // params will be passed to both IE or not IE browsers + //GMM: kioskmode enabled so users don't bypass download security video through player $output .= ' - ' . "\n" + + ' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; // only one needed becouse only one opening tag has been parsed by browsers diff --git a/includes/video.views.inc b/includes/video.views.inc new file mode 100644 index 0000000..1f0682e --- /dev/null +++ b/includes/video.views.inc @@ -0,0 +1,135 @@ + +* @todo +**/ + +function video_views_data() { + // Basic table information. + // ---------------------------------------------------------------- + // views table + $data['video']['table']['group'] = t('Video'); + $data['video']['table']['join'] = array( + // ...to the node table + 'node' => array( + 'left_field' => 'nid', + 'field' => 'vid', + ), + ); + + // Fields that can be inserted into a view + // play counter + $data['video']['play_counter'] = array( + 'title' => t('Play count'), + 'help' => t('This will display the number of times this has been played.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'title' => t('Play count'), + 'help' => t('Sort by the number of video plays.'), + 'handler' => 'views_handler_sort', + ), + ); + $data['video']['download_counter'] = array( + 'title' => t('Download count'), + 'help' => t('This will display the number of times this has been downloaded.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'title' => t('Download count'), + 'help' => t('Sort by the number of video downloads.'), + 'handler' => 'views_handler_sort', + ), + ); + $data['video']['videox'] = array( + 'title' => t('Width (x)'), + 'help' => t('This will display the width (x) of the video'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['video']['videoy'] = array( + 'title' => t('Height (y)'), + 'help' => t('This will display the height (y) of the video'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['video']['playtime_seconds'] = array( + 'title' => t('Length'), + 'help' => t('This will display the play length of the video.'), + 'field' => array( + 'handler' => 'video_views_handler_field_playtime_seconds', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'title' => t('Length'), + 'help' => t('Sort by the video length.'), + 'handler' => 'views_handler_sort', + ), + ); + $data['video']['download_link'] = array( + 'real field' => 'vidfile', + 'title' => t('Download link'), + 'help' => t('This will display a download link if the node allows it.'), + 'field' => array( + 'handler' => 'video_views_handler_field_download', + 'click sortable' => FALSE, + ) + ); + $data['video']['play_link'] = array( + 'real field' => 'vidfile', + 'title' => t('Play link'), + 'help' => t('This will display a play link if the node allows it.'), + 'field' => array( + 'handler' => 'video_views_handler_field_play', + 'click sortable' => FALSE, + ), + ); + + // Add video_image support only if the video_image module is enabled + if (module_exists('video_image')) { + $data['video']['video_image'] = array( + 'real field' => 'vidfile', + 'title' => t('Thumbnail'), + 'help' => t('This will display the thumbnail image for the video.'), + 'field' => array( + 'handler' => 'video_views_handler_field_image', + 'click sortable' => FALSE, + ), + ); + } + return $data; +} diff --git a/includes/video.views_default.inc b/includes/video.views_default.inc new file mode 100644 index 0000000..271738e --- /dev/null +++ b/includes/video.views_default.inc @@ -0,0 +1,233 @@ + +* @todo +**/ + +/** +* Provide a default view +* +* @return + array - of views +**/ +function video_views_default_views() { + $views = array(); + + // view definition (Views 2) + $view = new view; + $view->name = 'video_tracker'; + $view->description = 'Shows all recent video activity (table format)'; + $view->tag = ''; + $view->view_php = ''; + $view->base_table = 'node'; + $view->is_cacheable = FALSE; + $view->api_version = 2; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => 'Title', + 'link_to_node' => TRUE, + ), + 'changed' => array( + 'id' => 'changed', + 'table' => 'node', + 'field' => 'changed', + 'label' => 'Last Updated', + 'date_format' => 'small', + ), + 'name' => array( + 'id' => 'name', + 'table' => 'users', + 'field' => 'name', + 'label' => 'Author', + ), + 'playtime_seconds' => array( + 'label' => 'Play time', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'strip_tags' => 0, + 'html' => 0, + ), + 'exclude' => 0, + 'id' => 'playtime_seconds', + 'table' => 'video', + 'field' => 'playtime_seconds', + 'relationship' => 'none', + ), + 'video_image' => array( + 'id' => 'video_image', + 'table' => 'video', + 'field' => 'video_image', + 'label' => 'Preview / Play', + ), + )); + $handler->override_option('sorts', array( + 'changed' => array( + 'order' => 'ASC', + 'granularity' => 'second', + 'id' => 'changed', + 'table' => 'node', + 'field' => 'changed', + 'relationship' => 'none', + ), + )); + $handler->override_option('filters', array( + 'type' => array( + 'id' => 'type', + 'table' => 'node', + 'field' => 'type', + 'operator' => 'in', + 'value' => array( + '0' => 'video', + ), + ), + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'value' => '1', + ), + )); + $handler->override_option('access', array( + 'type' => 'none', + 'role' => array(), + 'perm' => '', + )); + $handler->override_option('cache', array( + 'type' => 'none', + )); + $handler->override_option('title', 'Recent video activity'); + $handler->override_option('header_format', '1'); + $handler->override_option('footer_format', '1'); + $handler->override_option('empty', 'There is no recent video activity'); + $handler->override_option('empty_format', '1'); + $handler->override_option('items_per_page', '20'); + $handler->override_option('use_pager', TRUE); + $handler->override_option('style_plugin', 'table'); + $handler->override_option('style_options', array( + 'columns' => array(), + 'default' => 'changed', + 'info' => array( + 'title' => array( + 'sortable' => TRUE, + ), + 'changed' => array( + 'sortable' => TRUE, + ), + ), + 'override' => FALSE, + 'order' => 'asc', + )); + $handler = $view->new_display('page', 'Page', 'page_1'); + $handler->override_option('path', 'video/tracker'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + )); + $handler = $view->new_display('block', 'Block', 'block_1'); + $handler->override_option('fields', array( + 'title' => array( + 'label' => '', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'strip_tags' => 0, + 'html' => 0, + ), + 'link_to_node' => 1, + 'exclude' => 0, + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'override' => array( + 'button' => 'Use default', + ), + 'relationship' => 'none', + ), + 'video_image' => array( + 'label' => '', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'strip_tags' => 0, + 'html' => 0, + ), + 'exclude' => 0, + 'id' => 'video_image', + 'table' => 'video', + 'field' => 'video_image', + 'override' => array( + 'button' => 'Use default', + ), + 'relationship' => 'none', + ), + )); + $handler->override_option('use_ajax', TRUE); + $handler->override_option('items_per_page', 1); + $handler->override_option('use_pager', 'mini'); + $handler->override_option('style_plugin', 'grid'); + $handler->override_option('style_options', array( + 'grouping' => '', + 'columns' => '1', + 'alignment' => 'horizontal', + )); + $handler->override_option('block_description', 'Video Tracker'); + $handler->override_option('block_caching', -1); + + // recent video node activity view + $views[$view->name] = $view; + return $views; +} + diff --git a/includes/video_views_handler_field_download.inc b/includes/video_views_handler_field_download.inc new file mode 100644 index 0000000..c01333e --- /dev/null +++ b/includes/video_views_handler_field_download.inc @@ -0,0 +1,37 @@ + + * @todo +**/ + +/** + * Field handler to display the play length of the video. + * + * @ingroup views_field_handlers + */ +class video_views_handler_field_download extends views_handler_field { + /** + * Render field output to the browser. + */ + function render($values) { + return _video_views_handler_field_download($values); + } +} +/** +* Handler to to return the correct download link for the video in a field +**/ +function _video_views_handler_field_download($values) { + /* $str = NULL; + foreach($values as $key => $value) { + $str .= $key .'
'; + } + return $str; */ + if($values->node_type && $values->node_type != 'video') return NULL; + return l(t('Download'), "node/$values->nid/download", array()); +} + diff --git a/includes/video_views_handler_field_image.inc b/includes/video_views_handler_field_image.inc new file mode 100644 index 0000000..fbbe905 --- /dev/null +++ b/includes/video_views_handler_field_image.inc @@ -0,0 +1,74 @@ + + * @todo +**/ + +/** + * Field handler to display the video preview thumbnail + * + * @ingroup views_field_handlers + */ +class video_views_handler_field_image extends views_handler_field { + /** + * Define options available for this field. + */ + function option_definition() { + $options = parent::option_definition(); + $options['img_type'] = array('default' => 'thumbnail'); + $options['disp_link'] = array('default' => TRUE); + return $options; + } + + /** + * Build option configuration form. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['img_type'] = array( + '#title' => t('Show image as'), + '#type' => 'select', + '#options' => array( + 'thumbnail' => t('Thumbnail'), + 'preview' => t('Preview'), + ), + '#default_value' => $this->options['img_type'], + ); + $form['disp_link'] = array( + '#title' => t('Link image to video'), + '#type' => 'checkbox', + '#default_value' => $this->options['disp_link'], + ); + + } +/** + * Render field output to the browser. + */ + function render($values) { + return _video_views_handler_field_image($values, $this->options['img_type'], $this->options['disp_link']); + } +} +/** +* Handler to render the preview image associated with a video +**/ +function _video_views_handler_field_image($values, $image_type, $linked) { + if($values->node_type && $values->node_type != 'video') return NULL; + $node = node_load($values->nid); + $output = NULL; + if($node->iid && $image = node_load($node->iid)) { + $image_html = NULL; + if($image != NULL && $image->type == 'image') { + $image_html = image_display($image, $image_type, array('class' => 'video_image_teaser')); + //Create a link with an image in it. + $output .= ($linked ? l($image_html, "node/$values->nid", array('html' => TRUE)) : $image_html); + $output .= '
'; + } + } + return $output; +} diff --git a/includes/video_views_handler_field_play.inc b/includes/video_views_handler_field_play.inc new file mode 100644 index 0000000..1eac89e --- /dev/null +++ b/includes/video_views_handler_field_play.inc @@ -0,0 +1,31 @@ + + * @todo +**/ + +/** + * Field handler to display the play length of the video. + * + * @ingroup views_field_handlers + */ +class video_views_handler_field_play extends views_handler_field { + /** + * Render field output to the browser. + */ + function render($values) { + return _video_views_handler_field_play($values); + } +} +/** +* Handler to to render the "Play" link field +**/ +function _video_views_handler_field_play($values) { + if($values->node_type && $values->node_type != 'video') return NULL; + return l(t('Play'), "node/$values->nid/play", array()); +} diff --git a/includes/video_views_handler_field_playtime_seconds.inc b/includes/video_views_handler_field_playtime_seconds.inc new file mode 100644 index 0000000..c0efc93 --- /dev/null +++ b/includes/video_views_handler_field_playtime_seconds.inc @@ -0,0 +1,76 @@ + + * @todo +**/ + +/** + * Field handler to display the play length of the video. + * + * @ingroup views_field_handlers + */ +class video_views_handler_field_playtime_seconds extends views_handler_field { + /** + * Define options available for this field. + */ + function option_definition() { + $options = parent::option_definition(); + $options['time_type'] = array('default' => 'hms'); + return $options; + } + + /** + * Build option configuration form. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['time_type'] = array( + '#title' => t('Show playtime as'), + '#type' => 'select', + '#options' => array( + 'hms' => t('Hour:min:sec'), + 'sec' => t('Seconds'), + ), + '#default_value' => $this->options['time_type'], + ); + } + /** + * Render field output to the browser. + */ + function render($values) { + return _video_playtime_seconds($values, $this->options['time_type']); + } +} +/** +* Handler to to render the correct playtime for the video in a field +**/ +function _video_playtime_seconds($values, $type) { + if($values->node_type && $values->node_type != 'video') return NULL; + switch ($type) { + case 'hms': + $hms = _video_sec2hms($values->video_playtime_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 $out; + case 'sec': + default: + return $values->video_playtime_seconds; + } +} diff --git a/po/video-module.pot b/po/video-module.pot index 2f7071d..136c95d 100644 --- a/po/video-module.pot +++ b/po/video-module.pot @@ -27,106 +27,126 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" -#: views_video.inc:26 -msgid "Video: Play count" +#: video.views.inc:26 +msgid "Play count" msgstr "" -#: views_video.inc:28 +#: video.views.inc:28 msgid "This will display the number of times this has been played." msgstr "" -#: views_video.inc:31 -msgid "Video: Download count" +#: video.views.inc:31 +msgid "Download count" msgstr "" -#: views_video.inc:33 +#: video.views.inc:33 msgid "This will display the number of times this has been downloaded." msgstr "" -#: views_video.inc:36 -msgid "Video: Length" +#: video.views.inc:36 +msgid "Length" msgstr "" -#: views_video.inc:39 +#: video.views.inc:39 msgid "This will display the play length of the video." msgstr "" -#: views_video.inc:42 -msgid "Video: Download link" +#: video.views.inc:42 +msgid "Download link" msgstr "" -#: views_video.inc:46 +#: video.views.inc:46 msgid "This will display a download link if the node allows it." msgstr "" -#: views_video.inc:49 -msgid "Video: Play link" +#: video.views.inc:49 +msgid "Play link" msgstr "" -#: views_video.inc:53 +#: video.views.inc:53 msgid "This will display a play link if the node allows it." msgstr "" -#: views_video.inc:56 -msgid "Video: Width (x)" +#: video.views.inc:56 +msgid "Width (x)" msgstr "" -#: views_video.inc:58 +#: video.views.inc:58 msgid "This will display the width (x) of the video" msgstr "" -#: views_video.inc:61 -msgid "Video: Height (y)" +#: video.views.inc:61 +msgid "Height (y)" msgstr "" -#: views_video.inc:63 +#: video.views.inc:63 msgid "This will display the height (y) of the video" msgstr "" -#: views_video.inc:71 -msgid "Video: Thumbnail" +#: video.views.inc:71 video_views_handler_field_image.inc:38 +msgid "Thumbnail" msgstr "" -#: views_video.inc:75 +#: video.views.inc:75 msgid "This will display the thumbnail image for the video." msgstr "" -#: views_video.inc:95 +#: video.views.inc:95 msgid "Shows all recent video activity (table format)" msgstr "" -#: views_video.inc:99 +#: video.views.inc:99 msgid "Recent video activity" msgstr "" -#: views_video.inc:104 +#: video.views.inc:104 msgid "There is no recent video activity" msgstr "" -#: views_video.inc:116 video.module:461 +#: video.views.inc:116 video.module:461 msgid "Title" msgstr "" -#: views_video.inc:123 +#: video.views.inc:123 msgid "Last Updated" msgstr "" -#: views_video.inc:131 +#: video.views.inc:131 msgid "Author" msgstr "" -#: views_video.inc:136 +#: video.views.inc:136 msgid "Preview / Play" msgstr "" -#: views_video.inc:170 +#: video.views.inc:170 msgid "Download" msgstr "" -#: views_video.inc:179 +#: video.views.inc:179 msgid "Play" msgstr "" +#: video_views_handler_field_image.inc:35 +msgid "Show image as" +msgstr "" + +#: video_views_handler_field_image.inc:39 +msgid "Preview" +msgstr "" + +#: video_views_handler_field_image.inc:44 +msgid "Link image to video" +msgstr "" + +#: video_views_handler_field_playtime_seconds.inc:34 +msgid "Show playtime as" +msgstr "" + +#: video_views_handler_field_playtime_seconds.inc:37 +msgid "Hour:min:sec" +msgstr "" + #: video.module:30 msgid "The video module (4.7 or with backport patch to 4.6) allows users to post video content to their site. The emergence of portable phones with video capture capabilities has made video capture ubiquitous. Video logging, or vlogging as a medium for personal video broadcasting has proven to be popular and is following the blogging, and podcasting phenomena's. Videos are useful for creative collaboration among community members. If community members can not meet in person videos of meetings are valuable for enhancing the interaction between community members." msgstr "" @@ -515,7 +535,7 @@ msgstr "" msgid "Integer of minutes." msgstr "" -#: video.module:534 +#: video.module:534 video_views_handler_field_playtime_seconds.inc:38 msgid "Seconds" msgstr "" @@ -675,11 +695,11 @@ msgstr "" msgid "http://support.mozilla.com/en-US/kb/Using+the+Windows+Media+Player+plugin+with+Firefox" msgstr "" -#: common.inc:0 +#: common.inc:367 msgid "Link to Firefox Plug-in" msgstr "" -#: common.inc:0 +#: common.inc:367 msgid "Download the plug-in for Firefox" msgstr "" diff --git a/types/video_upload/video_upload.module b/types/video_upload/video_upload.module index 5ad1a83..004b7fe 100644 --- a/types/video_upload/video_upload.module +++ b/types/video_upload/video_upload.module @@ -400,7 +400,7 @@ function _video_upload_presave(&$node) { $file_field = 'video_upload_file'; } - // get extention array + // get extension array $extensions = explode(",",variable_get('video_upload_allowed_extensions', 'mov,flv,wmv')); $validators = array( @@ -409,7 +409,6 @@ function _video_upload_presave(&$node) { // TODO : add file size validation // 'file_validate_size' => array($limits['file_size'], $limits['user_size']), - //GMM: Fix hard-coded allowed extensions if (count($_POST) && $file = file_save_upload($file_field , array('file_validate_extensions' => array(implode(" ",$extensions))))) { // a file has been uploaded $node->new_video_upload_file = $file; diff --git a/video.module b/video.module index dd0dd8e..3dc7f0d 100644 --- a/video.module +++ b/video.module @@ -5,15 +5,37 @@ * * @author Heshan Wanigasooriya * + * @author Glen Marianko Twitter@demoforum * @todo */ -/** - * Let's include views logic if views module is enabled -*/ -if (module_exists('views')) { - module_load_include('inc', 'video', 'views_video'); + +/** GMM: Views 2 + * Implementation of hook_views_api() + */ +function video_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'video').'/includes', + ); } +/** + * Implementation of hook_views_handlers() + */ +function video_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'video').'/includes', + ), + 'handlers' => array( + 'video_views_handler_field_playtime_seconds' => array('parent' => 'views_handler_field'), + 'video_views_handler_field_download' => array('parent' => 'views_handler_field'), + 'video_views_handler_field_play' => array('parent' => 'views_handler_field'), + 'video_views_handler_field_image' => array('parent' => 'views_handler_field'), + + ), + ); +} /******************************************************************** * General Hooks ********************************************************************/ diff --git a/views_video.inc b/views_video.inc deleted file mode 100644 index f3f9dc8..0000000 --- a/views_video.inc +++ /dev/null @@ -1,232 +0,0 @@ - -* @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; -} -- cgit v1.2.3