[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/video/ -> video_formatter.inc (source)

   1  <?php
   2  /**
   3   * @file
   4   * Video formatter hooks and callbacks.
   5   */
   6  
   7  /*
   8   * Default video cck formatter.  Makes sure the video being displayed exists, has been converted (if in que).
   9   * If not or the video is processed, then it will get the default player for the specific video type for output.
  10   */
  11  function theme_video_formatter_video_plain($element) {
  12    if (empty($element['#item']['fid']))
  13      return '';
  14    // Get our field information to determine if we are checking conversion
  15    $field = content_fields($element['#field_name'], $element['#type_name']);
  16    if (!empty($field['list_field']) && !$element['#item']['list'])
  17      return '';
  18    // Only needs to be ran if they are converting videos
  19  
  20    if (!empty($field['widget']['autoconversion']) && empty($element['#item']['data']['bypass_autoconversion'])) {
  21      module_load_include('inc', 'video', '/includes/conversion');
  22      $conversion = new video_conversion;
  23      $video = $conversion->load_job($element['#item']['fid']);
  24      if ($video->video_status == VIDEO_RENDERING_ACTIVE || $video->video_status == VIDEO_RENDERING_PENDING) {
  25        return theme('video_inprogress');
  26      }
  27      else if ($video->video_status == VIDEO_RENDERING_FAILED) {
  28        return theme('video_encoding_failed');
  29      }
  30    }
  31    return video_get_player($element);
  32  }
  33  
  34  /*
  35   * Renders the video thumbnail as a link to the node page.
  36   */
  37  
  38  function theme_video_formatter_video_nodelink($element, $imagecache = FALSE) {
  39    // Inside a view $element may contain null data. In that case, just return.
  40    if (empty($element['#item']['fid']))
  41      return '';
  42    //setup our thumbnail object
  43    module_load_include('inc', 'video', '/includes/video_helper');
  44    $video_helper = new video_helper;
  45    $thumbnail = $video_helper->thumbnail_object($element);
  46    //get our themed image
  47    $image = theme('video_image', $thumbnail, $thumbnail->alt, $thumbnail->title, '', TRUE, $imagecache);
  48    $class = 'popups video video-nodelink video-' . $element['#field_name'];
  49    return l($image, 'node/' . $element['#node']->nid, array('attributes' => array('class' => $class), 'html' => TRUE));
  50  }
  51  
  52  /*
  53   * Renders the video thumbnail with no inbuilt node link.
  54   */
  55  
  56  function theme_video_formatter_video_nonodelink($element, $imagecache = FALSE) {
  57    // Inside a view $element may contain null data. In that case, just return.
  58    if (empty($element['#item']['fid']))
  59      return '';
  60    //setup our thumbnail object
  61    module_load_include('inc', 'video', '/includes/video_helper');
  62    $video_helper = new video_helper;
  63    $thumbnail = $video_helper->thumbnail_object($element);
  64    // return the themed image
  65    $output = '<div class="popups video video-nonodelink video-' . $element['#field_name'] . '">';
  66    $output .= theme('video_image', $thumbnail, $thumbnail->alt, $thumbnail->title, null, TRUE, $imagecache);
  67    $output .= '</div>';
  68    return $output;
  69  }
  70  
  71  /*
  72   * Renders the video thumbnail.
  73   */
  74  
  75  function theme_video_formatter_video_thumbnail($element, $imagecache = FALSE) {
  76    // Inside a view $element may contain null data. In that case, just return.
  77    if (empty($element['#item']['fid']))
  78      return '';
  79    //setup our thumbnail object
  80    module_load_include('inc', 'video', '/includes/video_helper');
  81    $video_helper = new video_helper;
  82    $thumbnail = $video_helper->thumbnail_object($element);
  83    //get our themed image
  84    return theme('video_image', $thumbnail, $thumbnail->alt, $thumbnail->title, '', TRUE, $imagecache);
  85  }
  86  
  87  /*
  88   * Renders the video thumbnail linked to the absolute filepath of the video.  Colorbox is introduced to handle
  89   * the video in an overlay.
  90   *
  91   * @todo Very unstable, need better methods of integration.  Seems hackish right now to find out what flv player is being
  92   * used.  We are also using jmedia for all other filetypes.
  93   */
  94  
  95  function theme_video_formatter_video_colorbox($element, $imagecache = FALSE) {
  96    global $base_path;
  97    if (!module_exists('colorbox')) {
  98      drupal_set_message(t('You must download and enable !colorbox for this formatter.', array('!colorbox' => l(t('Colorbox'), 'http://www.drupal.org/project/colorbox'))), 'error');
  99      return theme('video_formatter_video_nodelink', $element);
 100    }
 101  
 102    // Inside a view $element may contain null data. In that case, just return.
 103    if (empty($element['#item']['fid']))
 104      return '';
 105  
 106    //load up our media plugins
 107    drupal_add_js(drupal_get_path('module', 'video') . '/js/jquery.media.js');
 108    drupal_add_js(drupal_get_path('module', 'video') . '/js/jquery.metadata.js');
 109    drupal_add_js(drupal_get_path('module', 'video') . '/js/flowplayer-3.2.0.min.js');
 110  
 111    //setup our video object
 112    module_load_include('inc', 'video', '/includes/video_helper');
 113    $video_helper = new video_helper;
 114    $video = $video_helper->video_object($element);
 115  
 116    $action = swftools_get_action($video->filepath);
 117    $player = swftools_get_player($action);
 118    $path = explode("_", $player);
 119    $player_url = $base_path . swftools_get_player_path() . '/' . $path[0] . '/' . variable_get($player . '_file', '');
 120    if (stristr($player, 'flowplayer')) {
 121      $player = 'flowplayer';
 122    }
 123    //add our default settings to the Drupal.settings object
 124    $settings = array('video' => array(
 125        'flvplayer' => $player_url,
 126        'autoplay' => $video->autoplay,
 127        'autobuffer' => $video->autobuffering,
 128        'player' => $player,
 129        ));
 130    drupal_add_js($settings, 'setting');
 131    $image = theme('video_image', $video->thumbnail, $video->thumbnail->alt, $video->thumbnail->title, '', TRUE, $imagecache);
 132    $class = 'video-box video-' . $element['#field_name'] . '{width:\'' . $video->player_width . 'px\', height:\'' . $video->player_height . 'px\', player:\'' . $player . '\'}';
 133    return l($image, $video->files->{$video->player}->url, array('attributes' => array('class' => $class), 'html' => TRUE));
 134  }
 135  
 136  /*
 137   * We are using the jMedia library to output our video files.
 138   *
 139   * @todo Does not work with flv files as this requires an actual flv player.  Need to figure out how to best integrate the player
 140   * into this function.
 141   *
 142   * We are outputing an anchor to the videofile.  The jMedia functions will overtake this anchor and setup our object/embed tags.
 143   */
 144  
 145  function theme_video_formatter_video_media_js($element) {
 146    //#913928
 147    $field = content_fields($element['#field_name'], $element['#type_name']);
 148    if (!empty($field['list_field']) && !$element['#item']['list'])
 149      return '';
 150  
 151    drupal_add_js(drupal_get_path('module', 'video') . '/js/jquery.media.js');
 152    drupal_add_js(drupal_get_path('module', 'video') . '/js/jquery.metadata.js');
 153    //setup our video object
 154    module_load_include('inc', 'video', '/includes/video_helper');
 155    $video_helper = new video_helper;
 156    $video = $video_helper->video_object($element);
 157    //lets output the link to be overtaken by jmedia
 158    $link = l($video->filename, $video->files->{$video->player}->url, array('attributes' => array('class' => 'jmedia {width: ' . $video->player_width . ', height: ' . $video->player_height . ', autoplay: ' . $video->autoplay . '}')));
 159    return $link;
 160  }
 161  
 162  /**
 163   * Displays a "encoding in progress message"
 164   */
 165  function theme_video_inprogress() {
 166    return '<div class="video-ffmpeg-helper-inprogress">' . t('This video is currently being processed. Please wait.') . '</div>';
 167  }
 168  
 169  /**
 170   * Display an "encoding failed" message"
 171   */
 172  function theme_video_encoding_failed() {
 173    return '<div class="video-ffmpeg-helper-encoding-failed">' . t('The video conversion process has failed. You might want to submit a simpler video format like <em>mpeg</em> or <em>divx avi</em>.<br />If the problem persists please contact website administrators.') . '</div>';
 174  }
 175  
 176  /**
 177   * Callback to FLV
 178   */
 179  function theme_video_flv($video, $node) {
 180    if ($video->flash_player == 'swftools') {
 181      $options = array(
 182        'params' => array(
 183          'width' => $video->player_width,
 184          'height' => $video->player_height,
 185        ),
 186        'othervars' => array(
 187          //@todo: swftools bug, can't enable this until they fix their pathing for the images.
 188          'image' => $video->thumbnail->swfthumb,
 189        ),
 190      );
 191      $themed_output = swf($video->files->{$video->player}->url, $options);
 192    }
 193    elseif ($video->flash_player == 'flowplayer') {
 194      $extraspace = intval(variable_get('video_flowplayer_extraplayerheight', 24));
 195  
 196      // kjh: use a playlist to display the thumbnail if not auto playing
 197      if (!$video->autoplay && $video->thumbnail->url) {
 198        $options = array(
 199          'playlist' => array($video->thumbnail->url,
 200            array('url' => urlencode($video->files->{$video->player}->url),
 201              'autoPlay' => $video->autoplay,
 202              'autoBuffering' => $video->autobuffering,
 203            ),),);
 204      }
 205      else {
 206        $options = array(
 207          'clip' => array('url' => urlencode($video->files->{$video->player}->url),
 208            'autoPlay' => $video->autoplay,
 209            'autoBuffering' => $video->autobuffering,
 210          ),);
 211      }
 212  
 213      $themed_output = theme(
 214          'flowplayer', $options, $video->formatter,
 215          array('style' => 'width:' . $video->player_width . 'px; height:' . ($video->player_height + $extraspace) . 'px;')
 216      );
 217    }
 218    else {
 219      $themed_output = t('No flash player has been setup. ' . l(t('Please select a player to play Flash videos.'), 'admin/settings/video/players'));
 220    }
 221    return theme('video_play_flv', $video, $node, $themed_output);
 222  }
 223  
 224  /**
 225   * Play HTML5 videos
 226   */
 227  function theme_video_html5($video, $node) {
 228    $themed_output = NULL;
 229    $video->html5_player = variable_get('video_extension_' . $video->player . '_html5_player', '');
 230    switch ($video->html5_player) {
 231      case 'video':
 232        return theme('video_play_html5', $video, $node, $themed_output);
 233  
 234      case 'videojs':
 235        $items = _video_object_to_array($video->files);
 236        
 237        foreach($items as &$item) {
 238          if (isset($item['url'])) {
 239            // The following is needed for Zencoder / S3 files
 240            $item['filepath'] = $item['url'];
 241          }
 242          else {
 243            // The following is needed because the VideoJS module doesn't create a full path by itself
 244            $item['filepath'] = $item['url'] = file_create_url(drupal_urlencode($item['url']));
 245          }
 246        }
 247        
 248        $items['thumbnail'] = (array) $video->thumbnail;
 249        
 250        $attributes = array(
 251          'width' => $video->player_width,
 252          'height' => $video->player_height,
 253        );
 254        
 255        return theme('videojs', $items, 'video-'. $video->fid, $attributes);
 256  
 257      default:
 258        return t('No HTML5 player has been setup. ' . l(t('Please select a player to play HTML5 videos.'), 'admin/settings/video/players'));
 259    }
 260  }
 261  
 262  /**
 263   * Helper funcations
 264   */
 265  function _video_object_to_array($data) {
 266    if (is_array($data) || is_object($data)) {
 267      $result = array();
 268      foreach ($data as $key => $value) {
 269        $result[$key] = _video_object_to_array($value);
 270      }
 271      return $result;
 272    }
 273    return $data;
 274  }
 275  
 276  function theme_video_formatter_imagecache($element) {
 277    // Inside a view $element may contain NULL data. In that case, just return.
 278    if (empty($element['#item']['fid'])) {
 279      return '';
 280    }
 281  
 282    // Extract the preset name from the formatter name.
 283    list($namespace, $theme_function) = explode('__', $element['#formatter'], 2);
 284    if ($preset = imagecache_preset_by_name($namespace)) {
 285      $element['imagecache_preset'] = $namespace;
 286    }
 287    //return $theme_function;
 288    return theme('video_formatter_' . $theme_function, $element, TRUE);
 289  }
 290  
 291  /**
 292   * Get the object for the suitable player for the parameter resource
 293   */
 294  function video_get_player($element) {
 295    // Setup our node object to be passed along with the player.
 296    $node = $element['#node'];
 297    // Setup our video object
 298    module_load_include('inc', 'video', '/includes/video_helper');
 299    $video_helper = new video_helper;
 300    $video = $video_helper->video_object($element);
 301  
 302    if ($video == NULL) {
 303      return '';
 304    }
 305  
 306    // Lets spit out our theme based on the extension
 307    $defaults = video_video_extensions();
 308    $theme_function = variable_get('video_extension_'. $video->player, $defaults[$video->player]);
 309    // Lets do some special handling for our flv files to accomdate multiple players.
 310    if ($theme_function == 'video_play_flv') {
 311      return theme('video_flv', $video, $node);
 312    }
 313    elseif ($theme_function == 'video_play_html5') {
 314      return theme('video_html5', $video, $node);
 315    }
 316    else {
 317      return theme($theme_function, $video, $node);
 318    }
 319  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7