You are here

function elfinder_file_browser in elFinder file manager 6

Same name and namespace in other branches
  1. 6.2 elfinder.module \elfinder_file_browser()
  2. 7.3 elfinder.module \elfinder_file_browser()
  3. 7 elfinder.module \elfinder_file_browser()
  4. 7.2 elfinder.module \elfinder_file_browser()

File browser render

1 call to elfinder_file_browser()
elfinder_block in ./elfinder.module
Implements hook_block().
1 string reference to 'elfinder_file_browser'
elfinder_menu in ./elfinder.module
Implements hook_menu().

File

./elfinder.module, line 97

Code

function elfinder_file_browser($browser_mode = 'default') {
  if (is_readable(elfinder_connector_path())) {
    global $language;
    $path = drupal_get_path('module', 'elfinder');
    $libpath = elfinder_lib_path();
    $editorApp = '';
    $langCode = $language->language;
    if (isset($_GET['app'])) {
      if (preg_match("/^[a-zA-Z]+\$/", $_GET['app'])) {
        $editorApp = $_GET['app'];
      }
      elseif (preg_match("/^([a-zA-Z]+)|/", $_GET['app'], $m)) {
        $editorApp = $m[1];
      }
    }
    if (isset($_GET['langCode'])) {
      if (preg_match("/^[a-zA-z]{2}\$/", $_GET['langCode'])) {
        $langCode = $_GET['langCode'];
      }
    }

    /* Initial frontend settings */
    $elfinder_js_settings = array(
      'connectorUrl' => url('elfinder/connector'),
      'moduleUrl' => url('elfinder'),
      'editorApp' => $editorApp,
      'langCode' => $langCode,
      'rememberLastDir' => variable_get('elfinder_settings_misc_rememberlastdir', 'true') == 'true' ? TRUE : FALSE,
      // remember last opened directory
      'browserMode' => $browser_mode,
    );
    if ($editorApp) {
      $elfinder_js_settings['editorCallback'] = 'elfinder_' . $editorApp . '_callback';
    }
    $options = array(
      'type' => 'module',
      'media' => 'screen',
    );
    elfinder_add_css($libpath . '/css/elfinder.css', $options);
    elfinder_add_css($path . '/css/elfinder.drupal.css', $options);
    $elfinder_jquery = key(elfinder_system_listing("jquery-[0-9\\.]+.*\\.js\$", elfinder_lib_path(), NULL, NULL));
    $elfinder_jquery_ui = key(elfinder_system_listing("jquery-ui-[0-9\\.]+.*\\.js\$", elfinder_lib_path(), NULL, NULL));
    $elfinder_jquery_ui_css = key(elfinder_system_listing("jquery-ui-[0-9\\.]+.*\\.css\$", elfinder_lib_path(), NULL, NULL));
    if ($elfinder_jquery) {
      drupal_add_js($elfinder_jquery);
    }
    if (module_exists('jquery_ui') && variable_get('elfinder_settings_misc_usesystemjquery', 'false') == 'true' && !preg_match("/^1\\.8/", jquery_ui_get_version())) {
      if (preg_match("/^1\\.6/", jquery_ui_get_version())) {
        elfinder_add_css(jquery_ui_get_path() . '/themes/default/ui.all.css', $options);
      }
      else {
        elfinder_add_css(jquery_ui_get_path() . '/themes/base/ui.all.css', $options);
      }
      jquery_ui_add(array(
        'ui.dialog',
        'ui.accordion',
        'ui.draggable',
        'ui.droppable',
        'ui.selectable',
        'ui.resizable',
      ));
    }
    else {
      $css11 = $libpath . '/js/ui-themes/base/ui.all.css';
      if (is_readable($css11)) {
        elfinder_add_css($css11, $options);
      }
      else {
        if ($elfinder_jquery_ui_css) {
          elfinder_add_css($elfinder_jquery_ui_css, $options);
        }
      }
      if ($elfinder_jquery_ui) {
        drupal_add_js($elfinder_jquery_ui);
      }
    }
    drupal_add_js($libpath . '/js/elfinder.full.js');

    /* Adding localization */
    if ($langCode != 'en' && is_readable($libpath . '/js/i18n/elfinder.' . $langCode . '.js')) {
      drupal_add_js($libpath . '/js/i18n/elfinder.' . $langCode . '.js');
    }

    /* Getting updated frontend settings from hook_elfinder_js_settings */
    $newjssettings = module_invoke_all('elfinder_js_settings', $elfinder_js_settings);
    if ($newjssettings) {
      $elfinder_js_settings = $newjssettings;
    }
    drupal_add_js(array(
      'elfinder' => $elfinder_js_settings,
    ), 'setting');

    /* Loading callbacks for returning url from file manager to caller */
    $editor_plugins = elfinder_system_listing("{$editorApp}\\.callback\\.js\$", $path . '/editors', 'name', 0);
    $callback_file = '';
    if (isset($editorApp) && isset($editor_plugins[$editorApp . '.callback'])) {
      $callback_file = $editor_plugins[$editorApp . '.callback']->filename;
      if (isset($callback_file)) {
        drupal_add_js($callback_file);
      }
    }
    drupal_add_js($path . '/js/helper.js');
    drupal_add_js($path . '/js/elfinder.callback.js');
  }
  else {
    drupal_set_message(t('elFinder library was not found. Please download it from <a href="@url">@url</a> and install to @libpath.', array(
      '@url' => elfinder_download_url(),
      '@libpath' => $libpath,
    )), 'error');
  }
  if ($browser_mode && $browser_mode == 'backend') {
    return theme('elfinder_page_backend');
  }
  else {
    print theme('elfinder_page');
  }
  module_invoke_all('exit');
  exit;
}