You are here

function imce_menu in IMCE 5

Same name and namespace in other branches
  1. 6.2 imce.module \imce_menu()
  2. 6 imce.module \imce_menu()
  3. 7 imce.module \imce_menu()

Implementation of hook_menu().

File

./imce.module, line 33

Code

function imce_menu($may_cache) {
  global $user;
  $GLOBALS['imce_ext'] = array(
    '.gif',
    '.jpg',
    '.jpeg',
    '.png',
  );
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'imce/browse',
      'title' => 'IMCE browse',
      'access' => user_access('access imce'),
      'callback' => 'imce_browse',
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/settings/imce',
      'title' => t('IMCE settings'),
      'description' => t('Control how your image/file browser works.'),
      'access' => user_access('administer imce'),
      'callback' => 'imce_form_admin',
    );
    $items[] = array(
      'path' => 'admin/settings/imce/settings',
      'title' => t('Settings'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/settings/imce/subfolder',
      'title' => t('Sub-folder tool'),
      'access' => user_access('administer imce'),
      'callback' => 'imce_form_subfolder',
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    );
  }
  elseif (arg(0) == 'user' && ($uid = arg(1)) && is_numeric($uid)) {
    if ($user->uid == $uid) {
      $access = user_access('access imce');
      $acc = $user;
    }
    elseif (user_access('administer imce') && $uid != 1 && ($acc = user_load(array(
      'uid' => $uid,
    )))) {
      $access = array_intersect(user_roles(0, 'access imce'), $acc->roles);
    }
    if ($access) {
      $items[] = array(
        'path' => 'user/' . $uid . '/imce',
        'title' => t('Personal files'),
        'access' => TRUE,
        'callback' => 'imce_user_page',
        'callback arguments' => array(
          $acc,
        ),
        'type' => MENU_LOCAL_TASK,
        'weight' => 10,
      );
    }
  }
  elseif (arg(0) == 'imce' && arg(1) != 'browse' && user_access('access imce')) {
    if (drupal_valid_token($_REQUEST['token'], 'imce')) {
      $set = (object) imce_settings_user();
      if (arg(1) == 'delete' && $set->delete && ($filename = basename(arg(2)))) {
        imce_delete_file($set, $filename);
      }
      elseif (arg(1) == 'upload' && $set->upload && $_FILES['thefile']) {
        imce_copy_uploaded($set, $_FILES['thefile']);
      }
      elseif (arg(1) == 'resize' && $set->resize && ($filename = basename($_POST['img_name']))) {
        imce_resize_image($set, $filename, $_POST['img_w'], $_POST['img_h'], $_POST['img_copy']);
      }
      elseif (arg(1) == 'dir' && $set->subnav && isset($_POST['dirname'])) {
        $target = $set->dir . '/' . $_POST['dirname'];
        if (is_dir($target) && ($real = file_check_location($target, $set->root))) {
          $_SESSION['imcedir'] = imce_relative_path($real, file_directory_path());
        }
      }
    }
    elseif (arg(1) == 'login' && user_access('administer imce') && is_numeric($uid = arg(2)) && $uid != 1 && $user->uid != $uid && ($acc = user_load(array(
      'uid' => $uid,
    ))) && array_intersect(user_roles(0, 'access imce'), $acc->roles)) {
      $_SESSION['imceuser'] = array(
        'uid' => $acc->uid,
        'roles' => $acc->roles,
        'name' => $acc->name ? $acc->name : t('Anonymous'),
        'ownperm' => arg(3) == 'own',
      );
      unset($_SESSION['imcedir']);
    }
    elseif (arg(1) == 'logout' && user_access('administer imce')) {
      unset($_SESSION['imceuser'], $_SESSION['imcedir']);
    }
    drupal_goto('imce/browse');
  }
  return $items;
}