You are here

emvideo_wattv.module in Asset 7

Emvideo wattv module.

File

modules/emvideo/modules/emvideo_wattv/emvideo_wattv.module
View source
<?php

/**
 * @file
 * Emvideo wattv module.
 */

/**
 * Implements hook_emvideo_parse().
 */
function emvideo_wattv_emvideo_parse($data) {
  $ret = FALSE;
  $page_url = '';

  // Note, as we are searching in whole string, possible to find that url within embed and it will works.
  if (preg_match('@http://www\\.wat\\.tv/video/(.+?\\.html)@i', $data, $matches)) {
    $page_url = 'http://www.wat.tv/video/' . $matches[1];
  }
  elseif (preg_match('@http://wat\\.tv/p/([0-9a-z]+)@i', $data, $matches)) {
    $page_url = 'http://wat.tv/p/' . $matches[1];
  }
  if ($page_url) {
    $video_page_data = @file($page_url);
    if ($video_page_data) {
      $video_page_data = implode("\n", $video_page_data);
      $matches = array();
      if (preg_match('@<meta name="twitter:player" content="(.*?)"@i', $video_page_data, $matches)) {
        $ret = array(
          'source' => $matches[1],
          'provider' => 'wattv',
        );
        $matches = array();

        // @todo: We have a problem with different https/http urls for snapshot. Seems we need redo whole storage system.
        if (preg_match('@<meta property="og:image" content="(.*?)"@i', $video_page_data, $matches)) {
          $ret['snapshot'] = $matches[1];
        }
      }
    }
  }
  elseif (preg_match('@<iframe src="(.*?)"@i', $data, $matches)) {
    $ret = array(
      'source' => $matches[1],
      'provider' => 'wattv',
    );
  }
  elseif (preg_match('@src="http://www\\.wat\\.tv/swf2/([0-9a-z]+)"@i', $data, $matches)) {
    $ret = array(
      'source' => 'http://www.wat.tv/swf2/' . $matches[1],
      'provider' => 'wattv',
    );
  }
  return $ret;
}

/**
 * Implements hook_emvideo_emcode().
 */
function emvideo_wattv_emvideo_emcode($params) {
  $output = FALSE;

  // We handle here only new type of embed, old will fallback into flash object rendering.
  if ($params['provider'] == 'wattv' && strpos($params['source'], 'http://www.wat.tv/swf2/') !== 0) {
    $output = '<iframe src="' . $params['source'] . '" width="' . $params['width'] . '" height="' . $params['height'] . '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
  }
  return $output;
}

Functions

Namesort descending Description
emvideo_wattv_emvideo_emcode Implements hook_emvideo_emcode().
emvideo_wattv_emvideo_parse Implements hook_emvideo_parse().