You are here

function export_node_export in Node export 5

Same name and namespace in other branches
  1. 5.2 export.pages.inc \export_node_export()
  2. 6 export.pages.inc \export_node_export()

Exports a node - return export code in a textarea

1 string reference to 'export_node_export'
export_menu in ./export.module
Implementation of hook_menu().

File

./export.module, line 149

Code

function export_node_export($nid) {
  if (is_numeric($nid)) {
    global $user;
    $node = node_load($nid);
    if (isset($node->nid) && export_is_permitted($node->type)) {
      $original_node = drupal_clone($node);
      $node->nid = NULL;
      $node->vid = NULL;
      $node->name = $user->name;
      $node->uid = $user->uid;
      $node->created = NULL;
      $node->menu = NULL;
      $node->path = NULL;
      $node->files = array();
      $node->title = t('!title', array(
        '!title' => $node->title,
      ));
      drupal_set_title(check_plain($node->title));
      if (variable_get('export_reset_' . $node->type, FALSE)) {
        $node_options = variable_get('node_options_' . $node->type, array(
          'status',
          'promote',
        ));

        // fill in the default values
        foreach (array(
          'status',
          'moderate',
          'promote',
          'sticky',
          'revision',
        ) as $key) {
          $node->{$key} = in_array($key, $node_options);
        }
      }

      // Let other modules do special fixing up.
      // The function signature is: hook_export_node_alter(&$node, $original_node, $method)
      foreach (module_implements('export_node_alter') as $module) {
        $function = $module . '_export_node_alter';
        $function($node, $original_node, "prepopulate");
      }
      $node_code = var_export($node, true);
      $node_code = str_replace('stdClass::__set_state(array(', 'node(code(', $node_code);
      $form['export'] = array(
        '#type' => 'textarea',
        '#title' => t('Node Code'),
        '#default_value' => $node_code,
        '#rows' => 30,
        '#description' => t('Copy this code and then on the site you want to import to, go to the Import Node link under Content Management, and paste it in there.'),
      );
      return $form;
    }
  }
}