You are here

function imce_working_directory in IMCE 7

Same name and namespace in other branches
  1. 6.2 inc/imce.page.inc \imce_working_directory()
  2. 6 inc/page.inc \imce_working_directory()

Return an available directory for the profile.

1 call to imce_working_directory()
imce_initiate_profile in inc/imce.page.inc
Initiate and return configuration profile for the $user.

File

inc/imce.page.inc, line 951
Implements the file browser.

Code

function imce_working_directory(&$imce) {

  // Do not use session if there is only one directory assigned.
  $sess = TRUE;
  if (count($imce['directories']) < 2) {
    $perms = reset($imce['directories']);
    if (!isset($perms['subnav']) || !$perms['subnav']) {
      $sess = FALSE;
    }
  }

  // Check GET.
  if (isset($_GET['dir'])) {
    $selected_dir = filter_xss($_GET['dir']);
    if ($info = imce_directory_info($selected_dir, $imce)) {
      if (imce_check_directory($selected_dir, $imce)) {
        if ($sess) {
          $_SESSION['imce_directory'] = rawurlencode($info['name']);
        }
      }
      else {
        $info = FALSE;
      }
    }
    else {
      imce_inaccessible_directory($selected_dir, $imce);
    }
    return $info;
  }

  // Check session.
  if ($sess && isset($_SESSION['imce_directory'])) {
    $dirname = check_url(rawurldecode($_SESSION['imce_directory']));
    if ($info = imce_directory_info($dirname, $imce)) {
      if (imce_check_directory($dirname, $imce)) {
        return $info;
      }
    }
  }

  // Or the whole list.
  foreach ($imce['directories'] as $dirname => $info) {
    $dirname = (string) $dirname;
    if (imce_check_directory($dirname, $imce)) {
      if ($sess) {
        $_SESSION['imce_directory'] = rawurlencode($dirname);
      }
      return $info;
    }
  }
  return FALSE;
}