You are here

function filefield_source_imce_custom_scan_full in FileField Sources 7

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

Scan and return files, subdirectories, and total size for "full" mode.

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

File

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

Code

function filefield_source_imce_custom_scan_full($dirname, &$imce) {

  // Get a list of files in the database for this directory.
  $scheme = $imce['scheme'];
  $sql_uri_name = $dirname == '.' ? $scheme . '://' : $scheme . '://' . $dirname . '/';
  $result = db_select('file_managed', 'f')
    ->fields('f', array(
    'uri',
  ))
    ->condition('f.uri', $sql_uri_name . '%', 'LIKE')
    ->condition('f.uri', $sql_uri_name . '_%/%', 'NOT LIKE')
    ->execute();
  $db_files = array();
  foreach ($result as $row) {
    $db_files[basename($row->uri)] = 1;
  }

  // Get the default IMCE directory scan, then filter down to database files.
  $directory = imce_scan_directory($dirname, $imce);
  foreach ($directory['files'] as $filename => $file) {
    if (!isset($db_files[$filename])) {
      unset($directory['files'][$filename]);
      $directory['dirsize'] -= $file['size'];
    }
  }
  return $directory;
}