You are here

function elfinder_filesystemconnector in elFinder file manager 7

Same name and namespace in other branches
  1. 7.3 elfinder.module \elfinder_filesystemconnector()
  2. 7.2 elfinder.module \elfinder_filesystemconnector()

File browser to filesystem php connector callback

1 string reference to 'elfinder_filesystemconnector'
elfinder_menu in ./elfinder.module
Implements hook_menu().

File

./elfinder.module, line 235

Code

function elfinder_filesystemconnector($mode = 'default') {
  global $base_root;

  /**
   * Emulate json_encode required by filesystem connector for old php without JSON support
   */
  if (!function_exists('json_encode')) {
    function json_encode($arg) {
      return drupal_json($arg);
    }
  }

  /* Disabling incompartible devel module features */
  if (module_exists('devel')) {
    $devel_incompat = array(
      'dev_timer',
      'devel_query_display',
      'dev_mem',
      'devel_redirect_page',
    );
    $flag = FALSE;
    foreach ($devel_incompat as $di) {
      if (variable_get($di, 0)) {
        $flag = TRUE;
        variable_set($di, 0);
      }
    }
    if ($flag) {
      drupal_set_message(t('elFinder disabled incompatible devel module features.'), 'warning');
    }
  }
  require_once elfinder_connector_path();
  $filedir = elfinder_file_directory_path(TRUE);
  $fileurl = elfinder_file_directory_url($mode == 'relative' ? TRUE : FALSE);
  $disabled_commands = array();
  $permissions = elfinder_permission();
  $commands = elfinder_cmd_permissions();

  // Disable not allowed commands
  foreach ($permissions as $perm_name => $perm_data) {
    if (array_key_exists($perm_name, $commands) && !user_access($perm_name)) {
      array_push($disabled_commands, $commands[$perm_name]);
    }
  }
  if (!elfinder_prepare_directory($filedir)) {
    drupal_set_message(t('Filesystem root @filedir is not writable', array(
      '@filedir' => $filedir,
    )), 'error');
  }
  $opts = array(
    'root' => $filedir,
    // path to root directory (named 'path' in elFinder 2.0)
    'URL' => $fileurl,
    // root directory URL
    'rootAlias' => t('Home'),
    // display this instead of root directory name (named 'alias' in elFinder 2.0)
    'disabled' => $disabled_commands,
    // list of not allowed commands
    'debug' => FALSE,
    'dirSize' => FALSE,
    'tmbSize' => variable_get('elfinder_settings_thumbnail_size', '48'),
    // thumbnail image size
    'tmbDir' => variable_get('elfinder_settings_thumbnail_dirname', 'tmb'),
    // thumbnail images directory
    'dateFormat' => variable_get('date_format_long', 'j M Y H:i'),
    // file modification date format
    'mimeDetect' => variable_get('elfinder_settings_filesystem_mimedetect', 'auto'),
    // file type detection method
    'fileUrl' => variable_get('elfinder_settings_filesystem_fileurl', 'true') == 'true' ? TRUE : FALSE,
    // show file absolute url
    'imgLib' => variable_get('elfinder_settings_thumbnail_imglib', 'auto'),
    // image manipulation library
    'fileMode' => octdec(variable_get('elfinder_settings_filesystem_fileperm', '0666')),
    // created file permissions
    'dirMode' => octdec(variable_get('elfinder_settings_filesystem_dirperm', '0777')),
  );
  class elFinderDrupal extends elFinder {
    protected function _mimetype($path) {
      if (variable_get('elfinder_settings_filesystem_mimedetect', 'auto') == 'drupal') {
        return file_get_mimetype($path, NULL);
      }
      else {
        return parent::_mimetype($path);
      }
    }
    protected function _hash($path) {
      return drupal_get_token($path);
    }

  }
  $newopts = module_invoke_all('elfinder_connector_init', $opts);
  if ($newopts) {
    $opts = $newopts;
  }
  $fm = new elFinderDrupal($opts);
  $fm
    ->run();
  module_invoke_all('exit');
  exit;
}