diff --git a/video_filter.module b/video_filter.module index 926e6b3..e4f7c35 100644 --- a/video_filter.module +++ b/video_filter.module @@ -24,6 +24,29 @@ function video_filter_filter_info() { 'video_filter_autoplay' => 1, 'video_filter_related' => 1, 'video_filter_html5' => 1, + 'video_filter_codecs' => array( + 'archive' => 'archive', + 'bliptv' => 'bliptv', + 'capped' => 'capped', + 'collegehumor' => 'collegehumor', + 'dailymotion' => 'dailymotion', + 'flickr_slideshows' => 'flickr_slideshows', + 'flickr_video' => 'flickr_video', + 'gametrailers' => 'gametrailers', + 'gamevideos' => 'gamevideos', + 'godtube' => 'godtube', + 'google' => 'google', + 'metacafe' => 'metacafe', + 'myspace' => 'myspace', + 'picasa_slideshows' => 'picasa_slideshows', + 'slideshare' => 'slideshare', + 'streamhoster' => 'streamhoster', + 'teachertube' => 'teachertube', + 'vimeo' => 'vimeo', + 'wistia' => 'wistia', + 'youtube' => 'youtube', + 'youtube_playlist' => 'youtube_playlist', + ), ), 'tips callback' => '_video_filter_tips', // See http://drupal.org/node/1061244. @@ -78,12 +101,32 @@ function _video_filter_settings($form, &$form_state, $filter, $format, $defaults ), ); + + $codecs_options = _video_filter_map_codecs_name(video_filter_get_codec_info()); + + $settings['video_filter_codecs'] = array( + '#type' => 'checkboxes', + '#title' => t('Codecs'), + '#description' => t('Choose which codecs will be available.'), + '#default_value' => isset($filter->settings['video_filter_codecs']) ? $filter->settings['video_filter_codecs'] : $defaults['video_filter_codecs'], + '#options' => $codecs_options, + ); + return $settings; } +function _video_filter_map_codecs_name($codecs) { + $codecs_map = array(); + foreach ($codecs as $codec_cod => $codec) { + $codecs_map[$codec_cod] = $codec['name']; + } + + return $codecs_map; +} + function _video_filter_tips($filter, $format, $long = FALSE) { if ($long) { - $codecs = video_filter_get_codec_info(); + $codecs = video_filter_get_codec_enabled($filter->settings['video_filter_codecs']); $supported = array(); $instructions = array(); foreach ($codecs as $codec) { @@ -133,7 +176,7 @@ function _video_filter_process($text, $filter, $format, $langcode, $cache, $cach } // Load all codecs. - $codecs = video_filter_get_codec_info(); + $codecs = video_filter_get_codec_enabled($filter->settings['video_filter_codecs']); // Find codec. foreach ($codecs as $codec_name => $codec) { @@ -271,6 +314,31 @@ function video_filter_get_codec_info() { return $codecs; } +function _video_filter_merge_format_codecs($filters_codecs){ + + $codecs = array_pop($filters_codecs); + + foreach ($filters_codecs as $format_name => $format_codecs){ + foreach ($format_codecs as $codec_name => $codec_value){ + if ($codec_value != 0 && $codecs[$codec_name] == 0){ + $codecs[$codec_name] = $codec_value; + } + } + } + + return $codecs; +} + + +function video_filter_get_codec_enabled($video_filter_codecs) { + $codecs = array_intersect_key( + video_filter_get_codec_info(), + array_filter($video_filter_codecs) + ); + + return $codecs; +} + /** * Function that outputs the element. * @@ -501,7 +569,7 @@ function _video_filter_form() { '#weight' => 97, ); - $text = '

' . t('Insert a 3rd party video from one of the following providers.') . '

'; + $text = '

' . t('Insert a 3rd party video from one of the following providers. Not all providers works in all text formats available.') . '

'; $text .= _video_filter_instructions(); $form['instructions']['text'] = array( @@ -604,7 +672,20 @@ function _video_filter_add_settings($editor) { * Parses Codec into instructions for WYSIWYG popup. */ function _video_filter_instructions() { - $codecs = video_filter_get_codec_info(); + // Get all codecs the user has permission to use in at least one text format. + global $user; + $formats = filter_formats($user); + $filters_codecs = array(); + foreach ($formats as $format) { + $format_filters = filter_list_format($format->format); + if (isset($format_filters['video_filter'])){ + $filters_codecs[$format->name] = $format_filters['video_filter']->settings['video_filter_codecs']; + } + } + $video_filter_codecs = _video_filter_merge_format_codecs($filters_codecs); + + $codecs = video_filter_get_codec_enabled($video_filter_codecs); + $output = '