You are here

function filefield_source_imce_custom_scan_restricted in FileField Sources 6

Same name and namespace in other branches
  1. 7 sources/imce.inc \filefield_source_imce_custom_scan_restricted()

Scan directory and return file list, subdirectories, and total size for Restricted Mode.

1 string reference to 'filefield_source_imce_custom_scan_restricted'
filefield_source_imce_page in sources/imce.inc
Outputs the IMCE browser for FileField.

File

sources/imce.inc, line 251
A FileField extension to allow referencing of files from IMCE.

Code

function filefield_source_imce_custom_scan_restricted($dirname, &$imce) {
  $field = $GLOBALS['conf']['imce_custom_field'];
  $fdp = file_directory_path();
  $field_path = $field['widget']['file_path'] == '' ? $fdp : filefield_widget_file_path($field);
  $db_info = content_database_info($field);

  // Get field files
  $result = db_query("SELECT f.* FROM {" . $db_info['table'] . "} c INNER JOIN {files} f ON c." . $db_info['columns']['fid']['column'] . " = f.fid WHERE f.status = 1 AND f.filepath LIKE '%s' AND f.filepath NOT LIKE '%s'", $field_path . '/%', $field_path . '/%/%');

  // Create directory info
  $directory = array(
    'dirsize' => 0,
    'files' => array(),
    'subdirectories' => array(),
    'error' => FALSE,
  );
  while ($file = db_fetch_object($result)) {

    // Get real name
    $name = basename($file->filepath);

    // Get dimensions
    $width = $height = 0;
    if ($img = imce_image_info($file->filepath)) {
      $width = $img['width'];
      $height = $img['height'];
    }
    $directory['files'][$name] = array(
      'name' => $name,
      'size' => $file->filesize,
      'width' => $width,
      'height' => $height,
      'date' => $file->timestamp,
    );
    $directory['dirsize'] += $file->filesize;
  }

  // Process IMCE. Make field directory the only accessible one.
  $imce['dir'] = $field_path == $fdp ? '.' : substr($field_path, strlen($fdp) + 1);
  $imce['directories'] = array();
  if (!empty($imce['perm'])) {
    filefield_source_imce_disable_perms($imce, array(
      'browse',
    ));
  }
  return $directory;
}