You are here

function _filebrowser_prepare_record in Filebrowser 7.2

Same name and namespace in other branches
  1. 8 filebrowser.common.inc \_filebrowser_prepare_record()
  2. 6.2 includes/node.inc \_filebrowser_prepare_record()
  3. 7.4 filebrowser.common.inc \_filebrowser_prepare_record()
  4. 7.3 filebrowser.common.inc \_filebrowser_prepare_record()

Prepare node record to be used. This is mainly about default stuff.

Parameters

$node node to prepage:

$load is this for loading (TRUE) or inserting/updating (FALSE):

3 calls to _filebrowser_prepare_record()
filebrowser_insert in ./filebrowser.module
Implements hook_insert().
filebrowser_load in ./filebrowser.module
Implements hook_load().
filebrowser_update in ./filebrowser.module
Implements hook_update().

File

./filebrowser.common.inc, line 81
Misc filebrowser common functions.

Code

function _filebrowser_prepare_record(&$node, $load = TRUE) {

  // Fix trailing slashes
  $node->folder_path = rtrim($node->folder_path, '/');

  // Process uploads
  $node->folder_uploads = (object) $node->folder_uploads;
  _filebrowser_set_default($node->folder_uploads->enabled, FALSE);
  _filebrowser_set_default($node->folder_uploads->allow_overwrite, FALSE);
  _filebrowser_set_default($node->folder_uploads->accepted_uploaded_files, '');

  // Process handlers
  $node->folder_uploads = (object) $node->folder_uploads;
  foreach (module_implements("filebrowser_handler_info") as $module) {
    if (isset($node->{$module})) {
      $node->file_handlers->{$module} = $node->{$module};
      unset($node->{$module});
    }
    $node->file_handlers = (object) $node->file_handlers;
    $node->file_handlers->{$module} = (object) $node->file_handlers->{$module};
  }

  // Fix rights
  $node->folder_rights = (object) $node->folder_rights;
  unset($node->folder_rights->private_downloads);
  _filebrowser_set_default($node->folder_rights->explore_subdirs, FALSE);
  _filebrowser_set_default($node->folder_rights->create_folders, FALSE);
  _filebrowser_set_default($node->folder_rights->download_archive, FALSE);
  _filebrowser_set_default($node->folder_rights->forbidden_files, "descript.ion\nfile.bbs\n.git\nCSV\n.svn\n");
  _filebrowser_set_default($node->folder_rights->filtered_files, "");
  if (!isset($node->folder_rights->download_manager) || !_filebrowser_externals('download_manager_info', $node->folder_rights->download_manager)) {
    $node->folder_rights->download_manager = 'public';
  }

  // Fix presentation
  $node->folder_presentation = (object) $node->folder_presentation;
  _filebrowser_set_default($node->folder_presentation->encoding, 'UTF8');
  if (!isset($node->folder_presentation->default_view) || !_filebrowser_externals('presentations', $node->folder_presentation->default_view)) {
    $node->folder_presentation->default_view = 'list-view';
  }
  _filebrowser_set_default($node->folder_presentation->hide_extension, FALSE);
  $columns = _filebrowser_externals('metadata_info');
  $node->folder_presentation->visible_columns = _filebrowser_filter_checkboxes_result($node->folder_presentation->visible_columns);
  foreach ($node->folder_presentation->visible_columns as $name => $value) {
    if (!isset($columns[$name])) {
      unset($node->folder_presentation->visible_columns[$name]);
    }
  }
  if (count($node->folder_presentation->visible_columns) == 0) {
    $node->folder_presentation->visible_columns = array(
      FILEBROWSER_DATA_NAME_ICON => 1,
      FILEBROWSER_DATA_NAME_DISPLAY_NAME => 1,
    );
  }
  if (!isset($node->folder_presentation->default_sort)) {
    foreach ($node->folder_presentation->visible_columns as $name => $foo) {
      if (isset($columns[$name]['sortable']) && $columns[$name]['sortable']) {
        $node->folder_presentation->default_sort = $name;
        break;
      }
    }
  }
  _filebrowser_set_default($node->folder_presentation->default_sort_order, 'asc');

  // Create serialized properties
  $data = new stdClass();
  $data->folder_rights = $node->folder_rights;
  $data->folder_presentation = $node->folder_presentation;
  $data->folder_uploads = $node->folder_uploads;
  $data->file_handlers = isset($node->file_handlers) ? $node->file_handlers : '';
  $node->properties = serialize($data);
}