You are here

function node_export_node_encode in Node export 6.2

Build node code string recursively

2 calls to node_export_node_encode()
hook_node_export_node_encode_line_alter in ./node_export.api.php
Override one line of the export code output.
node_export_node_export in ./node_export.module
Exports a node - populate a node code form set $return_code to TRUE to not return form but the code instead. set $format to some string if encoding should be handled by some module that will recognise the string.

File

./node_export.module, line 868
The Node Export module.

Code

function node_export_node_encode($var, $iteration = 0, $format = NULL) {

  // Allow other modules to take over this entire process before the first
  // iteration.  Typically the module would respond if $format was set to
  // something it recognises.
  if ($iteration == 0) {
    $return = FALSE;
    drupal_alter('node_export_node_encode', $return, $var, $format);
    if ($return !== FALSE) {
      return $return;
    }
  }

  // Default node encoding.
  $tab = '';
  for ($i = 0; $i < $iteration; $i++) {
    $tab = $tab . "  ";
  }
  $iteration++;
  if (is_object($var)) {
    $var = (array) $var;
    $var['#_export_node_encode_object'] = '1';
  }
  if (is_array($var)) {
    $empty = empty($var);
    $code = "array(" . ($empty ? '' : "\n");
    foreach ($var as $key => $value) {
      $out = $tab . "  '" . $key . "' => " . node_export_node_encode($value, $iteration) . ",\n";
      drupal_alter('node_export_node_encode_line', $out, $tab, $key, $value, $iteration);
      $code .= $out;
    }
    $code .= ($empty ? '' : $tab) . ")";
    return $code;
  }
  else {
    if (is_string($var)) {

      // Escape single quotes so we don't accidentally exit the string.
      return "'" . strtr($var, array(
        "'" => "\\'",
      )) . "'";
    }
    elseif (is_numeric($var)) {
      return $var;
    }
    elseif (is_bool($var)) {
      return $var ? 'TRUE' : 'FALSE';
    }
    else {
      return 'NULL';
    }
  }
}