You are here

function flashnode_prepare in Flash Node 5.2

Same name and namespace in other branches
  1. 5.6 flashnode.module \flashnode_prepare()
  2. 5.3 flashnode.module \flashnode_prepare()

Implementation of hook_prepare().

File

./flashnode.module, line 133

Code

function flashnode_prepare(&$node) {
  $field_name = 'flashfile';

  // check if the upload is valid
  if ($file = file_check_upload($field_name)) {

    // if it is then save it to the flash/temp folder
    $file = file_save_upload($field_name, _flashnode_filename($file->filename, TRUE));

    // if the upload succeeds...
    if ($file) {

      // ...check if the mime type wasn't flash
      if (strtolower($file->filemime) != 'application/x-shockwave-flash') {
        watchdog($field_name, t('Flash node was given %type for upload.', array(
          '%type' => $node->file->filemime,
        )));
        form_set_error($field_name, t('The specified file is not a valid Flash format.'));

        // delete the uploaded file in case it is unsafe
        file_delete($file->filepath);
        return;
      }
    }
    else {
      return;
    }

    // add data to the $node->flashnode object
    $node->flashnode['_flashnode'] = $file->filepath;
    $node->flashnode['filemime'] = $file->filemime;
    $node->new_file = TRUE;
  }

  // try to get the file settings for this file, using image_get_info
  $info = image_get_info(file_create_path($node->flashnode['_flashnode']));
  $node->flashnode['_height'] = $info['height'];
  $node->flashnode['_width'] = $info['width'];
}