1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* The Node export JSON format handler.
|
6 |
|
|
*
|
7 |
|
|
* Adds JSON format to Node export.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Export callback.
|
12 |
|
|
*/
|
13 |
|
|
function node_export_json_export($nodes, $format) {
|
14 |
|
|
return drupal_json_encode(node_export_json_encode_objects($nodes));
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Import callback.
|
19 |
|
|
*/
|
20 |
|
|
function node_export_json_import($code_string) {
|
21 |
|
|
return node_export_json_decode_objects(drupal_json_decode($code_string));
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Mark objects as being objects.
|
26 |
|
|
*/
|
27 |
|
|
function node_export_json_encode_objects($var) {
|
28 |
|
|
if (is_object($var)) {
|
29 |
|
|
$var = (array)$var;
|
30 |
|
|
$var['#node_export_object'] = '1';
|
31 |
|
|
}
|
32 |
|
|
if (is_array($var)) {
|
33 |
|
|
foreach ($var as $key => $value) {
|
34 |
|
|
$var[$key] = node_export_json_encode_objects($value);
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
return $var;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Recursively convert arrays back to objects.
|
42 |
|
|
*/
|
43 |
|
|
function node_export_json_decode_objects($array) {
|
44 |
|
|
if (is_array($array)) {
|
45 |
|
|
foreach ($array as $k => $v) {
|
46 |
|
|
if (is_array($v)) {
|
47 |
|
|
$array[$k] = node_export_json_decode_objects($v);
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
if (isset($array['#node_export_object'])) {
|
51 |
|
|
unset($array['#node_export_object']);
|
52 |
|
|
$array = (object)$array;
|
53 |
|
|
}
|
54 |
|
|
return $array;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
/**
|
59 |
|
|
* Callback for actions.
|
60 |
|
|
*/
|
61 |
|
|
function node_export_json_action_form($context, &$form_state) {
|
62 |
|
|
return node_export_action_form($context, $form_state, 'json');
|
63 |
|
|
} |