You are here

function filebrowser_view in Filebrowser 7.3

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

Implements hook_init().

File

./filebrowser.module, line 452

Code

function filebrowser_view($node, $view_mode) {
  if ($view_mode == "full") {
    _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 = "";

    //print_r($node);

    //return;
    $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 #2511546. Add a slash from the third breadcrumb
      $breadcrumb_path = $i < 2 ? $breadcrumb_path . $child_dir : $breadcrumb_path . '/' . $child_dir;
      $fid = db_query("SELECT fid FROM {node_dir_listing_content}\n                     WHERE path = :path", array(
        ':path' => $breadcrumb_path,
      ))
        ->fetchField();
      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(
        '#markup' => count($node->file_listing) == 0 ? '' : theme($current_view['theme'], array(
          'node' => $node,
        )),
        '#weight' => 1,
      );
      if ($node->folder_uploads->enabled && user_access(FILEBROWSER_UPLOAD)) {
        $form = drupal_get_form('filebrowser_form_upload', $node);
        $node->content['filebrowser_form_upload'] = array(
          '#markup' => drupal_render($form),
          '#weight' => 2,
        );
      }
      if ($node->folder_rights->create_folders && user_access(FILEBROWSER_CREATE_FOLDER)) {
        $form = drupal_get_form('filebrowser_form_create_folder', $node);
        $node->content['filebrowser_form_create_folder'] = array(
          '#markup' => drupal_render($form),
          '#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 folder', '@count folders');
        $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(
        '#markup' => theme('dir_listing_statistics', $statistics),
        '#weight' => 3,
      );
    }
  }

  // Insert filebrowser links
  $node->content['links']['filebrowser'] = array(
    '#theme' => 'links__node__blog',
    '#links' => _filebrowser_links($node),
    '#attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  );
  return $node;
}