You are here

function video_thumb_process in Video 7

Same name and namespace in other branches
  1. 6.5 video_widget.inc \video_thumb_process()
  2. 6.4 video_widget.inc \video_thumb_process()
1 call to video_thumb_process()
video_field_widget_process in ./video.field.inc
An element #process callback for the image_image field type.

File

./video.module, line 155

Code

function video_thumb_process(&$element, &$form_state) {

  // Developed for ffmpeg support
  $file = $element['#value'];
  $delta = $file['fid'];
  $field = field_widget_field($element, $form_state);
  $instance = field_widget_instance($element, $form_state);
  $settings = $instance['widget']['settings'];
  $gen_fail = FALSE;
  if (isset($element['preview']) && $file['fid'] != 0) {
    if (in_array($field['settings']['autothumbnail'], array(
      'auto',
      'auto_fallback',
    ))) {
      $default_thumb = array();
      $transcoder = new video_transcoder();
      if ($thumbs = $transcoder
        ->generate_thumbnails($file)) {
        $default_thumb = array_rand($thumbs);
        if (!empty($thumbs)) {
          foreach ($thumbs as $fid => $img) {

            // if file object contain url then use file name to identify object
            $thumbss[$img->fid] = theme('image_style', array(
              'style_name' => $field['settings']['preview_video_thumb_style'],
              'path' => $img->uri,
            ));
          }
        }
      }
      if (!empty($thumbss)) {
        $element['thumbnail'] = array(
          '#type' => 'radios',
          '#title' => t('Video thumbnails'),
          '#element_validate' => array(
            'video_thumbnail_validate',
          ),
          '#options' => $thumbss,
          '#default_value' => !empty($file['thumbnail']) ? $file['thumbnail'] : $thumbs[$default_thumb]->fid,
          '#weight' => 10,
          '#attributes' => array(
            'class' => array(
              'video-thumbnails',
            ),
            'onchange' => 'videoftp_thumbnail_change()',
            'rel' => 'video_large_thumbnail-' . $delta,
          ),
        );
      }
      else {
        $gen_fail = TRUE;
      }
    }

    // if fail creating thumbnails fall back to manual or manual upload
    if (!empty($gen_fail) && $field['settings']['autothumbnail'] == 'auto_fallback' || $field['settings']['autothumbnail'] == 'manual_upload') {
      $element['thumbnail'] = array(
        '#title' => t('Video thumbnail'),
        //        '#element_validate' => array('video_thumbnail_validate'),
        '#type' => 'managed_file',
        '#description' => t('The uploaded image will be used as video thumbnail on this video.'),
        '#default_value' => !empty($file['thumbnail']['fid']) && is_integer($file['thumbnail']['fid']) ? $file['thumbnail']['fid'] : NULL,
        '#upload_location' => file_default_scheme() . '://' . variable_get('video_thumb_path', 'videos/thumbnails') . '/' . $file['fid'],
      );
    }

    // if no thumbnail creation
    if ($field['settings']['autothumbnail'] == 'no') {
      $element['thumbnail'] = array(
        '#type' => 'value',
        '#value' => NULL,
      );
    }

    // Setup our large thumbnail that is on the left.
    // @todo Add smaller video preview instead of thumbnail?
    if (isset($file['thumbnail']) && !empty($file['thumbnail'])) {
      $large_thumb = file_load($file['thumbnail']);
    }
    elseif (!empty($field['settings']['default_video_thumbnail']['fid'])) {
      $large_thumb = file_load($field['settings']['default_video_thumbnail']['fid']);
    }
    else {

      //      $large_thumb = file_load($default_thumb);
    }

    //    print_r($field['settings']);
    //    $default_thumbnail = file_load($field['settings']['default_video_thumbnail']);
    // @todo Add video player
    if (!empty($large_thumb)) {
      $element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $delta . '">' . theme('image_style', array(
        'style_name' => $field['settings']['preview_video_thumb_style'],
        'path' => $large_thumb->uri,
      )) . '</div>';
    }
  }
}