drupal.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * The Node export Drupal format handler.
  5. *
  6. * Adds Drupal var export format to Node export.
  7. */
  8. /**
  9. * Export callback.
  10. */
  11. function node_export_drupal_export($nodes, $format) {
  12. require_once DRUPAL_ROOT . '/includes/utility.inc';
  13. return drupal_var_export($nodes);
  14. }
  15. /**
  16. * Import callback.
  17. */
  18. function node_export_drupal_import($code_string) {
  19. if (substr(ltrim($code_string), 0, 6) == "array(") {
  20. $nodes = eval('return ' . $code_string . ';');
  21. if (is_array($nodes)) {
  22. return node_export_drupal_decode_objects($nodes);
  23. }
  24. }
  25. }
  26. /**
  27. * Recursively convert arrays back to objects.
  28. *
  29. * This is only for backwards compatibility with the deprecated node_code format.
  30. */
  31. function node_export_drupal_decode_objects($array) {
  32. foreach ($array as $k => $v) {
  33. if (is_array($v)) {
  34. $array[$k] = node_export_drupal_decode_objects($v);
  35. }
  36. }
  37. if (isset($array['#_export_node_encode_object'])) {
  38. unset($array['#_export_node_encode_object']);
  39. $array = (object)$array;
  40. }
  41. return $array;
  42. }
  43. /**
  44. * Callback for actions.
  45. */
  46. function node_export_drupal_action_form($context, &$form_state) {
  47. return node_export_action_form($context, $form_state, 'drupal');
  48. }