You are here

function filebrowser_view in Filebrowser 6.2

Same name and namespace in other branches
  1. 7.4 filebrowser.module \filebrowser_view()
  2. 7.2 filebrowser.module \filebrowser_view()
  3. 7.3 filebrowser.module \filebrowser_view()

Implementation of hook_init().

File

./filebrowser.module, line 318

Code

function filebrowser_view($node, $teaser = FALSE, $page = FALSE) {
  global $user, $base_url;
  $node = node_prepare($node, $teaser);
  if (!$teaser) {
    _filebrowser_load_files($node);

    // Full node content view
    // ========================================================
    // Keep track of the current location and update breadcrumbs to reflect that.
    $breadcrumbs = array(
      l(t('Home'), NULL),
    );
    $breadcrumb_path = "";
    $path_elements = explode('/', rtrim($node->file_listing['.']['relative-path'], "/"));
    for ($i = 0; $i < count($path_elements); $i++) {
      $child_dir = $path_elements[$i] == '' ? '/' : $path_elements[$i];

      // Issue #2513304: Breadcrumbs not linked properly .. add slashes
      $breadcrumb_path = $i < 2 ? $breadcrumb_path . $child_dir : $breadcrumb_path . '/' . $child_dir;
      $fid = db_result(db_query("SELECT fid FROM {node_dir_listing_content} WHERE path='%s'", $breadcrumb_path));
      if ($child_dir == '/') {
        $label = $node->title;
      }
      else {
        $label = $child_dir;
      }
      if ($i < count($path_elements) - 1) {
        $breadcrumbs[] = l($label, "node/{$node->nid}/{$fid}");
      }
      else {
        $breadcrumbs[] = $label;
      }
    }
    drupal_set_breadcrumb($breadcrumbs);

    // Insert file listing  content part
    $current_view = _filebrowser_externals('presentations', $node->folder_presentation->default_view);
    $node->content['filebrowser_content'] = array(
      '#value' => count($node->file_listing) == 0 ? '' : theme($current_view['theme'], $node),
      '#weight' => 1,
    );
    if ($node->folder_uploads->enabled && user_access(FILEBROWSER_UPLOAD)) {
      module_load_include("form.upload.inc", "filebrowser");
      $node->content['filebrowser_form_upload'] = array(
        '#value' => drupal_get_form('filebrowser_form_upload', $node),
        '#weight' => 2,
      );
    }
    if ($node->folder_uploads->enabled && user_access(FILEBROWSER_CREATE_FOLDER)) {
      module_load_include("form.create_folder.inc", "filebrowser");
      $node->content['filebrowser_form_create_folder'] = array(
        '#value' => drupal_get_form('filebrowser_form_create_folder', $node),
        '#weight' => 3,
      );
    }
    $statistics = array(
      'empty' => t('This folder is empty'),
    );
    if ($node->file_listing['.']['folders_count'] > 0) {
      $statistics['folders'] = format_plural($node->file_listing['.']['folders_count'], '1 dossier', '@count dossiers');
      $statistics['empty'] = NULL;
    }
    if ($node->file_listing['.']['files_count'] > 0) {
      $statistics['files'] = format_plural($node->file_listing['.']['files_count'], '1 file', '@count files');
      $statistics['size'] = format_size($node->file_listing['.']['size']);
      $statistics['empty'] = NULL;
    }
    $node->content['filebrowser_statistics'] = array(
      '#value' => theme('dir_listing_statistics', $statistics),
      '#weight' => 3,
    );
  }
  return $node;
}