You are here

function _video_image_submit in Video 5

1 call to _video_image_submit()
video_image_nodeapi in plugins/video_image/video_image.module
Implementation of hook_nodeapi()

File

plugins/video_image/video_image.module, line 260
Enable image support for video module.

Code

function _video_image_submit(&$node) {
  if ($node->regenerate_thumbnail) {
    _video_image_regenerate_thumbnail($node);
  }
  if (is_array($node->tempimage['fids']) && $node->tempimage['fids']['_original']) {
    $image = _video_image_temp_image_load(array_values($node->tempimage['fids']));
    db_query("DELETE FROM {files} WHERE fid in (%s)", implode(',', array_values($node->tempimage['fids'])));

    // initialize standard node fields
    $image->uid = $node->uid;
    $image->created = time();
    $image->title = t('Video thumbnail for !title', array(
      '!title' => $node->title,
    ));
    $image = node_submit($image);
    $image->uid = $node->uid;
    $image->status = _video_image_publish_thumbnails();
    $image->promote = _video_image_promote_thumbnails();

    // This is a messages hack (we don't want to see what happens under the covers)
    _video_image_pause_messages(true);
    if ($node->iid) {
      $oldimage = node_load($node->iid);
      $oldimage->images = $image->images;

      // delete the old images?
      $oldimage->new_image = 1;
      node_save($oldimage);
      $node->iid = $oldimage->nid;
    }
    else {
      node_save($image);
      $node->iid = $image->nid;

      // store the iid into the serial_data
      $node->serial_data['iid'] = $node->iid;

      // needed to set the correct status and promote values even if the user does not have enough permissions. Is there a better solution???
      // db_query('UPDATE {node} SET status = %d, promote = %d WHERE nid = %d AND vid = %d', _video_image_publish_thumbnails(), _video_image_promote_thumbnails(), $image->nid, $image->vid);
    }
    _video_image_pause_messages();
  }
  else {
    $node->serial_data['iid'] = $node->iid;
  }
}