You are here

class MediaInternetOEmbedHandler in oEmbed 7.0

Same name and namespace in other branches
  1. 8 MediaInternetOEmbedHandler.inc \MediaInternetOEmbedHandler
  2. 7 MediaInternetOEmbedHandler.inc \MediaInternetOEmbedHandler

Implementation of MediaInternetBaseHandler.

Hierarchy

Expanded class hierarchy of MediaInternetOEmbedHandler

See also

hook_media_internet_providers().

File

./MediaInternetOEmbedHandler.inc, line 20
MediaInternetOEmbedHandler.inc

View source
class MediaInternetOEmbedHandler extends MediaInternetBaseHandler {
  public $fileObject;

  /**
   * Claim this URL.
   */
  public function claim($embedCode) {
    $matches = array();
    if (oembed_get_provider($embedCode, $matches)) {
      return TRUE;
    }
  }

  /**
   * File should not validate if we cannot fetch valid oEmbed data.
   */
  public function validate() {
    $file = $this
      ->getFileObject();
    $validators = array(
      'oembed_file_validator_type' => array(),
    );
    $errors = file_validate($file, $validators);
    foreach ($errors as $error) {
      throw new MediaInternetValidationException($error);
    }
  }

  /**
   * Returns a file object which can be used for validation
   *
   * @return StdClass
   */
  public function getFileObject() {
    if (!$this->fileObject) {
      $file = oembed_url_to_file($this->embedCode);
      $this->fileObject = $file;
    }
    return $this->fileObject;
  }

  /**
   * Returns an array representation of the oEmbed data, or NULL on failure.
   *
   * An example project that calls this method is Media Browser Plus
   * (http://drupal.org/project/media_browser_plus). Other projects may do so
   * in the future.
   */
  public function getOEmbed() {
    $embed = oembed_get_data($this->embedCode);
    return $embed ? (array) $embed : NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaInternetOEmbedHandler::$fileObject public property
MediaInternetOEmbedHandler::claim public function Claim this URL.
MediaInternetOEmbedHandler::getFileObject public function Returns a file object which can be used for validation
MediaInternetOEmbedHandler::getOEmbed public function Returns an array representation of the oEmbed data, or NULL on failure.
MediaInternetOEmbedHandler::validate public function File should not validate if we cannot fetch valid oEmbed data.