You are here

function _imagecrop_file_load in Image javascript crop 5

Same name and namespace in other branches
  1. 6 imagecrop.module \_imagecrop_file_load()

Helper function to load a file into an object

Parameters

$fid file id:

$module specific module which does not use the files table:

Return value

$file with properties of the file or false

1 call to _imagecrop_file_load()
create_image_object in ./imagecrop.module
Helper function to create image

File

./imagecrop.module, line 529
Provides a javascript toolbox through an imagecache action.

Code

function _imagecrop_file_load($fid, $module) {

  // standard files table
  if (empty($module)) {
    $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
  }
  else {
    if ($module == 'node_images') {
      $result = db_query('SELECT * FROM {node_images} WHERE id = %d', $fid);
    }
  }
  $file = db_fetch_object($result);
  if ($file) {

    // make sure it's an image. Any other mime extensions possible?
    // return false if it's not the right mime type
    $filemime = array(
      'image/jpeg',
      'image/gif',
      'image/png',
      'image/pjpeg',
    );
    if (!in_array($file->filemime, $filemime)) {
      return FALSE;
    }

    // access denied if current user hasn't enough permissions
    $node = node_load($file->nid);
    if (!user_access('administer nodes') && !user_access('edit ' . $node->type . ' content') && !user_access('edit own ' . $node->type . ' content')) {
      drupal_access_denied();
      exit;
    }

    // all seems ok, return file
    return $file;
  }

  // return false if no file was found.
  return FALSE;
}