function _video_image_presave in Video 6
Same name and namespace in other branches
- 6.2 plugins/video_image/video_image.module \_video_image_presave()
1 call to _video_image_presave()
- video_image_nodeapi in plugins/
video_image/ video_image.module - Implementation of hook_nodeapi()
File
- plugins/
video_image/ video_image.module, line 275 - video_image.module
Code
function _video_image_presave(&$node) {
// ############# PREPARE #######################
if (count($_POST)) {
$validators = array(
'file_validate_is_image' => array(),
);
$field_name = file_save_upload('image', $validators);
if (!$field_name && video_image_is_autothumbable($node)) {
_video_image_thumbnail_debug(t('video_image_nodeapi: prepare: ready to thumbnail video'));
$field_name = module_invoke('video_' . $node->vtype, 'v_auto_thumbnail', $node);
if ($field_name === false && count($_POST)) {
drupal_set_message(t('The thumbnailing process of your video failed for some reason. Video thumbnail will not be available.'), 'error');
}
}
}
if ($field_name) {
$node->tempimage = _video_image_temp_image_store($field_name);
$node->new_image = TRUE;
//print_r($node);
//die;
}
else {
if (is_array($_POST['tempimage']) && ($_POST['op'] == 'Preview' || $_POST['op'] == 'Submit')) {
//print_r($node);
//exit;
$node->tempimage = (array) _video_image_temp_image_load(array_values($_POST['tempimage']['fids']));
}
}
// ###########################################################################
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']));
//print_r($image);
//exit;
db_query("DELETE FROM {files} WHERE fid in (%s)", implode(',', array_values($node->tempimage['fids'])));
// initialize standard node fields
//print_r($image);
//exit;
$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;
$node->serial_data['iid'] = $node->iid;
}
else {
node_save($image);
//print_r($image);
//exit;
//image_insert($image);
$node->iid = $image->nid;
// store the iid into the serial_data
$node->serial_data['iid'] = $node->iid;
//print_r($node);
//die;
// 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;
}
}