[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  /*
   3   * @file
   4   * Class file used to create our video and thumbnail objects.
   5   * @todo : remove video_zencoder validation form the class
   6   *
   7   */
   8  class video_helper {
   9    public function video_object($element) {
  10      $field = content_fields($element['#field_name'], $element['#type_name']);
  11      //setup our width x height
  12      $dimensions = explode("x", $element['#item']['data']['dimensions']);
  13      $player_dimensions = explode("x", $element['#item']['data']['player_dimensions']);
  14      if (!isset($dimensions[0]) || !isset($dimensions[1])) {
  15        $dimensions = explode("x", $field['widget']['default_dimensions']);
  16        if (!isset($dimensions[0]) || !isset($dimensions[1])) {
  17          drupal_set_message(t('Something is wrong with your dimensions.  Make sure you enter dimensions in the form of WxH.'), 'error');
  18        }
  19      }
  20      if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) {
  21        $player_dimensions = explode("x", $field['widget']['default_player_dimensions']);
  22        if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) {
  23          drupal_set_message(t('Something is wrong with your player dimensions.  Make sure you enter the player dimensions in the form of WxH.'), 'error');
  24        }
  25      }
  26  
  27      $extension = strtolower(pathinfo($element['#item']['filename'], PATHINFO_EXTENSION));
  28      if (empty($extension)) {
  29        drupal_set_message(
  30          t('Could not determine the extension of filename @filename for node @node-title, element @element-title, item @item',
  31            array('@filename' => $element['#item']['filename'], '@node-title' => $element['#node']->node_title, '@element-title' => $field['widget']['label'], '@item' => $element['#item']['#delta'])),
  32          'error');
  33        return NULL;
  34      }
  35  
  36      // Build our video object for all types.
  37      $video = new stdClass();
  38      $video->fid = $element['#item']['fid'];
  39      $video->original = $element['#item'];
  40      $video->files->{$extension}->filename = pathinfo($element['#item']['filepath'], PATHINFO_FILENAME) .'.'. $extension;
  41      $video->files->{$extension}->filepath = $element['#item']['filepath'];
  42      $video->files->{$extension}->url = file_create_url($element['#item']['filepath']);
  43      $video->files->{$extension}->filemime = $element['#item']['filemime'];
  44      $video->files->{$extension}->extension = $extension;
  45      $video->player = $extension;
  46      $video->width = trim($dimensions[0]);
  47      $video->height = trim($dimensions[1]);
  48      $video->player_width = trim($player_dimensions[0]);
  49      $video->player_height = trim($player_dimensions[1]);
  50      $video->thumbnail = $this->thumbnail_object($element);
  51      $video->formatter = $element['#formatter'];
  52      $video->autoplay = variable_get('video_autoplay', TRUE);
  53      $video->autobuffering = variable_get('video_autobuffering', TRUE);
  54      $video->theora_player = variable_get('video_ogg_player', 'http://theora.org/cortado.jar');
  55      // lets find out if we have transcoded this file and update our paths.
  56      if (isset($field['widget']['autoconversion']) && $field['widget']['autoconversion']
  57          && !$element['#item']['data']['bypass_autoconversion']) {
  58        // discard all existing file data
  59        $video->files = new stdClass();
  60        module_load_include('inc', 'video', '/includes/conversion');
  61        $conversion = new video_conversion;
  62        $conversion->load_completed_job($video);
  63      }
  64  //    echo '<pre>';
  65  //    print_r($video);
  66  //    die();
  67      // Let othere module to load the video files by referance
  68      // Lets find out if we have pushed this file to the cdn if enabled.
  69      // @TODO : add correct filesystem load to this
  70      $filesystem = variable_get('vid_filesystem', 'drupal');
  71      if ($filesystem != 'drupal') {
  72        module_load_include('inc', 'video', '/includes/filesystem');
  73        $filesystem = new video_filesystem();
  74        $filesystem->load_file($video);
  75      }
  76  
  77  
  78      // Moved to last to recheck incase we changed our extension above.
  79      $video->flash_player = variable_get('video_extension_' . $video->player . '_flash_player', '');
  80      $video->html5_player = variable_get('video_extension_' . $video->player . '_html5_player', '');
  81  
  82      // Return our object
  83      return $video;
  84    }
  85  
  86    public function thumbnail_object($element) {
  87      $field = content_fields($element['#field_name'], $element['#type_name']);
  88      // Build our thumbnail object
  89      $thumbnail = new stdClass();
  90      $thumbnail->filepath = '';
  91      $thumbnail->url = '';
  92      //@todo future enhancements for our thumbnails
  93      $thumbnail->alt = '';
  94      $thumbnail->title = '';
  95      $thumbnail->description = '';
  96  
  97      // Setup our thumbnail path.
  98      $use_default_img = isset($element['#item']['data']['use_default_video_thumb']) ? $element['#item']['data']['use_default_video_thumb'] : false;
  99      if ($use_default_img && !empty($field['widget']['default_video_thumb']['filepath'])) {
 100        $thumbnail->filepath = $field['widget']['default_video_thumb']['filepath'];
 101      } elseif (isset($element['#item']['data']['video_thumb']) ? $element['#item']['data']['video_thumb'] : false) {
 102        $thumbnail->filepath = $element['#item']['data']['video_thumb'];
 103      } else {
 104        //need some type of default if nothing is present
 105        //drupal_set_message(t('No thumbnail has been configured for the video.'), 'error');
 106      }
 107      //lets check for an imagecache preset
 108      if (isset($element['imagecache_preset'])) {
 109        $thumbnail->url = imagecache_create_url($element['imagecache_preset'], $thumbnail->filepath);
 110        $thumbnail->filepath = imagecache_create_path($element['imagecache_preset'], $thumbnail->filepath);
 111      } else {
 112        $thumbnail->url = file_create_url($thumbnail->filepath);
 113      }
 114  
 115      //swftools appends sites/default/files to the front of our path...
 116      //@todo Is this a setting?  Need to figure this out.
 117      $thumbnail->swfthumb = $thumbnail->filepath;
 118      // filemime
 119      $thumbnail->filemime = file_get_mimetype($thumbnail->filepath);
 120      // Return our object
 121      return $thumbnail;
 122    }
 123  
 124  }


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