You are here

function node_export_get_file in Node export 6.3

Same name and namespace in other branches
  1. 6.2 node_export.module \node_export_get_file()
  2. 7.3 node_export.pages.inc \node_export_get_file()

Generate text file.

Parameters

$nids: An array of node ids.

$code_string: The text output.

$format: The format used.

2 calls to node_export_get_file()
node_export_form_submit in ./node_export.pages.inc
Export form submit function.
node_export_gui in ./node_export.pages.inc
Export GUI function.

File

./node_export.pages.inc, line 363
The Node export pages file.

Code

function node_export_get_file($nids, $code_string, $format = NULL) {
  $filename_data = array();
  $filename_data['count'] = count($nids);
  $filename_data['time'] = time();
  $filename_data['format'] = $format ? $format : 'export';

  // Add a list of nids
  if (count($nids) <= variable_get('node_export_file_list', 10)) {
    $filename_data['list'] = '[' . implode(',', $nids) . ']';
  }
  $name = variable_get('node_export_filename', 'node-export[nid-list]([node-count]-nodes).[timestamp].[format]');
  if (module_exists('token')) {
    $name = token_replace($name, 'Node export filename', $filename_data, '[', ']');
  }
  else {

    // So it works without token.
    $name = str_replace('[nid-list]', $filename_data['list'], $name);
    $name = str_replace('[node-count]', $filename_data['count'], $name);
    $name = str_replace('[timestamp]', $filename_data['time'], $name);
    $name = str_replace('[format]', $filename_data['format'], $name);
  }
  header('Content-type: text/plain');
  header('Content-Disposition: attachment; filename="' . $name . '"');
  print $code_string;

  // Clean exit.
  module_invoke_all('exit');
  exit;
}