0
|
1 <?php
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7 function digitalobjects_importPagesFromFile(){
|
|
8 $filename = "/tmp/maps.json";
|
|
9 # $filename = "/tmp/echo.json";
|
|
10 $handle = fopen($filename, "r");
|
|
11 $contents = fread($handle, filesize($filename));
|
|
12 fclose($handle);
|
|
13
|
|
14 $pages = drupal_json_decode($contents);
|
|
15
|
|
16 $cnt=0;
|
|
17 foreach ($pages as $key => $page){
|
|
18
|
|
19 $page = base64_decode($page);
|
|
20 digitalobjects_importPage($page,$key);
|
|
21 $cnt++;
|
|
22
|
|
23 }
|
|
24
|
|
25
|
|
26 }
|
|
27
|
|
28
|
|
29 function digitalobjects_importPage($page,$key){
|
|
30
|
|
31 $baseUrl = "http://localhost:18080/echo_nav/echo_pages/content/scientific_revolution/harriot/maps/";
|
|
32
|
|
33 $fnames = explode("/",$key);
|
|
34
|
|
35 if ($fnames[1] != "maps"){
|
|
36 dpm($fnames[0]);
|
|
37 return;
|
|
38 }
|
|
39
|
|
40 $fname = str_replace(".pt","1_1.png",$fnames[sizeof($fnames)-1]);
|
|
41
|
|
42 $image = file_get_contents($baseUrl . $fname); // string
|
|
43 $file = file_save_data($image, 'public://' . $fname,FILE_EXISTS_REPLACE);
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48 $node = new stdClass();
|
|
49 $node->type = 'map_page';
|
|
50 node_object_prepare($node);
|
|
51
|
|
52 $node->body['und'][0]['value'] = check_markup($page,'full_html');
|
|
53
|
|
54 $node->body['und'][0]['format'] = 'full_html';
|
|
55
|
|
56 $node->path['alias']="harriot/maps/" . $fnames[sizeof($fnames)-1];
|
|
57
|
|
58 $node->title = "_".$key;
|
|
59
|
|
60
|
|
61 $node->language = LANGUAGE_NONE;
|
|
62
|
|
63
|
|
64 $node->field_echopath['und'][0]['value']=$key;
|
|
65
|
|
66 $node->field_image[LANGUAGE_NONE]['0']['fid'] = $file->fid;
|
|
67 $node = node_submit($node);
|
|
68
|
|
69
|
|
70
|
|
71
|
|
72 /*$node->field_admintag['und'][0] = array (
|
|
73 'tid' => $tid,
|
|
74
|
|
75 );*/
|
|
76 // Try to set your custom field
|
|
77
|
|
78 $node = node_submit($node);
|
|
79
|
|
80 node_save($node);
|
|
81
|
|
82 }
|
|
83
|
|
84
|
|
85
|
|
86 function digitalobjects_importCollectionFromFile() {
|
|
87
|
|
88
|
|
89 $filename = "/tmp/china.json";
|
|
90 $handle = fopen($filename, "r");
|
|
91 $contents = fread($handle, filesize($filename));
|
|
92 fclose($handle);
|
|
93
|
|
94 $collection = drupal_json_decode($contents);
|
|
95 digitalobjects_importCollection($collection);
|
|
96 }
|
|
97
|
|
98 function digitalobjects_importCollection($collection,$tid){
|
|
99
|
|
100 $node = new stdClass();
|
|
101 $node->type = 'digitalcollection';
|
|
102 node_object_prepare($node);
|
|
103
|
|
104 $node->body['und'][0]['value'] = check_markup($collection['description'],'full_html');
|
|
105
|
|
106 $node->body['und'][0]['format'] = 'full_html';
|
|
107
|
|
108
|
|
109 $node->title = $collection['title'];
|
|
110
|
|
111
|
|
112 $node->language = LANGUAGE_NONE;
|
|
113
|
|
114
|
|
115 $node->field_echopath['und'][0]['value']=$collection['echo_path'];
|
|
116 $node->field_label['und'][0]['value']=$collection['label'];
|
|
117 $node = node_submit($node);
|
|
118
|
|
119
|
|
120 $cnt=0;
|
|
121 foreach ($collection['content'] as $cont){
|
|
122 print $cont;
|
|
123 if (($cont != "") && ($cont !=null)){
|
|
124 $node->field_objid['und'][$cnt]['objid']=$cont;
|
|
125 $cnt++;
|
|
126
|
|
127
|
|
128 }
|
|
129 }
|
|
130
|
|
131 $node->field_admintag['und'][0] = array (
|
|
132 'tid' => $tid,
|
|
133
|
|
134 );
|
|
135 // Try to set your custom field
|
|
136
|
|
137 $node = node_submit($node);
|
|
138
|
|
139 node_save($node);
|
|
140
|
|
141 }
|
|
142
|
|
143 function digitalobjects_importCollections($tid) {
|
|
144 $filename = "/tmp/export.json";
|
|
145 # $filename = "/tmp/echo.json";
|
|
146 $handle = fopen($filename, "r");
|
|
147 $contents = fread($handle, filesize($filename));
|
|
148 fclose($handle);
|
|
149
|
|
150 $collections = drupal_json_decode($contents);
|
|
151
|
|
152 $cnt=0;
|
|
153 foreach ($collections as $key => $collection){
|
|
154 digitalobjects_importCollection($collection,$tid);
|
|
155 $cnt++;
|
|
156
|
|
157 }
|
|
158
|
|
159 } |