You are here

function video_upload_create_node_from in Video 5

Same name and namespace in other branches
  1. 6 types/video_upload/video_upload.module \video_upload_create_node_from()
  2. 6.2 types/video_upload/video_upload.module \video_upload_create_node_from()

Function to other modules to use to create image nodes.

Parameters

$filepath: String filepath of an image file. Note that this file will be moved into the image module's images directory.

$title: String to be used as the node's title. If this is ommitted the filename will be used.

$body : String to be used as the node's body.

$taxonomy: Taxonomy terms to assign to the node if the taxonomy.module is installed.

Return value

A node object if the node is created successfully or FALSE on error.

File

types/video_upload/video_upload.module, line 652
Enable Uploaded videos support for video module.

Code

function video_upload_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL) {
  global $user;
  if (!user_access('create video')) {
    drupal_access_denied();
  }
  if (!is_object($filepath)) {
    $p = $filepath;
    $filepath = new stdClass();
    $filepath->filepath = $p;
    $filepath->filename = basename($p);
    $filepath->filesize = filesize($p);
  }

  // Ensure it's a valid video

  //if (!$image_info = image_get_info($filepath)) {

  //  return FALSE;

  //}

  // Build the node.
  $node = new stdClass();
  $node->type = 'video';
  $node->vtype = 'upload';
  $node->uid = $user->uid;
  $node->name = $user->name;
  $node->title = isset($title) ? $title : basename($filepath);
  $node->body = $body;

  // Set the node's defaults... (copied this from node and comment.module)
  $node_options = variable_get('node_options_' . $node->type, array(
    'status',
    'promote',
  ));
  $node->status = in_array('status', $node_options);
  $node->promote = in_array('promote', $node_options);
  if (module_exists('comment')) {
    $node->comment = variable_get("comment_{$node->type}", COMMENT_NODE_READ_WRITE);
  }
  if (module_exists('taxonomy')) {
    $node->taxonomy = $taxonomy;
  }
  $node->video_upload_file = $filepath;
  node_invoke_nodeapi($node, 'prepare');
  $node->new_video_upload_file_fid = $node->new_video_upload_file->fid;

  // Save the node.
  $node = node_submit($node);
  node_save($node);

  // Remove the original image now that the import has completed.
  file_delete($original_path);
  return $node;
}