Mercurial > hg > MPIWG-drupal-modules
diff sites/all/modules/custom/digitalobjects/digitalobjects.import.php @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sites/all/modules/custom/digitalobjects/digitalobjects.import.php Wed Jul 31 13:49:13 2013 +0200 @@ -0,0 +1,159 @@ +<?php + + + + + +function digitalobjects_importPagesFromFile(){ + $filename = "/tmp/maps.json"; + # $filename = "/tmp/echo.json"; + $handle = fopen($filename, "r"); + $contents = fread($handle, filesize($filename)); + fclose($handle); + + $pages = drupal_json_decode($contents); + + $cnt=0; + foreach ($pages as $key => $page){ + + $page = base64_decode($page); + digitalobjects_importPage($page,$key); + $cnt++; + + } + + +} + + +function digitalobjects_importPage($page,$key){ + + $baseUrl = "http://localhost:18080/echo_nav/echo_pages/content/scientific_revolution/harriot/maps/"; + + $fnames = explode("/",$key); + + if ($fnames[1] != "maps"){ + dpm($fnames[0]); + return; + } + + $fname = str_replace(".pt","1_1.png",$fnames[sizeof($fnames)-1]); + + $image = file_get_contents($baseUrl . $fname); // string + $file = file_save_data($image, 'public://' . $fname,FILE_EXISTS_REPLACE); + + + + + $node = new stdClass(); + $node->type = 'map_page'; + node_object_prepare($node); + + $node->body['und'][0]['value'] = check_markup($page,'full_html'); + + $node->body['und'][0]['format'] = 'full_html'; + + $node->path['alias']="harriot/maps/" . $fnames[sizeof($fnames)-1]; + + $node->title = "_".$key; + + + $node->language = LANGUAGE_NONE; + + + $node->field_echopath['und'][0]['value']=$key; + + $node->field_image[LANGUAGE_NONE]['0']['fid'] = $file->fid; + $node = node_submit($node); + + + + + /*$node->field_admintag['und'][0] = array ( + 'tid' => $tid, + + );*/ + // Try to set your custom field + + $node = node_submit($node); + + node_save($node); + + } + + + +function digitalobjects_importCollectionFromFile() { + + + $filename = "/tmp/china.json"; + $handle = fopen($filename, "r"); + $contents = fread($handle, filesize($filename)); + fclose($handle); + + $collection = drupal_json_decode($contents); + digitalobjects_importCollection($collection); +} + +function digitalobjects_importCollection($collection,$tid){ + + $node = new stdClass(); + $node->type = 'digitalcollection'; + node_object_prepare($node); + + $node->body['und'][0]['value'] = check_markup($collection['description'],'full_html'); + + $node->body['und'][0]['format'] = 'full_html'; + + + $node->title = $collection['title']; + + + $node->language = LANGUAGE_NONE; + + + $node->field_echopath['und'][0]['value']=$collection['echo_path']; + $node->field_label['und'][0]['value']=$collection['label']; + $node = node_submit($node); + + + $cnt=0; + foreach ($collection['content'] as $cont){ + print $cont; + if (($cont != "") && ($cont !=null)){ + $node->field_objid['und'][$cnt]['objid']=$cont; + $cnt++; + + + } + } + + $node->field_admintag['und'][0] = array ( + 'tid' => $tid, + + ); + // Try to set your custom field + + $node = node_submit($node); + + node_save($node); + +} + +function digitalobjects_importCollections($tid) { + $filename = "/tmp/export.json"; + # $filename = "/tmp/echo.json"; + $handle = fopen($filename, "r"); + $contents = fread($handle, filesize($filename)); + fclose($handle); + + $collections = drupal_json_decode($contents); + + $cnt=0; + foreach ($collections as $key => $collection){ + digitalobjects_importCollection($collection,$tid); + $cnt++; + + } + +} \ No newline at end of file