diff --git a/CHANGELOG.txt b/CHANGELOG.txt deleted file mode 100644 index 9627dc1..0000000 --- a/CHANGELOG.txt +++ /dev/null @@ -1,4 +0,0 @@ - -CHANGELOG for Media: Archive - -by aaron: Add provider file for archive.org videos. diff --git a/MediaArchiveStreamWrapper.inc b/MediaArchiveStreamWrapper.inc deleted file mode 100755 index 1a8cbe2..0000000 --- a/MediaArchiveStreamWrapper.inc +++ /dev/null @@ -1,39 +0,0 @@ -get_parameters(); - return 'http://www.archive.org/download/'. check_plain($parts['v']) .'/' . check_plain($parts['v']) .'.thumbs/' . check_plain($parts['org']) .'_000001.jpg'; - - } - - function getLocalThumbnailPath() { - $parts = $this->get_parameters(); - $local_path = 'public://media-archive/' . check_plain($parts['v']) . '.jpg'; - if (!file_exists($local_path)) { - $dirname = drupal_dirname($local_path); - file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - @copy($this->getOriginalThumbnailPath(), $local_path); - } - return $local_path; - } -} diff --git a/README.txt b/README.txt old mode 100755 new mode 100644 diff --git a/css/media_archive.css b/css/media_archive.css deleted file mode 100755 index 37c43c2..0000000 --- a/css/media_archive.css +++ /dev/null @@ -1,21 +0,0 @@ - -.media-archive-preview-wrapper { - max-width: 100%; - min-height: 50px; - position: relative; -} - -.media-archive-preview-wrapper object, -.media-archive-preview-wrapper iframe { - max-width: 100%; - position: relative; -} - -.media-archive-preview-wrapper .js-fallback { - left: 0; - margin-top: -0.5em; - position: absolute; - right: 0; - text-align: center; - top: 50%; -} diff --git a/includes/MediaArchiveStreamWrapper.inc b/includes/MediaArchiveStreamWrapper.inc new file mode 100644 index 0000000..3390cc7 --- /dev/null +++ b/includes/MediaArchiveStreamWrapper.inc @@ -0,0 +1,76 @@ +get_parameters()) { + return $this->base_url . '?' . http_build_query($parameters); + } + } + static function getMimeType($uri, $mapping = NULL) { + return 'video/archive'; + } + + function getTarget($f) { + return FALSE; + } + + function getOriginalThumbnailPath() { + $parts = $this->get_parameters(); + return check_plain($parts['video_thumb']); + } + + function getLocalThumbnailPath() { + $parts = $this->get_parameters(); + $local_path = 'public://media-archive/' . check_plain($parts['video_videofirst']) . '.jpg'; + + if (!file_exists($local_path)) { + $dirname = drupal_dirname($local_path); + file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + $response = drupal_http_request($this->getOriginalThumbnailPath()); + if (!isset($response->error)) { + file_save_data($response->data, $local_path, TRUE); + } + else { + @copy($this->getOriginalThumbnailPath(), $local_path); + } + } + return $local_path; + } +} diff --git a/includes/MediaInternetArchiveHandler.inc b/includes/MediaInternetArchiveHandler.inc new file mode 100644 index 0000000..50147db --- /dev/null +++ b/includes/MediaInternetArchiveHandler.inc @@ -0,0 +1,131 @@ +data; + return $ids[$id]; + } + + $response = drupal_http_request('http://' . MEDIA_ARCHIVE_BASE_URL . '/embed/' . $id . MEDIA_ARCHIVE_REST_API); + $data = drupal_json_decode($response->data); + + $ids[$id] = $data; + cache_set('media_archive:rawid:' . $id, $ids[$id], 'cache_media_xml', media_variable_get('xml_cache_expire', 3600)); + + return $data; + } + + /** + * Check if an Archive.org video id is valid. + * + * This is a bit diffrent from other providers, + * we also return the file_name on success. (?) + * + * @return + * string $file_name. + */ + public function validId($video_id) { + // TODO. + return TRUE; + } + + /** + * Parse the embed code provided by the user. + */ + public function parse($embedCode) { + $scheme = 'archive://'; + preg_match('@archive\.org/details/([^"\& ]+)@i', $embedCode, $matches); + if (!empty($matches)) { + $org = self::validId($matches[1]); + return file_stream_wrapper_uri_normalize('archive://' . $matches[1]); + } + return FALSE; + } + + public function claim($embedCode) { + if ($this->parse($embedCode)) { + return TRUE; + } + } + + public function getFileObject() { + $uri = $this->parse($this->embedCode); + + $file = file_uri_to_object($uri, TRUE); + + if (empty($file->fid)) { +// TODO: fix up this with a real human readable filename. +// $title = $path[1]; +// $file->filename = truncate_utf8($title, 255); + } + + return $file; + } + + /** + * Returns information about the media. See http://video.search.yahoo.com/mrss. + * + * @return + * If ATOM+MRSS information is available, a SimpleXML element containing + * ATOM and MRSS elements, as per those respective specifications. + * + * @todo Would be better for the return value to be an array rather than a + * SimpleXML element, but media_retrieve_xml() needs to be upgraded to + * handle namespaces first. + * http://archive.org/file/4035623?skin=rss + */ + public function getMRSS() { + $uri = media_archive_media_parse($this->embedCode); + $video_id = arg(1, file_uri_target($uri)); + $rss_url = url('http://gdata.archive.org/feeds/api/videos/' . $video_id, array('query' => array('v' => '2'))); + // @todo Use media_retrieve_xml() once it's upgraded to include elements + // from all namespaces, not just the document default namespace. + $entry = simplexml_load_file($rss_url); + return $entry; + } + + /** + * Returns information about the media. See http://www.oembed.com/. + * + * @return + * If oEmbed information is available, an array containing 'title', 'type', + * 'url', and other information as specified by the oEmbed standard. + * Otherwise, NULL. + * http://archive.org/oembed/?url=http://archive.org/file/12345 + */ + public function getOEmbed() { + $uri = media_archive_media_parse($this->embedCode); + $external_url = drupal_realpath($uri); + $oembed_url = url('http://archive.org/oembed', array('query' => array('url' => $external_url, 'format' => 'json'))); + $response = drupal_http_request($oembed_url); + if (!isset($response->error)) { + return drupal_json_decode($response->data); + } + } +} diff --git a/includes/media_archive.formatters.inc b/includes/media_archive.formatters.inc new file mode 100644 index 0000000..e61a98f --- /dev/null +++ b/includes/media_archive.formatters.inc @@ -0,0 +1,257 @@ + t('Archive Video'), + 'file types' => array('video'), + 'default settings' => array(), + 'view callback' => 'media_archive_file_formatter_video_view', + 'settings callback' => 'media_archive_file_formatter_video_settings', + ); + + foreach (array('width', 'height', 'autoplay', 'controls', 'controls_hide', 'loop') as $setting) { + $formatters['media_archive_video']['default settings'][$setting] = media_archive_variable_get($setting); + } + + $formatters['media_archive_image'] = array( + 'label' => t('Archive Preview Image'), + 'file types' => array('video'), + 'default settings' => array( + 'image_style' => '', + ), + 'view callback' => 'media_archive_file_formatter_image_view', + 'settings callback' => 'media_archive_file_formatter_image_settings', + ); + + return $formatters; +} + +/** + * Implements hook_file_formatter_FORMATTER_view(). + */ +function media_archive_file_formatter_video_view($file, $display, $langcode) { + $scheme = file_uri_scheme($file->uri); + // WYSIWYG does not yet support video inside a running editor instance. + if ($scheme == 'archive' && empty($file->override['wysiwyg'])) { + $element = array( + '#theme' => 'media_archive_video', + '#uri' => $file->uri, + '#options' => array(), + ); + + // Fake a default for attributes so the ternary doesn't choke. + $display['settings']['attributes'] = array(); + + foreach (array('width', 'height', 'autoplay', 'controls', 'controls_hide', 'loop') as $setting) { + $element['#options'][$setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting]; + } + return $element; + } +} + +/** + * Implements hook_file_formatter_FORMATTER_settings(). + */ +function media_archive_file_formatter_video_settings($form, &$form_state, $settings) { + $element = array(); + $element['width'] = array( + '#title' => t('Width'), + '#type' => 'textfield', + '#default_value' => $settings['width'], + '#element_validate' => array('_archive_validate_video_width_and_height'), + ); + $element['height'] = array( + '#title' => t('Height'), + '#type' => 'textfield', + '#default_value' => $settings['height'], + '#element_validate' => array('_archive_validate_video_width_and_height'), + ); + $element['autoplay'] = array( + '#title' => t('Autoplay'), + '#type' => 'checkbox', + '#default_value' => $settings['autoplay'], + ); + $element['controls'] = array( + '#title' => t('Show controls'), + '#type' => 'checkbox', + '#default_value' => $settings['controls'], + ); + $element['controls_hide'] = array( + '#title' => t('Auto hide controls'), + '#type' => 'checkbox', + '#default_value' => $settings['controls_hide'], + ); + $element['loop'] = array( + '#title' => t('Loop video'), + '#type' => 'checkbox', + '#default_value' => $settings['loop'], + ); + + return $element; +} + +/** + * Validation for width and height. + */ +function _archive_validate_video_width_and_height($element, &$form_state, $form) { + + // Check if the value is a number with an optional decimal or percentage sign, or "auto". + if (!empty($element['#value']) && !preg_match('/^(auto|([0-9]*(\.[0-9]+)?%?))$/', $element['#value'])) { + form_error($element, t("The value entered for @dimension is invalid. Please insert a unitless integer for pixels, a percent, or \"auto\". Note that percent and auto may not function correctly depending on the browser and doctype.", array('@dimension' => $element['#title']))); + } +} + +/** + * Implements hook_file_formatter_FORMATTER_view(). + */ +function media_archive_file_formatter_image_view($file, $display, $langcode) { + $scheme = file_uri_scheme($file->uri); + if ($scheme == 'archive') { + $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri); + $image_style = $display['settings']['image_style']; + $valid_image_styles = image_style_options(FALSE); + // @TODO: If autosubmit is removed and we allow view modes that insert + // images in the WYSIWYG, add file->overrides handling. + if (empty($image_style) || !isset($valid_image_styles[$image_style])) { + $element = array( + '#theme' => 'image', + '#path' => $wrapper->getOriginalThumbnailPath(), + '#alt' => isset($file->override['attributes']['alt']) ? $file->override['attributes']['alt'] : $file->filename, + ); + } + else { + $element = array( + '#theme' => 'image_style', + '#style_name' => $image_style, + '#path' => $wrapper->getLocalThumbnailPath(), + '#alt' => isset($file->override['attributes']['alt']) ? $file->override['attributes']['alt'] : $file->filename, + ); + } + + return $element; + } +} + +/** + * Implements hook_file_formatter_FORMATTER_settings(). + */ +function media_archive_file_formatter_image_settings($form, &$form_state, $settings) { + $element = array(); + $element['image_style'] = array( + '#title' => t('Image style'), + '#type' => 'select', + '#options' => image_style_options(FALSE), + '#default_value' => $settings['image_style'], + '#empty_option' => t('None (original image)'), + ); + $element['width'] = array( + '#title' => t('Width'), + '#type' => 'textfield', + '#default_value' => $settings['width'], + '#states' => array( + 'visible' => array( + ':input[name="displays[media_archive_image][settings][image_style]"]' => array('value' => ''), + ), + ), + ); + $element['height'] = array( + '#title' => t('Height'), + '#type' => 'textfield', + '#default_value' => $settings['height'], + '#states' => array( + 'visible' => array( + ':input[name="displays[media_archive_image][settings][image_style]"]' => array('value' => ''), + ), + ), + ); + return $element; +} + +/** + * Implements hook_file_default_displays(). + */ +function media_archive_file_default_displays() { + $default_displays = array(); + + // Default settings for displaying as a video. + $default_video_settings = array( + 'default' => array( + 'width' => 640, + 'height' => 388, + 'autoplay' => FALSE, + 'controls' => TRUE, + 'controls_hide' => TRUE, + 'loop' => FALSE, + ), + 'teaser' => array( + 'width' => 560, + 'height' => 348, + 'autoplay' => FALSE, + 'controls' => TRUE, + 'controls_hide' => TRUE, + 'loop' => FALSE, + ), + 'media_large' => array( + 'width' => 480, + 'height' => 360, + 'autoplay' => FALSE, + 'controls' => TRUE, + 'controls_hide' => TRUE, + 'loop' => FALSE, + ), + 'media_original' => array( + 'width' => 640, + 'height' => 480, + 'autoplay' => media_archive_variable_get('autoplay'), + 'controls' => TRUE, + 'controls_hide' => TRUE, + 'loop' => FALSE, + ), + ); + foreach ($default_video_settings as $view_mode => $settings) { + $display_name = 'video__' . $view_mode . '__media_archive_video'; + $default_displays[$display_name] = (object) array( + 'api_version' => 1, + 'name' => $display_name, + 'status' => 1, + 'weight' => 1, + 'settings' => $settings, + ); + } + + // Default settings for displaying a video preview image. + // We enable preview images even for view modes that also play video + // for use inside a running WYSIWYG editor. We weight them so video + // formatters come first in the cascade to make sure the video formatter + // is used whenever possible. + $default_image_styles = array( + 'default' => 'large', + 'preview' => 'square_thumbnail', + 'teaser' => 'large', + // Legacy view modes, see note above. + 'media_preview' => 'square_thumbnail', + 'media_large' => 'large', + 'media_original' => '', + ); + foreach ($default_image_styles as $view_mode => $image_style) { + $display_name = 'video__' . $view_mode . '__media_archive_image'; + $default_displays[$display_name] = (object) array( + 'api_version' => 1, + 'name' => $display_name, + 'status' => 1, + 'weight' => 2, + 'settings' => array('image_style' => $image_style), + ); + } + + return $default_displays; +} diff --git a/includes/media_archive.styles.inc b/includes/media_archive.styles.inc deleted file mode 100755 index b01f973..0000000 --- a/includes/media_archive.styles.inc +++ /dev/null @@ -1,166 +0,0 @@ - array( - 'containers' => array( - 'media_archive' => array( - 'class' => 'MediaArchiveStyles', - 'name' => 'media_archive', - 'label' => t('Archive'), - 'preview' => 'media_archive_preview_style', - ), - ), - ), - ); -} - - -/** - * Implementation of Styles module hook_styles_default_presets(). - */ -function media_archive_styles_default_presets() { - return array( - 'file' => array( - 'containers' => array( - 'media_archive' => array( - 'default preset' => 'linked_thumbnail', - 'styles' => array( - 'original' => array( - 'default preset' => 'video', - ), - 'thumbnail' => array( - 'default preset' => 'linked_thumbnail', - ), - 'square_thumbnail' => array( - 'default preset' => 'linked_square_thumbnail', - ), - 'medium' => array( - 'default preset' => 'linked_medium', - ), - 'large' => array( - 'default preset' => 'large_video', - ), - ), - 'presets' => array( - 'unlinked_thumbnail' => array( - array( - 'name' => 'thumbnail', - 'settings' => array(), - ), - ), - 'linked_thumbnail' => array( - array( - 'name' => 'link_to_media', - 'settings' => array(), - ), - array( - 'name' => 'thumbnail', - 'settings' => array(), - ), - ), - 'linked_square_thumbnail' => array( - array( - 'name' => 'link_to_media', - 'settings' => array(), - ), - array( - 'name' => 'image_style', - 'settings' => array( - 'image_style' => 'square_thumbnail', - ), - ), - array( - 'name' => 'thumbnail', - 'settings' => array(), - ), - ), - 'linked_medium' => array( - array( - 'name' => 'link_to_media', - 'settings' => array(), - ), - array( - 'name' => 'image_style', - 'settings' => array( - 'image_style' => 'medium', - ), - ), - array( - 'name' => 'thumbnail', - 'settings' => array(), - ), - ), - 'video' => array( - array( - 'name' => 'video', - 'settings' => array(), - ), - ), - 'large_video' => array( - array( - 'name' => 'resize', - 'settings' => array( - 'width' => 480, - 'height' => 360, - ), - ), - array( - 'name' => 'video', - 'settings' => array(), - ), - ), - ), - ), - ), - ), - ); -} - -class MediaArchiveStyles extends FileStyles { - public $autoplay; - public $fullscreen; - - function get_autoplay() { - return $this->get('autoplay'); - } - function set_autoplay($value) { - return $this->set('autoplay', $value); - } - function get_fullscreen() { - return $this->get('fullscreen'); - } - function set_fullscreen($value) { - return $this->set('fullscreen', $value); - } - - function get_image_uri() { - if ($image_uri = $this->get('image_uri')) { - return $image_uri; - } - $object = $this->get_object(); - if ($object->uri) { - $wrapper = file_stream_wrapper_get_instance_by_uri($object->uri); - return $wrapper->getLocalThumbnailPath(); - } - } - function video($effect) { - $variables = array( - 'uri' => $this->get_uri(), - 'width' => $this->get_width(), - 'height' => $this->get_height(), - 'autoplay' => $this->get_autoplay(), - 'fullscreen' => $this->get_fullscreen(), - ); - $this->set_output(theme('media_archive_video', $variables)); - } -} diff --git a/includes/media_archive.variables.inc b/includes/media_archive.variables.inc old mode 100755 new mode 100644 index 10b39b6..4d9842a --- a/includes/media_archive.variables.inc +++ b/includes/media_archive.variables.inc @@ -2,6 +2,7 @@ /** * @file media_archive/includes/media_archive.variables.inc + * * Variable defaults for Media: Archive. */ @@ -15,6 +16,23 @@ define('MEDIA_ARCHIVE_NAMESPACE', 'media_archive__'); /** + * This is the rest point for the Archive api. + * + * @see http://archive.org/help/json.php + * @examle http://archive.org/details/ComputerNetworks_TheHeraldsOfResourceSharing&output=json + */ +define('MEDIA_ARCHIVE_REST_API', '&output=json'); + +/** + * This needs to change i guess. + */ +define('MEDIA_ARCHIVE_BASE_URL', 'archive.org'); + +/** + * Variable system uses Ctools Exportables. + */ + +/** * Wrapper for variable_get() using the Media: Archive variable registry. * * @param string $name @@ -101,11 +119,12 @@ function media_archive_variable_default($name = NULL) { if (!isset($defaults)) { $defaults = array( - 'width' => 560, - 'height' =>340, - 'autoplay' => FALSE, - 'fullscreen' => TRUE, - 'preview_uri' => 'archive://v/-jubiv7QUco', + 'width' => 560, + 'height' => 340, + 'autoplay' => FALSE, + 'controls' => TRUE, + 'controls_hide' => TRUE, + 'loop' => FALSE, ); } diff --git a/includes/themes/media-archive-video.tpl.php b/includes/themes/media-archive-video.tpl.php old mode 100755 new mode 100644 index 4ba519d..f858ca1 --- a/includes/themes/media-archive-video.tpl.php +++ b/includes/themes/media-archive-video.tpl.php @@ -1,24 +1,44 @@ -
-
- -
+
+
diff --git a/includes/themes/media_archive.theme.inc b/includes/themes/media_archive.theme.inc old mode 100755 new mode 100644 index 2fc0fe2..413d991 --- a/includes/themes/media_archive.theme.inc +++ b/includes/themes/media_archive.theme.inc @@ -10,213 +10,74 @@ * Preprocess function for theme('media_archive_video'). */ function media_archive_preprocess_media_archive_video(&$variables) { + // Define some variables. + $protocol = 'http:'; + $url_base = 'archive.org'; + // Build the URL for display. $uri = $variables['uri']; $wrapper = file_stream_wrapper_get_instance_by_uri($uri); $parts = $wrapper->get_parameters(); - $variables['video_id'] = check_plain($parts['v']); - - //convert episode id from filepath to embed code - $variables['embed_code'] = media_archive_embedcode_lookup($variables['video_id']); - - $variables['width'] = isset($variables['width']) ? $variables['width'] : media_archive_variable_get('width'); - $variables['height'] = isset($variables['height']) ? $variables['height'] : media_archive_variable_get('height'); - $variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_archive_variable_get('autoplay'); - $variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_archive_variable_get('fullscreen'); - $variables['autoplay'] = $variables['autoplay'] ? 1 : 1; - $variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false'; - - $variables['wrapper_id'] = 'media_archive_' . $variables['video_id'] . '_' . $variables['id']; - - $mp4URL = 'http://www.archive.org/download/' . $variables['video_id'] . '/' . $variables['embed_code'] . '_512kb.mp4'; - $ogvURL = 'http://www.archive.org/download/' . $variables['video_id'] . '/' . $variables['embed_code'] . '.ogv'; - - //Fix for IE!! - - // - - - $variables['output'] = ''; - - // For users with JavaScript, these object and embed tags will be replaced - // by an iframe, so that we can support users without Flash. - /* - $variables['output'] = ''; - $variables['output'] .= ''; - $variables['output'] .= ''; - $variables['output'] .= ''; - $variables['output'] .= ''; - - $variables['output'] .= ""; - - $config = "'key':\'#$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'" . $variables['embed_code'] . "_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/" . $variables['video_id'] . "/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']"; - - - $variables['output'] .= ''; - $variables['output'] .= ''; -*/ - -/* - - $variables['output'] = << - - - - - -OUTPUT; -*/ - // @todo Replace this inline JavaScript with at least calls to - // drupal_add_js()/drupal_get_js(), and ideally, with a behavior. Keep - // in mind that the solution needs to work when inside a colorbox or - // otherwise in an AJAX response, but that should now be possible in D7. - - /* - - $iframe_id = drupal_json_encode($variables['wrapper_id'] .'_iframe'); - $wrapper_id = drupal_json_encode($variables['wrapper_id']); - $JSObject = 'Drupal.settings.media_archive[' . $wrapper_id . ']'; - $variables['output'] .= << - if (Drupal.settings && Drupal.media_archive) { - Drupal.settings.media_archive = Drupal.settings.media_archive || {}; - $JSObject = {}; - $JSObject.width = {$variables['width']}; - $JSObject.height = {$variables['height']}; - $JSObject.video_id = "{$variables['video_id']}"; - $JSObject.fullscreen = {$variables['fullscreen']}; - $JSObject.id = $iframe_id; - Drupal.media_archive.insertEmbed($wrapper_id); - } - -OUTPUT; -*/ + $variables['video_id'] = check_plain($parts['v']); + $variables['wrapper_id'] = 'media_archive_' . $variables['video_id'] . '_' . $parts['video_videosecond']; + + // Define some links to the available formats. + $mediaformat = array( + 'mp4URL' => '_512kb.mp4', + 'webmURL' => '.webm', + 'ogvURL' => '.ogv', + ); + foreach ($mediaformat as $format => $ext) { + $variables[$format] = 'http://' . MEDIA_ARCHIVE_BASE_URL . '/download/' . $variables['video_id'] . '/' . $parts['video_videosecond'] . $ext; + } - //drupal_add_js(drupal_get_path('module', 'media_archive') . '/js/media_archive.js'); - drupal_add_css(drupal_get_path('module', 'media_archive') . '/css/media_archive.css'); - drupal_add_js(drupal_get_path('module', 'media_archive') . '/js/flash_detect_min.js'); -} + // Add some options as their own template variables. + foreach (array('width', 'height') as $theme_var) { + $variables[$theme_var] = $variables['options'][$theme_var]; + } -function theme_media_archive_field_formatter_styles($variables) { - $element = $variables['element']; - $style = $variables['style']; - $variables['file'] = $element['#item']; - $variables['uri'] = $variables['file']['uri']; - $variables['style_name'] = $style['name']; - return theme('media_archive_embed', $variables); -} + // Build the html5 player settings and flash query. + $query = array(); -/** - * Preview for Styles UI. - */ -function theme_media_archive_preview_style($variables) { - $variables['uri'] = media_archive_variable_get('preview_uri'); - $variables['field_type'] = 'file'; - $variables['object'] = file_uri_to_object($variables['uri']); + if ($variables['options']['autoplay']) { + $variables['autoplay'] = ' autoplay'; + $query['autoplay'] = 'true'; + } + else { + $variables['autoplay'] = ''; + } - return theme('styles', $variables); -} + // Show controls. + if ($variables['options']['controls']) { + $variables['controls'] = ' controls'; + $query['controlbar.position'] = 'over'; + } + else { + $variables['controls'] = ''; + $query['controlbar.position'] = 'none'; + } -/** - * NOTE: Deprecated with Styles version 2. - */ -function theme_media_archive_styles($variables) { - $style = $variables['style']; - $variables['file'] = $variables['object']; - $variables['uri'] = $variables['object']->uri; - $variables['style_name'] = $style['name']; - return theme('media_archive_embed', $variables); -} + // Hide controls after mouse left the player window. + if ($variables['options']['controls_hide']) { + $query['controlbar.idlehide'] = 'true'; + } + else { + $query['controlbar.idlehide'] = 'false'; + } -/** - * @todo: get this working - * - * This code is for embedding videos in WYSIYWG areas, not currently working. - * NOTE: Deprecated with Styles version 2. - */ -function theme_media_archive_embed($variables) { - $preset_name = $variables['preset_name']; - $preset = styles_containers_available_styles('file', 'media_archive', $preset_name); - $output = ''; - if (!empty($preset)) { - // Build the URL for display. - $uri = $variables['uri']; - $wrapper = file_stream_wrapper_get_instance_by_uri($uri); - $parts = $wrapper->get_parameters(); + // Loop the video. + if ($variables['options']['loop']) { + $variables['loop'] = ' loop'; + $query['repeat'] = 'list'; + } + else { + $variables['loop'] = ''; + } - $fullscreen_value = $autoplay = 'false'; - $in_browser = $thumbnail = FALSE; + $variables['poster'] = ''; - foreach ($preset['effects'] as $effect) { - switch ($effect['name']) { - case 'autoplay': - $autoplay = $effect['data']['autoplay'] ? 'true' : 'false'; - break; - case 'resize': - $width = $effect['data']['width']; - $height = $effect['data']['height']; - break; - case 'fullscreen': - $fullscreen_value = $effect['data']['fullscreen'] ? 'true' : 'false'; - break; - case 'thumbnail': - $thumbnail = $effect['data']['thumbnail']; - } - } - if (isset($variables['object']->override)) { - $override = $variables['object']->override; - if (isset($override['width'])) { - $width = $override['width']; - } - if (isset($override['height'])) { - $height = $override['height']; - } - if (isset($override['wysiwyg'])) { - $thumbnail = TRUE; - } - if (isset($override['browser']) && $override['browser']) { - $in_browser = TRUE; - $thumbnail = TRUE; - } - } - $width = isset($width) ? $width : media_archive_variable_get('width'); - $height = isset($height) ? $height : media_archive_variable_get('height'); - $video_id = check_plain($parts['v']); - if ($thumbnail) { - // @todo Clean this up. - $image_variables = array( - 'path' => $wrapper->getOriginalThumbnailPath(), - 'alt' => $variables['alt'], - 'title' => $variables['title'], - 'getsize' => FALSE, - ); - if (isset($preset['image_style'])) { - $image_variables['path'] = $wrapper->getLocalThumbnailPath(); - $image_variables['style_name'] = $preset['image_style']; - $output = theme('image_style', $image_variables); - } - else { - // We need to add this style attribute here so that it doesn't get lost - // If you resize a video in a node, save it, edit it, but don't adjust - // the sizing of the video while editing, the size will revert to the - // default. Adding the specific size here retains the original resizing - $WYSIWYG = isset($variables['object']->override['style']) ? $variables['object']->override['style'] : ''; - $image_variables['attributes'] = array('width' => $width, 'height' => $height, 'style' => $WYSIWYG); - $output = theme('image', $image_variables); - } - if ($in_browser) { - // Add an overlay that says 'Archive' to media library browser thumbnails. - $output .= ''; - } - } - else { - $output = theme('media_archive_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL))); - } - } - return $output; + // Build the flash url. + $variables['url'] = url($protocol . '//www.' . $url_base . '/embed/' . $variables['video_id'], array('query' => $query, 'external' => TRUE)); + $variables['url'] = htmlspecialchars($variables['url']); } diff --git a/js/flash_detect_min.js b/js/flash_detect_min.js deleted file mode 100755 index ebdff92..0000000 --- a/js/flash_detect_min.js +++ /dev/null @@ -1,5 +0,0 @@ -//http://www.featureblend.com/license.txt -var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){} -return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){} -return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};} -return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i=arguments[i]){if(i+10){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i'); - that.browser = $('ul', mediaBrowser.getActivePanel()); - that.browser.addClass('clearfix'); - that.getMedia(); - } - }); - }, - - getStreams: function () { - return ['archive://']; - }, - - getConditions: function () { - return {}; - //return this.settings.conditions; - }, - - getMedia: function() { - var that = this; - var callback = mediaBrowser.getCallbackUrl('getMedia'); - var params = { - conditions: JSON.stringify(this.getConditions()), - streams: JSON.stringify(this.getStreams()) - }; - jQuery.get( - callback, - params, - function(data, status) { - that.mediaFiles = data.media; - that.emptyMessage = data.empty; - that.pager = data.pager; - that.render(); - }, - 'json' - ); - }, - - render: function() { - var that = this; - mediaBrowser.getActivePanel().removeClass('throbber'); - if (this.mediaFiles.length < 1) { - jQuery('
').appendTo(this.browser) - .html(this.emptyMessage); - return; - } - - for (var m in this.mediaFiles) { - mediaFile = this.mediaFiles[m]; - - var listItem = jQuery('
  • ').appendTo(this.browser) - .attr('id', 'media-file-' + mediaFile.fid) - .addClass('media-file'); - - var imgLink = jQuery('').appendTo(listItem) - .html(mediaFile.preview) - .bind('click', mediaFile, function(e) { - // Notify the main browser - //this.selectedMedia = mediaFile; - $('div.media-thumbnail img').removeClass('selected'); - $('div.media-thumbnail img', $(this)).addClass('selected'); - mediaBrowser.notify('mediaSelected', {mediaFiles: [e.data]}); - //that.settings.onSelect(mediaFile); - return false; - }); - } - jQuery('
    ').appendTo(this.browser) - .html(this.pager); - } - }; -}; - - Drupal.media.browser.register('archive_library', Drupal.media.browser.plugin.archive_library); -})(jQuery); diff --git a/js/media_archive.js b/js/media_archive.js deleted file mode 100755 index 6eb5155..0000000 --- a/js/media_archive.js +++ /dev/null @@ -1,99 +0,0 @@ - -/** - * @file media_archive/js/media_archive.js - */ - -(function ($) { - -Drupal.media_archive = {}; -Drupal.behaviors.media_archive = { - attach: function (context, settings) { - // Check the browser to see if it supports html5 video. - var video = document.createElement('video'); - var html5 = video.canPlayType ? true : false; - - // If it has video, does it support the correct codecs? - if (html5) { - html5 = false; - if (video.canPlayType( 'video/webm; codecs="vp8, vorbis"' ) || video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')) { - html5 = true; - } - } - - // Put a prompt in the video wrappers to let users know they need flash - if (!FlashDetect.installed && !html5){ - $('.media-archive-preview-wrapper').each(Drupal.media_archive.needFlash); - } - } -}; - -Drupal.media_archive.needFlash = function () { - var id = $(this).attr('id'); - var wrapper = $('.media-archive-preview-wrapper'); - var hw = Drupal.settings.media_archive[id].height / Drupal.settings.media_archive[id].width; - wrapper.html('
    ' + Drupal.t('You need Flash to watch this video. Get Flash', {'@flash':'http://get.adobe.com/flashplayer'}) + '
    '); - wrapper.height(wrapper.width() * hw); -}; - -Drupal.media_archive.insertEmbed = function (embed_id) { - var videoWrapper = $('#' + embed_id + '.media-archive-preview-wrapper'); - var settings = Drupal.settings.media_archive[embed_id]; - - // Calculate the ratio of the dimensions of the embed. - settings.hw = settings.height / settings.width; - - // Replace the object embed with Archive's iframe. This isn't done by the - // theme function because Archive doesn't have a no-JS or no-Flash fallback. - var video = $(''); - var src = 'http://www.archive.org/file/' + settings.video_id; - - // Allow other modules to modify the video settings. - settings.options = {wmode : 'opaque'}; - $(window).trigger('media_archive_load', settings); - - // Merge Archive options (such as autoplay) into the source URL. - var query = $.param(settings.options); - if (query) { - src += '?' + query; - } - - // Set up the iframe with its contents and add it to the page. - video - .attr('id', settings.id) - .attr('width', settings.width) - .attr('height', settings.height) - .attr('src', src); - videoWrapper.html(video); - - // Bind a resize event to handle fluid layouts. - $(window).bind('resize', Drupal.media_archive.resizeEmbeds); - - // For some reason Chrome does not properly size the container around the - // embed and it will just render the embed at full size unless we set this - // timeout. - if (!$('.lightbox-stack').length) { - setTimeout(Drupal.media_archive.resizeEmbeds, 1); - } -}; - -Drupal.media_archive.resizeEmbeds = function () { - $('.media-archive-preview-wrapper').each(Drupal.media_archive.resizeEmbed); -}; - -Drupal.media_archive.resizeEmbed = function () { - var context = $(this).parent(); - var video = $(this).children(':first-child'); - var hw = Drupal.settings.media_archive[$(this).attr('id')].hw; - // Change the height of the wrapper that was given a fixed height by the - // Archive theming function. - $(this) - .height(context.width() * hw) - .width(context.width()); - - // Change the attributes on the embed to match the new size. - video - .height(context.width() * hw) - .width(context.width()); -}; - -})(jQuery); \ No newline at end of file diff --git a/media_archive.admin.inc b/media_archive.admin.inc deleted file mode 100755 index f900f08..0000000 --- a/media_archive.admin.inc +++ /dev/null @@ -1,113 +0,0 @@ - 'vertical_tabs', - ); - $form['archive']['all'] = array( - '#type' => 'fieldset', - '#title' => t('All Archive videos'), - ); - - // Get all archive files for this user - $results = db_query("SELECT fid FROM {file_managed} WHERE uid = :uid AND uri LIKE :uri", array( - ':uid' => $user->uid, - ':uri' => 'archive%%' - ))->fetchAll(); - - foreach ($results as $result) { - $file = file_load($result->fid); - $output = theme('image', array( - 'path' => 'http://img.archive.org/vi/' . pathinfo($file->uri, PATHINFO_FILENAME) . '/0.jpg', - 'title' => 'title', - 'alt' => 'alt', - 'attributes' => array('width' => 150), - 'getsize' => FALSE, - )); - $form['archive']['all'][$file->fid] = array( - '#markup' => $output, - ); - } - -/* $form['archive']['all']['test'] = array( - '#type' => 'checkbox', - '#title' => 'test', - );*/ - $form['archive']['add_from_url'] = array( - '#type' => 'fieldset', - '#title' => t('Add from URL'), - ); - $form['archive']['add_from_url']['url'] = array( - '#type' => 'textfield', - '#title' => 'URL', - '#description' => 'Input the URL of the desired Archive video page.', - ); - $form['redirect'] = array( - '#type' => 'value', - '#value' => $redirect, - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** - * Validation for media_archive_add(). - */ -function media_archive_add_validate($form, &$form_state) { - if (!preg_match('@blip\.tv/file/([^"\& ]+)@i', $form_state['values']['url'], $matches)) { - form_set_error('url', t('Please submit a valid Archive video URL.')); - } -} - -/** - * Submission for media_archive_add(). - * - * This will create a file object for the Archive video. - */ -function media_archive_add_submit($form, &$form_state) { - $defaults = array ( - 'display' => TRUE, - ); - - $uri = media_archive_media_parse($form_state['values']['url']); - - // Check to see if this a duplicate of an existing file - $files = file_load_multiple(NULL, array('uri' => $uri)); - if ($files) { - // This is ugly. - $file = array_shift($files); - } - else { - // @TODO: This won't work for Archive and many other streams. - // copy($url, $destination); - $file = file_uri_to_object($uri); - file_save($file); - } - - // field_attach_insert('media', $file); - if ($file) { - $form_state['redirect'] = 'media/' . $file->fid . '/edit'; - field_attach_submit('media', $file, $form, $form_state); - field_attach_insert('media', $file); - } - else { - drupal_set_message(t('An error occurred and no file was saved.'), 'error'); - } - - $form_state['redirect'] = !empty($form_state['values']['redirect']) ? $form_state['values']['redirect'] : 'media/' . $file->fid . '/edit'; -} diff --git a/media_archive.info b/media_archive.info old mode 100755 new mode 100644 index 366943c..aaca05b --- a/media_archive.info +++ b/media_archive.info @@ -1,10 +1,11 @@ - name = Media: Archive description = Provides Archive support to the Media module. -package = "Media" +package = Media core = 7.x files[] = media_archive.module -files[] = MediaArchiveStreamWrapper.inc -files[] = media_archive.admin.inc -files[] = includes/media_archive.styles.inc +files[] = includes/MediaInternetArchiveHandler.inc +files[] = includes/MediaArchiveStreamWrapper.inc +files[] = includes/media_archive.formatters.inc +files[] = includes/media_archive.variables.inc +dependencies[] = media dependencies[] = media_internet diff --git a/media_archive.install b/media_archive.install old mode 100755 new mode 100644 index 4bbfaf1..9f8d8a6 --- a/media_archive.install +++ b/media_archive.install @@ -16,9 +16,10 @@ function media_archive_install() { * Implement hook_uninstall(). */ function media_archive_uninstall() { + drupal_load('module', 'media_archive'); + foreach (media_archive_variable_default() as $variable => $value) { media_archive_variable_del($variable); } - return array(array('success' => TRUE, 'query' => "Deleted all variables in the Media: Archive namespace.")); + return array(array('success' => TRUE, 'query' => "Deleted all variables in the Media: Archive.org namespace.")); } - diff --git a/media_archive.module b/media_archive.module old mode 100755 new mode 100644 index fac56cc..3637cf2 --- a/media_archive.module +++ b/media_archive.module @@ -1,352 +1,89 @@ t('Archive.org'), + ); + + return $info; +} /** - * Create stream wrapper for Archive videos. + * Implements hook_stream_wrappers(). */ function media_archive_stream_wrappers() { return array( 'archive' => array( - 'name' => t('Archive videos'), + 'name' => t('Archive.org videos'), 'class' => 'MediaArchiveStreamWrapper', - 'description' => t('Videos provided by Archive.'), + 'description' => t('Videos provided by Archive.org.'), 'type' => STREAM_WRAPPERS_READ_VISIBLE, ), ); } -function media_archive_media_format_form_prepare_alter(&$form, &$form_state, $media) { - $settings = array('autosubmit' => ($media->type == "video")); - drupal_add_js(array('media_format_form' => $settings), 'setting'); -} - /** * Implements hook_theme(). */ function media_archive_theme($existing, $type, $theme, $path) { return array( - 'media_archive_preview_style' => array( - 'variables' => array('style_name' => NULL), - 'file' => 'media_archive.theme.inc', - 'path' => $path . '/includes/themes', - ), - 'media_archive_field_formatter_styles' => array( - 'variables' => array('element' => NULL, 'style' => NULL), - 'file' => 'media_archive.theme.inc', - 'path' => $path . '/includes/themes', - ), 'media_archive_video' => array( - 'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL), + 'variables' => array('uri' => NULL, 'options' => array()), 'file' => 'media_archive.theme.inc', 'path' => $path . '/includes/themes', 'template' => 'media-archive-video', ), - 'media_archive_embed' => array( - 'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL), - 'file' => 'media_archive.theme.inc', - 'path' => $path . '/includes/themes', - ), - 'media_archive_styles' => array( - 'variables' => array('element' => NULL, 'style' => NULL), - 'file' => 'media_archive.theme.inc', - 'path' => $path . '/includes/themes', - ), - ); -} - -/** - * Implementation of Styles module hook_styles_register(). - */ -function media_archive_styles_register() { - return array( - 'MediaArchiveStyles' => array( - 'field_types' => 'file', - 'name' => t('MediaArchive'), - 'description' => t('Media Archive styles.'), - 'path' => drupal_get_path('module', 'media_archive') .'/includes', - 'file' => 'media_archive.styles.inc', - ), ); } /** - * Implements hook_styles_containers(). (Deprecated in version 2) - */ -function media_archive_styles_containers() { - return array( - 'file' => array( - 'containers' => array( - 'media_archive' => array( - 'label' => t('Archive Styles'), - 'data' => array( - 'streams' => array( - 'archive', - ), - 'mimetypes' => array( - 'video/archive', - ), - ), - 'weight' => 0, - 'filter callback' => 'media_archive_formatter_filter', - 'themes' => array( - 'field_formatter_styles' => 'media_archive_field_formatter_styles', - 'styles' => 'media_archive_styles', - 'preview' => 'media_archive_preview_style', - ), - 'description' => t('Archive Styles will display embedded Archive videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your Archive styles here'), 'admin/config/media/media-archive-styles'))), - ), - ), - ), - ); -} - -function media_archive_formatter_filter($variables) { - if (isset($variables['object'])) { - $object = $variables['object']; - return (file_uri_scheme($object->uri) == 'archive') && ($object->filemime == 'video/archive'); - } -} - -/** - * Implementation of the File Styles module's hook_file_styles_filter(). - */ -function media_archive_file_styles_filter($object) { - if ((file_uri_scheme($object->uri) == 'archive') && ($object->filemime == 'video/archive')) { - return 'media_archive'; - } -} - -/** - * Implements hook_styles_styles(). - */ -function media_archive_styles_styles() { - $styles = array( - 'file' => array( - 'containers' => array( - 'media_archive' => array( - 'styles' => array( - 'archive_thumbnail' => array( - 'name' => 'archive_thumbnail', - 'effects' => array( - array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)), - array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 100, 'height' => 75)), - ), - ), - 'archive_preview' => array( - 'name' => 'archive_preview', - 'effects' => array( - array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 1)), - array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 220, 'height' => 165)), - ), - ), - 'archive_full' => array( - 'name' => 'archive_full', - 'effects' => array( - array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)), - array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 640, 'height' => 480)), - array('label' => t('Full screen'), 'name' => 'fullscreen', 'data' => array('fullscreen' => 1)), - ), - ), - ), - ), - ), - ), - ); - - // Allow any image style to be applied to the thumbnail. - foreach (image_styles() as $style_name => $image_style) { - $styles['file']['containers']['media_archive']['styles']['archive_thumbnail_' . $style_name] = array( - 'name' => 'archive_thumbnail_' . $style_name, - 'image_style' => $style_name, - 'effects' => array( - array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)), - ), - ); - } - - return $styles; -} - -/** - * Implements hook_styles_presets(). + * Implements hook_file_mimetype_mapping_alter(). + * + * Regster the video/archive mimetype. */ -function media_archive_styles_presets() { - $presets = array( - 'file' => array( - 'square_thumbnail' => array( - 'media_archive' => array( - 'archive_thumbnail_square_thumbnail', - ), - ), - 'thumbnail' => array( - 'media_archive' => array( - 'archive_thumbnail', - ), - ), - 'small' => array( - 'media_archive' => array( - 'archive_preview', - ), - ), - 'large' => array( - 'media_archive' => array( - 'archive_full', - ), - ), - 'original' => array( - 'media_archive' => array( - 'archive_full', - ), - ), - ), - ); - return $presets; +function media_archive_file_mimetype_mapping_alter(&$mapping) { + $mapping['mimetypes'][] = 'video/archive'; + $mapping['mimetypes'][] = 'image/archive'; } - - /** - * Implements hook_media_parse(). + * Implements hook_file_default_types_alter(). * - * @todo: this might be deprecated now that we have media_internet, - * but the hook is still being called in a couple places in media. + * Adds the video/archive fake mimetype to video files. */ -function media_archive_media_parse($url, $options = array()) { - $scheme = 'archive://'; - preg_match('@archive\.org/details/([^"\& ]+)@i', $url, $matches); - - - if (isset($matches[1])) { - $org = media_archive_embedcode_lookup($matches[1]); - return file_stream_wrapper_uri_normalize($scheme . 'v/' . $matches[1] . '/org/' . $org); - } - // @TODO: Validate for malformed archive urls. +function media_archive_file_default_types_alter(&$types) { + $types['video']->mimetypes[] = 'video/archive'; + $types['image']->mimetypes[] = 'image/archive'; } /** - * Implements hook_media_internet_providers(); + * Implements hook_ctools_plugin_api(). */ -function media_archive_media_internet_providers() { - $path = drupal_get_path('module', 'media_archive'); - return array( - 'MediaInternetArchiveHandler' => array( - 'title' => 'archive', - 'image' => $path . '/images/stream-archive.png' +function media_archive_ctools_plugin_api($owner, $api) { + static $api_versions = array( + 'file_entity' => array( + 'file_default_displays' => 1, ), ); -} - -class MediaInternetArchiveHandler extends MediaInternetBaseHandler { - public function claim($embedCode) { - if (media_archive_media_parse($embedCode)) { - return TRUE; - } - } - - public function validate() { - // @todo Media module currently fails when two files try to have the same - // URI, so catch that in the validation step. Some day, it would be nice - // to allow it, however. See http://drupal.org/node/952422. - $uri = media_archive_media_parse($this->embedCode); - $existing_files = file_load_multiple(array(), array('uri' => $uri)); - if (count($existing_files)) { - throw new MediaInternetValidationException(t('You have entered a URL for a video that is already in your library.')); - } - } - - public function save() { - $file = $this->getFileObject(); - file_save($file); - return $file; - } - - public function getFileObject() { - $uri = media_archive_media_parse($this->embedCode); - //@todo: this is terribly broken in some ways because the function is really - // made for local files which are 'real' - return file_uri_to_object($uri); - } - - /** - * Returns information about the media. See http://video.search.yahoo.com/mrss. - * - * @return - * If ATOM+MRSS information is available, a SimpleXML element containing - * ATOM and MRSS elements, as per those respective specifications. - * - * @todo Would be better for the return value to be an array rather than a - * SimpleXML element, but media_retrieve_xml() needs to be upgraded to - * handle namespaces first. - */ - - //http://archive.org/file/4035623?skin=rss - - public function getMRSS() { - $uri = media_archive_media_parse($this->embedCode); - $video_id = arg(1, file_uri_target($uri)); - $rss_url = url('http://gdata.archive.org/feeds/api/videos/' . $video_id, array('query' => array('v' => '2'))); - // @todo Use media_retrieve_xml() once it's upgraded to include elements - // from all namespaces, not just the document default namespace. - $entry = simplexml_load_file($rss_url); - return $entry; - } - - /** - * Returns information about the media. See http://www.oembed.com/. - * - * @return - * If oEmbed information is available, an array containing 'title', 'type', - * 'url', and other information as specified by the oEmbed standard. - * Otherwise, NULL. - */ - - //http://archive.org/oembed/?url=http://archive.org/file/12345 - - public function getOEmbed() { - $uri = media_archive_media_parse($this->embedCode); - $external_url = drupal_realpath($uri); - $oembed_url = url('http://archive.org/oembed', array('query' => array('url' => $external_url, 'format' => 'json'))); - $response = drupal_http_request($oembed_url); - if (!isset($response->error)) { - return drupal_json_decode($response->data); - } - } -} - -function media_archive_embedcode_lookup($video_id) { - - //http://www.archive.org/download/bavc-77620-dominotheory/bavc-77620-dominotheory_files.xml - - //Domino_Theory.mpeg - - // I hate this, but after reading http://data.agaric.com/node/2378 I'm - // begining to think there isn't an easier way - // if there isn't a better way, this needs to be done once and stored - $url = 'http://www.archive.org/download/' . $video_id . '/' . $video_id; - $rss_source = $url . '_files.xml'; - $rss = file_get_contents($rss_source); - - preg_match('/(.+)<\/original>/', $rss, $matches); - - if (isset($matches[1])) { - $info = pathinfo($matches[1]); - $file_name = basename($matches[1],'.'.$info['extension']); - return $file_name; + if (isset($api_versions[$owner][$api])) { + return array('version' => $api_versions[$owner][$api]); } } diff --git a/media_archive.wysiwyg.css b/media_archive.wysiwyg.css deleted file mode 100755 index 7dd1bde..0000000 --- a/media_archive.wysiwyg.css +++ /dev/null @@ -1,30 +0,0 @@ - -/** - * @file - * Overlay for Archive thumbnails in the media library browser. - */ -#media-browser .styles-container-media_archive { - /* Relative wrapper for the overlay. */ - position: relative; -} -#media-browser .styles-container-media_archive span { - /* Here's the overlay image. */ - background: url(images/stream-archive.png) no-repeat; - - /* Absolute positioning in the relative wrapper creates the overlay. */ - position: absolute; - - /* Size of the overlay */ - width: 69px; - height: 22px; - - /* Position of the overlay */ - left: 33px; - top: 80px; -} -#media-browser .styles-container-media_archive span:hover { - /* The */ - background-position: 0px -22px; -} -#media-browser .styles-container-media_archive img { -} diff --git a/providers/emaudio/archive_audio.inc b/providers/emaudio/archive_audio.inc deleted file mode 100644 index 7c42237..0000000 --- a/providers/emaudio/archive_audio.inc +++ /dev/null @@ -1,359 +0,0 @@ - The machine name of the provider. This must be the same as - * the base name of this filename, before the .inc extension. - * 'name' => The translated name of the provider. - * 'url' => The url to the main page for the provider. - * 'settings_description' => A description of the provider that will be - * posted in the admin settings form. - * 'supported_features' => An array of rows describing the state of certain - * supported features by the provider. These will be rendered in a table, - * with the columns being 'Feature', 'Supported', 'Notes'. In general, - * the 'Feature' column will give the name of the feature, 'Supported' - * will be Yes or No, and 'Notes' will give an optional description or - * caveats to the feature. - */ -function emaudio_archive_audio_info() { - $features = array( - array(t('Thumbnails'), t('No'), ''), - array(t('Autoplay'), t('Yes'), ''), - array(t('RSS attachment'), t('No'), ''), - ); - return array( - 'provider' => 'archive_audio', - 'name' => t('Archive'), - 'url' => EMAUDIO_ARCHIVE_MAIN_URL, - 'settings_description' => t('These settings specifically affect audio played from !archive. You can also read more about its !api.', array('!archive' => l(t('Archive.com'), EMAUDIO_ARCHIVE_MAIN_URL), '!api' => l(t("developer's API"), EMAUDIO_ARCHIVE_API_URL))), - 'supported_features' => $features, - ); -} - -/** - * hook emaudio_PROVIDER_settings - * This should return a subform to be added to the emaudio_settings() admin - * settings page. - * - * Note that a form field set will already be provided at $form['archive'], - * so if you want specific provider settings within that field set, you should - * add the elements to that form array element. - */ -function emaudio_archive_audio_settings() { - /* No Settings for this provider */ -} - -/** - * hook emaudio_PROVIDER_extract - * - * This is called to extract the audio code from a pasted URL or embed code. - * - * We'll be passed a URL or the embed code from a audio when an editor pastes - * that in the field's textfield. We'll need to either pass back an array of - * regex expressions to match, or do the matching ourselves and return the - * resulting audio code. - * - * @param $parse - * An optional string with the pasted URL or embed code. - * @return - * Either an array of regex expressions to be tested, or a string with the - * audio code to be used. If the hook tests the code itself, it should - * return either the string of the audio code (if matched), or an empty - * array. Otherwise, the calling function will handle testing the embed code - * against each regex string in the returned array. - */ -function emaudio_archive_audio_extract($parse = '') { - // Here we assume that a URL will be passed in the form of - // http://www.archive.org/details/text-audio-title - // or embed code in the form of - // $value) { - $item_files[$key]['name'] = $key; - } - - //Get playlist files only (.m3u files) - $files_playlists = array_filter($item_files, "_archive_audio_isplaylist"); - - //If there is no playlist then fail - if (is_null($files_playlists)) { - form_set_error($error_field, 'This archive.org item does not appear to have a playlist.'); - return $data; - } - - //We'll custom sort the array so we'll get first VBR playlists, then other - //playlists sorted by highest bitrate. Goal is to present the highest - //bitrate playlist offered for this item. - $data['playlists'] = $files_playlists; - $worked = uasort($files_playlists, "_archive_audio_playlistsort"); - $candidate_playlist = array_shift($files_playlists); - $data['playlist_file_used'] = $candidate_playlist; - - //Retrieve the playlist - $result = drupal_http_request('http://' . $server_url . $candidate_playlist['name']); - if (!empty($result->error)) { - form_set_error($error_field, 'The playlist for the item at archive.org could not be retrieved. The audio can not be displayed.'); - return $data; - } - $playlist = $result->data; - //We'll store it in the data element as it is used in our theme function to - //output the player later. - $data['playlist'] = explode("\n", trim($playlist)); - - return $data; -} - -/** - * Sort playlist files - */ -function _archive_audio_playlistsort($file1, $file2) { - $components1 = explode(" ", $file1['format']); - $components2 = explode(" ", $file2['format']); - if ($components1[0] == $components2[0]) { - return 0; - } - //We'll prefer the Variable Bitrate (VBR) - elseif ($components1[0] == "VBR") { - return -1; - } - elseif ($components2[0] == "VBR") { - return 1; - } - //Otherwise we'll look for the highest bitrate playlist - $br1 = (int)$components1[0]; - $br2 = (int)$components2[0]; - if ($br1 > $br2) { - return -1; - } - else { - return 1; - } -} - -/** - * Is this file a playlist (.m3u) file? - */ -function _archive_audio_isplaylist($file) { - if (substr($file['format'], -3, 3) == "M3U") { - return TRUE; - } - else { - return FALSE; - } -} - -/** - * hook emfield_PROVIDER_rss - */ -function emaudio_archive_audio_rss($item, $teaser = NULL) { - // Get size and mime type of first playlist file - $url = $item['data']['playlist'][0]; - $response = emfield_request_header('archive_audio', $url, $cached = FALSE); - if ($response->code == 200) { - $data['size'] = $response->headers['Content-Length']; - $data['mime'] = $response->headers['Content-Type']; - } - - if ($data['size']) { - $file = array(); - $file['filepath'] = $url; - $file['filesize'] = $data['size']; - $file['filemime'] = $data['mime']; - } - return $file; -} - -/** - * hook emaudio_PROVIDER_embedded_link($audio_code) - * returns a link to view the audio at the provider's site. - * @param $audio_code - * The string containing the audio item. - * @return - * A string containing the URL the audio item at the original provider's site. - */ -function emaudio_archive_audio_embedded_link($audio_code) { - return 'http://www.archive.org/details/'. $audio_code; -} - -/** - * Implementation of hook emaudio_archive_audio_audio(). - * - * This actually displays the full/normal-sized audio we want, usually on the default page view. - * - * @param $embed - * The audio code for the audio to embed. - * @param $width - * The width to display the audio. - * @param $height - * The height to display the audio. - * @param $field - * The field info from the requesting node. - * @param $item - * The actual content from the field. - * @return - * The html of the embedded audio. - */ -function emaudio_archive_audio_audio($embed = NULL, $width = 0, $height = 0, $field = NULL, $item, $node, $autoplay) { - $output = theme('emaudio_archive_audio_flash', $embed, $width, $height, $field, $item, $node, $autoplay); - - return $output; -} - -/** - * The embedded flash displaying the archive audio. - */ -function theme_emaudio_archive_audio_flash($embed, $width, $height, $field, $item, $node, $autoplay) { - $output = ''; - if ($item) { - $flowplayerplaylist = _media_archive_flowplayer_playlist($item['data']['playlist']); - $controlplaylist = (count($item['data']['playlist'])>1) ? "true" : "false"; - $clipautoplay = $autoplay ? 'true' : 'false'; - $output = << - -EOD; - } - return $output; -} - -/** - * Implementation of hook_emfield_subtheme(). - */ -function emaudio_archive_audio_emfield_subtheme() { - return array( - 'emaudio_archive_audio_flash' => array( - 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'field' => NULL, 'data' => NULL, 'node' => NULL, 'autoplay' => NULL), - 'file' => 'providers/emaudio/archive_audio.inc', - 'path' => drupal_get_path('module', 'media_archive'), - ) - ); -} diff --git a/providers/emvideo/archive.inc b/providers/emvideo/archive.inc deleted file mode 100644 index dc7577e..0000000 --- a/providers/emvideo/archive.inc +++ /dev/null @@ -1,407 +0,0 @@ - The machine name of the provider. This must be the same as - * the base name of this filename, before the .inc extension. - * 'name' => The translated name of the provider. - * 'url' => The url to the main page for the provider. - * 'settings_description' => A description of the provider that will be - * posted in the admin settings form. - * 'supported_features' => An array of rows describing the state of certain - * supported features by the provider. These will be rendered in a table, - * with the columns being 'Feature', 'Supported', 'Notes'. In general, - * the 'Feature' column will give the name of the feature, 'Supported' - * will be Yes or No, and 'Notes' will give an optional description or - * caveats to the feature. - */ -function emvideo_archive_info() { - $features = array( - array(t('Autoplay'), t('Yes'), ''), - array(t('RSS Attachment'), t('Yes'), ''), - array(t('Thumbnails'), t('Yes'), t('')), - array(t('Full screen mode'), t('Yes'), t('You may customize the player to enable or disable full screen playback. Full screen mode is enabled by default.')), - ); - return array( - 'provider' => 'archive', - 'name' => t('archive.org'), - 'url' => EMVIDEO_ARCHIVE_MAIN_URL, - 'settings_description' => t('These settings specifically affect videos displayed from !archive. You can also read more about its !api.', array('!archive' => l(t('Archive.com'), EMVIDEO_ARCHIVE_MAIN_URL), '!api' => l(t("developer's API"), EMVIDEO_ARCHIVE_API_URL))), - 'supported_features' => $features, - ); -} - -/** - * hook emvideo_PROVIDER_settings - * This should return a subform to be added to the emvideo_settings() admin - * settings page. - * - * Note that a form field set will already be provided at $form['archive'], - * so if you want specific provider settings within that field set, you should - * add the elements to that form array element. - */ -function emvideo_archive_settings() { - // We'll add a field set of player options here. You may add other options - // to this element, or remove the field set entirely if there are no - // user-configurable options allowed by the archive provider. - /* $form['archive']['player_options'] = array( - '#type' => 'fieldset', - '#title' => t('Embedded video player options'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - // This is an option to set the video to full screen. You should remove this - // option if it is not provided by the archive provider. - $form['archive']['player_options']['emvideo_archive_full_screen'] = array( - '#type' => 'checkbox', - '#title' => t('Allow fullscreen'), - '#default_value' => variable_get('emvideo_archive_full_screen', 1), - '#description' => t('Allow users to view video using the entire computer screen.'), - ); - - return $form;*/ -} - -/** - * hook emvideo_PROVIDER_extract - * - * This is called to extract the video code from a pasted URL or embed code. - * - * We'll be passed a URL or the embed code from a video when an editor pastes - * that in the field's textfield. We'll need to either pass back an array of - * regex expressions to match, or do the matching ourselves and return the - * resulting video code. - * - * @param $parse - * An optional string with the pasted URL or embed code. - * @return - * Either an array of regex expressions to be tested, or a string with the - * video code to be used. If the hook tests the code itself, it should - * return either the string of the video code (if matched), or an empty - * array. Otherwise, the calling function will handle testing the embed code - * against each regex string in the returned array. - */ -function emvideo_archive_extract($parse = '') { - // Here we assume that a URL will be passed in the form of - // http://www.archive.org/video/text-video-title - // or embed code in the form of $value) { - $item_files[$key]['name'] = $key; - } - - //Get only .mp4 files - $files_play = array_filter($item_files, "_archive_video_toplay"); - - //If there is no playlist then fail - if (is_null($files_play)) { - form_set_error($error_field, 'This archive.org item does not appear to have files to play.'); - return $data; - } - - //Create a playlist suitable for feeding to player - foreach ($files_play as $file => $file_data) { - $data['playlist'][] = $download_url . $file; - } - - // Add the thumbnail data. - $data['thumbnail'] = 'http://www.archive.org/download/'. $item['value'] .'/format=Thumbnail?.jpg'; - - return $data; -} - -/** - * Is this a 512Kb MPEG4 file? - */ -function _archive_video_toplay($file) { - if ($file['format'] == "512Kb MPEG4") { - return TRUE; - } - else { - return FALSE; - } -} - -/** - * hook emvideo_PROVIDER_duration($item) - * Returns the duration of the video in seconds. - * @param $item - * The video item itself, which needs the $data array. - * @return - * The duration of the video in seconds. - */ -function emvideo_archive_duration($item) { - if (!isset($item['data']['emvideo_archive_version'])) { - $item['data'] = emvideo_archive_data(NULL, $item); - } - return isset($item['data']['metadata']['RUNTIME'][0]) ? emvideo_convert_to_seconds($item['data']['metadata']['RUNTIME'][0]) : 0; -} - -/** - * hook emvideo_PROVIDER_rss - * - * This attaches a file to an RSS feed. - */ -function emvideo_archive_rss($item, $teaser = NULL) { - if ($item['value']) { - $file['thumbnail']['filepath'] = $item['data']['thumbnail']; - - return $file; - } -} - -/** - * hook emvideo_PROVIDER_embedded_link($video_code) - * returns a link to view the video at the provider's site. - * @param $video_code - * The string containing the video to watch. - * @return - * A string containing the URL to view the video at the original provider's site. - */ -function emvideo_archive_embedded_link($video_code) { - return 'http://www.archive.org/details/'. $video_code; -} - -/** - * The embedded flash displaying the archive video. - */ -function theme_emvideo_archive_flash($item, $width, $height, $autoplay) { - $output = ''; - if ($item['embed']) { - $flowplayerplaylist = _media_archive_flowplayer_playlist($item['data']['playlist']); - $controlplaylist = (count($item['data']['playlist'])>1) ? "true" : "false"; - $clipautoplay = $autoplay ? 'true' : 'false'; - $output = << -EOD; - } - return $output; -} - -/** - * hook emvideo_PROVIDER_thumbnail - * Returns the external url for a thumbnail of a specific video. - * @param $field - * The field of the requesting node. - * @param $item - * The actual content of the field from the requesting node. - * @return - * A URL pointing to the thumbnail. - */ -function emvideo_archive_thumbnail($field, $item, $formatter, $node, $width, $height) { - // In this demonstration, we previously retrieved a thumbnail using oEmbed - // during the data hook. - return $item['data']['thumbnail']; -} - -/** - * hook emvideo_PROVIDER_video - * This actually displays the full/normal-sized video we want, usually on the - * default page view. - * @param $embed - * The video code for the video to embed. - * @param $width - * The width to display the video. - * @param $height - * The height to display the video. - * @param $field - * The field info from the requesting node. - * @param $item - * The actual content from the field. - * @return - * The html of the embedded video. - */ -function emvideo_archive_video($embed, $width, $height, $field, $item, $node, $autoplay) { - $output = theme('emvideo_archive_flash', $item, $width, $height, $autoplay); - return $output; -} - -/** - * hook emvideo_PROVIDER_video - * - * This actually displays the preview-sized video we want, commonly for the - * teaser. - * @param $embed - * The video code for the video to embed. - * @param $width - * The width to display the video. - * @param $height - * The height to display the video. - * @param $field - * The field info from the requesting node. - * @param $item - * The actual content from the field. - * @return - * The html of the embedded video. - */ -function emvideo_archive_preview($embed, $width, $height, $field, $item, $node, $autoplay) { - $output = theme('emvideo_archive_flash', $item, $width, $height, $autoplay); - return $output; -} - -/** - * Implementation of hook_emfield_subtheme(). - * This returns any theme functions defined by this provider. - */ -function emvideo_archive_emfield_subtheme() { - $themes = array( - 'emvideo_archive_flash' => array( - 'arguments' => array('item' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL), - 'file' => 'providers/archive.inc', - // If you don't provide a 'path' value, then it will default to - // the emvideo.module path. Obviously, replace 'emarchive' with - // the actual name of your custom module. - //'path' => drupal_get_path('module', 'emarchive'), - ) - ); - return $themes; -} - -/** - * Implement hook_emvideo_PROVIDER_content_generate(). - */ -function emvideo_archive_content_generate() { - return array( - 'http://www.archive.org/details/DrupalconDc2009-DrupalMultimedia', - 'http://www.archive.org/details/DrupalconBoston2008-DrupalMultimedia', - 'http://www.archive.org/details/drupal_song_dcamp_pune_09', - 'http://www.archive.org/details/Drupal.Peru_DrupalSong20090718', - ); -}