'media_flickr_ajax_parse', // 'access arguments' => array('access content'), // ); $items = array(); $items['admin/config/media/media_flickr'] = array( 'title' => 'Flickr settings', 'description' => 'Configure required settings for Media: Flickr.', 'page callback' => 'drupal_get_form', 'page arguments' => array('media_flickr_settings_form'), 'access arguments' => array('administer media'), 'file' => 'media_flickr.admin.inc', ); $items['media/add/media_flickr'] = array( 'title' => 'Add media from Flickr', 'page callback' => 'drupal_get_form', 'page arguments' => array('media_flickr_add'), 'access arguments' => array('administer media'), 'type' => MENU_LOCAL_ACTION, 'file' => 'media_flickr.admin.inc', 'weight' => -1, ); $items['admin/content/media/add/media_flickr'] = $items['media/add/media_flickr']; return $items; } /** * Create stream wrapper for Flickr videos. */ function media_flickr_stream_wrappers() { stream_wrapper_register('flickr', 'MediaFlickrStreamWrapper'); return array( 'flickr' => array( 'name' => t('Flickr photos'), 'class' => 'MediaFlickrStreamWrapper', 'description' => t('Photos provided by Flickr.'), ), ); } /** * Implements hook_theme(). */ function media_flickr_theme($existing, $type, $theme, $path) { return array( 'media_flickr_preview_style_old' => array( 'variables' => array('style' => NULL), ), 'media_flickr_preview_style' => array( 'variables' => array('field_type' => NULL, 'container_name' => NULL, 'style_name' => NULL), ), 'media_flickr_field_formatter_styles' => array( 'variables' => array('element' => NULL, 'style' => NULL), ), 'media_flickr_embed' => array( 'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL), ), 'media_flickr_styles' => array( 'variables' => array('element' => NULL, 'style' => NULL), ), ); } function theme_media_flickr_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_flickr_embed', $variables); } /** * Determine if a stream belongs to Media: Flickr. */ function media_flickr_formatter_filter($variables) { if (isset($variables['object'])) { $object = $variables['object']; return (file_uri_scheme($object->uri) == 'flickr')/* && ($object->filemime == 'application/octet-stream')*/; } } function theme_media_flickr_preview_style($variables) { $variables['uri'] = variable_get('media_flickr_preview_uri', 'flickr://u/esmerel/p/3910304052'); return theme('media_flickr_embed', $variables); } function theme_media_flickr_styles($variables) { $style = $variables['style']; $variables['file'] = $variables['object']; $variables['uri'] = $variables['object']->uri; $variables['style_name'] = $style['name']; return theme('media_flickr_embed', $variables); } function theme_media_flickr_embed($variables) { $preset_name = $variables['preset_name']; $preset = styles_containers_available_styles('file', 'media_flickr', $preset_name); if (!empty($preset)) { // Build the URL for display. $uri = $variables['uri']; $wrapper = file_stream_wrapper_get_instance_by_uri($uri); $parts = $wrapper->get_parameters(); $url = 'http://flickr.com/photos/' . check_plain($parts['u']) . '/' . check_plain($parts['p']); $fullscreen_value = $autoplay = 'false'; $in_browser = $thumbnail = FALSE; $width = $height = 0; foreach ($preset['effects'] as $effect) { switch ($effect['name']) { case 'resize': $width = isset($effect['data']['width']) ? $effect['data']['width'] : NULL; $height = isset($effect['data']['height']) ? $effect['data']['height'] : NULL; break; } } 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['browser']) && $override['browser']) { $in_browser = TRUE; } } $attributes = array(); if ($width) { $attributes['width'] = $width; } if ($height) { $attributes['height'] = $height; } $output = theme('image', array( 'path' => media_flickr_image_url($parts['p'], $width, $height), 'alt' => $variables['alt'], 'title' => $variables['title'], 'attributes' => $attributes, 'getsize' => FALSE, )); if ($in_browser) { // Add an overlay that says 'Flickr' to media library browser thumbnails. $output .= ''; } return $output; } } /** * Based on the Photo ID of a Flickr image, this will return the URL to the * image itself. * * @param $photo_code * The Flickr photo code. * @param $width * @param $height * We use this to guess the actual size provided by Flickr. * @param boolean $refresh * Optional; if TRUE, then we'll force a new load of the XML. Otherwise, * a cached version will be retrieved if possible. */ function media_flickr_image_url($photo_code, $width = 0, $height = 0, $refresh = FALSE) { module_load_include('inc', 'media_flickr', 'media_flickr.utilities'); return _media_flickr_photo_url($photo_code, $width, $height, $refresh); } /** * Implements hook_media_parse(). */ function media_flickr_media_parse($url, $options = array()) { $scheme = 'flickr://'; preg_match('@flickr\.com/photos/([^/]*)/(\d+)@i', $url, $matches); if (isset($matches[1]) && isset($matches[2])) { return file_stream_wrapper_uri_normalize($scheme . 'u/' . $matches[1] . '/p/' . $matches[2]); } // @TODO: Validate for malformed flickr urls. } /** * Implements hook_media_internet_providers(); */ function media_flickr_media_internet_providers() { $path = drupal_get_path('module', 'media_flickr'); return array( 'MediaInternetFlickrHandler' => array( 'title' => 'youtube', 'image' => $path . '/images/stream-flickr.png' ), ); } class MediaInternetFlickrHandler extends MediaInternetBaseHandler { public function claim($embedCode) { if (media_flickr_media_parse($embedCode)) { return TRUE; } } public function save() { $file = $this->getFileObject(); file_save($file); return $file; } public function getFileObject() { $uri = media_flickr_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); } } /** * @DEPRECATED * Implements hook_styles_containers(). */ function media_flickr_styles_containers() { return array( 'file' => array( 'containers' => array( 'media_flickr' => array( 'label' => t('Flickr Styles'), 'data' => array( 'streams' => array( 'flickr', ), 'mimetypes' => array( // @TODO: Add image mimetypes here... // 'application/octet-stream', ), ), 'weight' => 0, 'filter callback' => 'media_flickr_formatter_filter', 'themes' => array( 'field_formatter_styles' => 'media_flickr_field_formatter_styles', 'styles' => 'media_flickr_styles', 'preview' => 'media_flickr_preview_style', ), 'description' => t('Flickr Styles will display embedded Flickr photos to your choosing, such as by resizing. You can !manage.', array('!manage' => l(t('manage your Flickr styles here'), 'admin/config/media/media-flickr-styles'))), ), ), ), ); } /** * @DEPRECATED * Implements hook_styles_styles(). */ function media_flickr_styles_styles() { return array( 'file' => array( 'containers' => array( 'media_flickr' => array( 'styles' => array( 'flickr_thumbnail' => array( 'name' => 'flickr_thumbnail', 'effects' => array( array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 100, 'height' => 75)), ), ), 'flickr_small' => array( 'name' => 'flickr_small', 'effects' => array( array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 220)), ), ), 'flickr_large' => array( 'name' => 'flickr_large', 'effects' => array( array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 640)), ), ), 'flickr_original' => array( 'name' => 'flickr_original', 'effects' => array( ), ), ), ), ), ), ); } /** * @DEPRECATED * Implements hook_styles_presets(). */ function media_flickr_styles_presets() { $presets = array( 'file' => array( 'square_thumbnail' => array( 'media_flickr' => array( 'flickr_thumbnail', ), ), 'thumbnail' => array( 'media_flickr' => array( 'flickr_thumbnail', ), ), 'small' => array( 'media_flickr' => array( 'flickr_small', ), ), 'large' => array( 'media_flickr' => array( 'flickr_large', ), ), 'original' => array( 'media_flickr' => array( 'flickr_original', ), ), ), ); return $presets; }