You are here

function filefield_source_imce_custom_scan_restricted in FileField Sources 7

Same name and namespace in other branches
  1. 6 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 257
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'];
  $root = $imce['scheme'] . '://';
  $field_uri = $field['_uri'];
  $is_root = $field_uri == $root;

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

  // Create directory info
  $directory = array(
    'dirsize' => 0,
    'files' => array(),
    'subdirectories' => array(),
    'error' => FALSE,
  );
  if (isset($field['storage']['details']['sql']['FIELD_LOAD_CURRENT'])) {
    $storage = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT'];
    $table_info = reset($storage);
    $table = key($storage);
    $sql_uri = $field_uri . ($is_root ? '' : '/');
    $query = db_select($table, 'cf');
    $query
      ->innerJoin('file_managed', 'f', 'f.fid = cf.' . $table_info['fid']);
    $result = $query
      ->fields('f')
      ->condition('f.status', 1)
      ->condition('f.uri', $sql_uri . '%', 'LIKE')
      ->condition('f.uri', $sql_uri . '%/%', 'NOT LIKE')
      ->execute();
    foreach ($result as $file) {

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

      // Get dimensions
      $width = $height = 0;
      if ($img = imce_image_info($file->uri)) {
        $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;
    }
  }
  return $directory;
}