You are here

MediaInternetFlickrHandler.inc in Media: Flickr 7.2

Same filename and directory in other branches
  1. 7 includes/MediaInternetFlickrHandler.inc

Extends the MediaInternetBaseHandler class to handle Flickr images.

File

includes/MediaInternetFlickrHandler.inc
View source
<?php

/**
 * @file
 * Extends the MediaInternetBaseHandler class to handle Flickr images.
 */

/**
 * Implementation of MediaInternetBaseHandler.
 *
 * @see hook_media_internet_providers().
 */
class MediaInternetFlickrHandler extends MediaInternetBaseHandler {
  public function parse($embedCode) {
    return media_flickr_media_parse($embedCode);
  }
  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);

    // Try to default the file name to the image's title.
    if (empty($file->fid) && ($info = $this
      ->getOEmbed())) {
      $file->filename = truncate_utf8($info['title'], 255);
    }
    return $file;
  }

  /**
   * 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.
   */
  public function getOEmbed() {
    $uri = $this
      ->parse($this->embedCode);
    $external_url = drupal_realpath($uri);
    $oembed_url = url('https://www.flickr.com/services/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);
    }
    else {
      throw new Exception("Error Processing Request. (Error: {$response->code}, {$response->error})");
      return;
    }
  }

}

Classes

Namesort descending Description
MediaInternetFlickrHandler Implementation of MediaInternetBaseHandler.