diff digitalobjects.module @ 0:6f6e07baad80 default tip

initial
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Tue, 02 Jun 2015 08:57:48 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/digitalobjects.module	Tue Jun 02 08:57:48 2015 +0200
@@ -0,0 +1,1112 @@
+<?php
+/* Implements hook_menu */
+
+
+/* TODOS
+ *
+ *
+ */
+include('digitalobject_reader.php');
+include('digitalobjects.import.php');
+include('digitalobjects.collections.inc');
+
+
+
+/** implement hook init experimental**/
+
+
+
+#function digitalobjects_init() {
+#  dpm("HUH");
+#  drupal_add_js(drupal_get_path('module', 'digitalobjects') .'/chooser.js');
+#}
+
+/**
+ * Implementation of hook_enable().
+ */
+
+function digitalobjects_enable() {
+
+  #adds a field for the current collection to the user bundle
+  #every user can select a current collection, where objects are added to
+  // Check if our field is not already created.
+  if (!field_info_field('field_digitalobjects_cid')) {
+    dpm("create field:field_digitalobjects_cidfor user");
+    $field = array(
+        'field_name' => 'field_digitalobjects_cid',
+        'type' => 'digitalobjects_digitalcollection',
+    );
+    field_create_field($field);
+
+    // Create the instance on the bundle.
+    $instance = array(
+        'field_name' => 'field_digitalobjects_cid',
+        'entity_type' => 'user',
+        'label' => 'Current collection',
+        'bundle' => 'user',
+        // If you don't set the "required" property then the field wont be required by default.
+        'required' => False,
+        'settings' => array(
+            // Here you inform either or not you want this field showing up on the registration form.
+            'user_register_form' => 1,
+        ),
+        'widget' => array(
+            'type' => 'digitalcollection_default_textfield',
+        ),
+    );
+    field_create_instance($instance);
+  }
+}
+
+function digitalobjects_menu(){
+
+    $items['digitalcollections/manageCurrent'] = array(
+        'description' => 'show an object.',
+        'page callback' => 'digitalobjects_digitalcollectionsManage',
+        'access arguments'   => array('access content'),
+        'file'               => 'digitalobjects.collections.inc',
+
+    );
+
+
+    $items['digitalobject'] = array(
+        'description' => 'show an object.',
+        'page callback' => 'digitalobjects_page',
+        'access arguments'   => array('access content'),
+
+    );
+     $items['admin/config/media/digitalobjects'] = array(
+            'title'              => 'Digitalobject',
+            'description'        => 'Set path to the metadaprovider for digitalobjects',
+            'weight'             => 10,
+            'page callback'      => 'drupal_get_form',
+            'page arguments'     => array('digitalobjects_settings'),
+            'access arguments'   => array('administrate digitalobjects'),
+            'file'               => 'digitalobjects.admin.inc',
+
+        );
+
+
+
+
+
+     $items['user/%/collections'] = array(
+         'title'              => 'Collections',
+         'description'        => 'Set path to the metadaprovider for digitalobjects',
+         'weight'             => 10,
+         'page callback'      => 'digitalobjects_user_admin_collection',
+         'page arguments'     => array(1),
+         'access arguments'   => array('manage private collections'),
+         'file'               => 'digitalobjects.collections.inc',
+         'type' => MENU_LOCAL_TASK,
+     );
+
+
+
+     $items['digitalobject/%/view'] = array(
+        'title'              => 'View',
+               'description' => 'show an object.',
+        'page callback' => 'digitalobjects_page',
+        'access arguments'   => array('access content'),
+            'page arguments'     => array(1),
+
+         'access arguments'   => array('access content'),
+          'type' => MENU_LOCAL_TASK,
+
+     );
+
+     $items['digitalobject/%/edit'] = array(
+         'title'              => 'Edit',
+         'description'        => 'Set path to the metadaprovider for digitalobjects',
+         'weight'             => 10,
+         'page callback'      => 'digitalobjects_edit',
+         'page arguments'     => array(1),
+
+         'access arguments'   => array('administrate digitalobjects'),
+         'type' => MENU_LOCAL_TASK,
+
+     );
+
+     $items['digitalobject/%/usage'] = array(
+         'title'              => 'Usage',
+         'description'        => 'Set path to the metadaprovider for digitalobjects',
+         'weight'             => 10,
+         'page callback'      => 'digitalobjects_show_usage',
+         'page arguments'     => array(1),
+
+         'access arguments'   => array('access content'),
+         'type' => MENU_LOCAL_TASK,
+
+     );
+
+     $items['digitalobject/%/add'] = array(
+         'title'              => 'Add',
+         'description'        => 'Add an object to the current collection',
+         'weight'             => 10,
+         'page callback'      => 'digitalobjects_addToCurrentCollection',
+         'page arguments'     => array(1),
+
+         'access arguments'   => array('administrate digitalobjects'),
+         'file'               => 'digitalobjects.collections.inc',
+         'type' => MENU_LOCAL_TASK,
+
+     );
+    return $items;
+
+}
+
+
+function  digitalobjects_create_primary_node($objid){
+$node = new stdClass();
+$node->type = 'digitalobject';
+node_object_prepare($node);
+global $user;
+#dpm($user);
+#$node->uid=$user->uid;
+$node->field_single_objid['und'][0]['objid']=$objid;
+
+$node->title = $objid;
+
+$node->language = LANGUAGE_NONE;
+#$node = node_submit($node);
+
+#$node->field_object_type['und'][0]=array('tid'=> '6');
+
+$foo = taxonomy_get_term_by_name('primary');
+foreach($foo as $term) {
+
+  if(($term->vocabulary_machine_name) == 'digitalobject_types') {
+
+    $node->field_object_type['und'][]['tid'] = $term->tid;
+  }
+}
+$node = node_submit($node);
+
+node_save($node);
+
+return $node;
+}
+
+function digitalobjects_edit($objid){
+  #suche ob es schon ein locales object zu dieser id gibt.
+  $query = new EntityFieldQuery();
+  $entities = $query->entityCondition('entity_type', 'node')
+  ->entityCondition('bundle', 'digitalobject')
+  ->fieldCondition('field_single_objid', 'objid', $objid,"=")
+  ->execute();
+
+  if ($entities == null) #existiert noch nicht, dann anlegen
+  {
+    $node =digitalobjects_create_primary_node($objid);
+    #$node->field_object_type['und'][0]=array('tid'=> 'autocreate',
+    #'name' => "primary",
+    #'vocabulary_machine_name' => 'digitialobject_types');
+
+  } else {
+
+
+  $nodes = node_load_multiple(array_keys($entities['node']));
+
+  #gibt es eins, dann gib dieses zum editieren zurück
+  #TODO falls mehrere existieren, was dann??
+
+  #gehe durch alle gefundene
+  foreach ($nodes as $node){
+    #$typeTag = $entity->object_type['und']
+
+    if (isset($node->field_object_type['und'])){
+    $tid = $node->field_object_type['und'][0]['tid'];
+    $tax =taxonomy_term_load($tid);
+    if ($tax->name == "primary"){ #'primary gefunden'
+      module_load_include('inc', 'node', 'node.pages');
+      return drupal_get_form('digitalobject_node_form', $node);
+    }}
+  } # keine primary dann lege diese an:
+
+  $node =digitalobjects_create_primary_node($objid);
+
+  #$vals = array_values($nodes);
+  #$node= array_shift($vals);
+  }
+
+  $node = node_submit($node);
+
+  #node_save($node);
+  module_load_include('inc', 'node', 'node.pages');
+
+  return drupal_get_form('digitalobject_node_form', $node);
+
+}
+
+
+function digitalobjects_show_usage($objid){
+  $query = new EntityFieldQuery();
+  $entities = $query->entityCondition('entity_type', 'node')
+  ->fieldCondition('field_objid', 'objid', $objid,"=")
+  ->execute();
+
+
+  $data = array();
+
+  #treffer gefunden
+  if (isset($entities['node'])){
+
+  $nodes = node_load_multiple(array_keys($entities['node']));
+
+
+  foreach ($nodes as $node){
+    $data[$node->nid] = $node->title;
+
+  }
+
+
+  $output['digitalobjects_item_usage']= array(
+      '#theme' => 'digitalobjects_item_usage',
+      '#data' => $data);
+
+  return $output;
+  }
+
+  return "<h2> object not used in a collection </h2>";
+  }
+
+
+function digitalobjects_page($keys = ''){
+
+
+  #suche ob es schon ein locales object zu dieser id gibt.
+  $query = new EntityFieldQuery();
+  $entities = $query->entityCondition('entity_type', 'node')
+  ->entityCondition('bundle', 'digitalobject')
+  ->fieldCondition('field_single_objid', 'objid', $keys,"=")
+  ->execute();
+
+  if ($entities == null) #existiert noch nicht, dann generische Anzeige
+  {
+
+  $output['digitalobjects_item']= array(
+  '#theme' => 'digitalobjects_item',
+  '#objid' => $keys);
+
+  return $output;
+  } else {
+    $nodes = node_load_multiple(array_keys($entities['node']));
+
+    #gibt es eins, dann gib dieses zum editieren zurück
+    #TODO falls mehrere existieren, was dann??
+
+    #gehe durch alle gefundene
+    foreach ($nodes as $node){
+      if (isset($node->field_object_type['und'])){
+        $tid = $node->field_object_type['und'][0]['tid'];
+        $tax =taxonomy_term_load($tid);
+
+        if ($tax->name == "primary"){ #'primary gefunden'
+          return node_view($node, $view_mode = 'full');
+        }
+      }
+    }
+    #keine primary node gefunden, generische ausgabe
+    $output['digitalobjects_item']= array(
+        '#theme' => 'digitalobjects_item',
+        '#objid' => $keys);
+    return $output;
+  }
+}
+
+/* implements digitalobject_theme */
+
+function digitalobjects_theme(){
+
+    return array(
+        'digitalobjects_item'  => array(
+            'variables' => array('objid' => NULL),
+            'file' => 'digitalobjects.item.inc',
+            'template' => 'digitalobjects-item',
+        ),
+        'digitalobjects_item_short'  => array(
+            'variables' => array('objid' => NULL),
+            'file' => 'digitalobjects.item.inc',
+            'template' => 'digitalobjects-item-short',
+        ),
+
+        'digitalobjects_item_thumbnail'  => array(
+            'variables' => array('objid' => NULL),
+            'file' => 'digitalobjects.item.inc',
+            'template' => 'digitalobjects-item-thumbnail',
+        ),
+
+	'digitalobjects_item_thumbnail_large'  => array(
+            'variables' => array('objid' => NULL),
+            'file' => 'digitalobjects.item.inc',
+            'template' => 'digitalobjects-item-thumbnail',
+        ),
+
+        'digitalobjects_item_objid'  => array(
+            'variables' => array('objid' => NULL),
+            'template' => 'digitalobjects-item-objid',
+        ),
+        'digitalobjects_item_tools'  => array(
+            'variables' => array('objid' => NULL),
+            'template' => 'digitalobjects-item-tools',
+        ),
+        'digitalobjects_item_usage'  => array(
+            'variables' => array('data' => NULL),
+            'template' => 'digitalobjects-item-usage',
+        ),
+        'digitalobjects_collection_simple'  => array(
+            'variables' => array('objid' => NULL),
+            'template' => 'digitalobjects-collection-simple',
+        ),
+        'digitalobjects_currentCollection_block'  => array(
+            'variables' => array('node' => NULL),
+            'template' => 'digitalobjects-current-collection',
+        ),
+        'digitalobjects_collection_nodeLink'  => array(
+            'variables' => array("entities" => $NULL),
+            'template' => 'digitalobjects-collection-nodeLink',
+        ),
+
+
+
+        'digitalobjects_item_xml'  => array(
+            'variables' => array('objid' => NULL),
+            'file' => 'digitalobjects.item.inc',
+            'template' => 'digitalobjects-item-xml',
+        ),
+
+        'digitalobjects_collection_usedIn'  => array(
+
+            'template' => 'digitalobjects-collection-usedIn',
+        ),
+
+        'digitalobjects_items'  => array(
+            'variables' => array('search_results' => NULL),
+            'template' => 'digitalobjects-items',
+        ),
+
+        'digitalobjects_image_src_link_viewer'  => array(
+            'variables' => array('src' => NULL,'link' => NULL),
+            'template' => 'digitalobjects-image_src_link_viewer',
+        ),
+
+        'digitalobjects_image_src_link_viewer_large'  => array(
+            'variables' => array('src' => NULL,'link' => NULL),
+            'template' => 'digitalobjects-image_src_link_viewer_large',
+        ),
+
+        'digitalobjects_pdf_link_viewer'  => array(
+            'variables' => array('title' => NULL,'link' => NULL),
+            'template' => 'digitalobjects-pdf_link_viewer',
+        ),
+
+     /*   'digitalobjects_user_admin_page' => array(
+         'variables' => array('digitalobjects_user_admin','uid' =>1),
+        'template'  => 'digitalobjects-user-admin-form'
+         ),*/
+            );
+}
+
+function digitalobjects_forms($form_id, $args) {
+
+  $forms['digitalobjects_user_admin_form']= array(
+      'callback' => 'digitalobjects_user_admin',
+      'callback arguments' => array('digitalobjects_user_admin_page'),
+  );
+  return $forms;
+};
+
+
+
+
+function digitalobjects_user_admin(array $form, array &$form_state) {
+
+  $form['digitalcollection'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Active collection'),
+      '#size' => 15,
+      '#default_value' => 'xxxx',
+      '#attributes' => array('title' => t('Enter the terms id of the current collection.')),
+  );
+
+
+  $form['userid'] = array(
+      '#type' => 'hidden',
+  );
+  #$form['actions'] = array('#type' => 'actions');
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
+  $form['submit']['#submit'][] = 'digitalobjects_user_admin_form_submit';
+
+  return $form;
+}
+/* implements a new field type for the digitalobject id */
+
+function digitalobjects_field_info(){
+
+  return array('digitalobjects_digitalobject' => array (
+      'label' => t('Digital Object ID'),
+      'description' => t('This field stores a digital object ID'),
+      'settings' => array('max_length' =>20),
+     'instance_settings' => array('text_processing' => 0),
+      'default_widget' => 'digitalobject_default_textfield',
+      'default_formatter' => 'digitalobjects_fullmetadata',
+    ),
+      'digitalobjects_digitalcollection' => array (
+          'label' => t('Digital Collection ID'),
+          'description' => t('This field stores a digital collection ID'),
+          'settings' => array('max_length' =>20),
+          'instance_settings' => array('text_processing' => 0),
+          'default_widget' => 'digitalcollection_default_textfield',
+          'default_formatter' => 'digitalcollection_fullmetadata',
+          ),
+
+
+  );
+
+
+}
+
+
+
+
+function digitalobjects_field_formatter_info() {
+
+  return array(
+      // This formatter shows the obejct with fullmetadata
+      'digitalobjects_fullmetadata' => array(
+          'label' => t('Fullmetadata formatter'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+      'digitalobjects_label' => array(
+          'label' => t('Label formatter'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+      'digitalobjects_thumbnail' => array(
+          'label' => t('Thumbnail formatter (100px'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+
+      'digitalobjects_thumbnail_large' => array(
+          'label' => t('Thumbnail formatter (l200px)'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+      'digitalobjects_objid' => array(
+          'label' => t('Objid as String formatter'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+
+      'digitalobjects_xml' => array(
+          'label' => t('Objids as XML formatter'),
+          'field types' => array('digitalobjects_digitalobject'),
+      ),
+
+      'digitalobjects_collection_simple' => array(
+          'label' => t('Simple formatter'),
+          'field types' => array('digitalobjects_digitalcollection'),
+      ),
+      'digitalobjects_image_src_link_viewer' => array(
+          'label' => t('View Image and Link from URL'),
+          'field types' => array('link_field'),
+      ),
+
+      'digitalobjects_image_src_link_viewer_large' => array(
+          'label' => t('View Image and Link from URL (200px)'),
+          'field types' => array('link_field'),
+      ),
+  	'digitalobjects_image_viewer' => array(
+  				'label' => t('View filename as image with link to digilib'),
+  				'field types' => array('text'),
+  		),
+	'digitalobjects_image_viewer_large' => array(
+  				'label' => t('View filename as image (200px) with link to digilib'),
+  				'field types' => array('text'),
+  		),
+      'digitalobjects_pdf_link_viewer' => array(
+          'label' => t('View PDF in external viewer'),
+          'field types' => array('link_field'),
+      ),
+
+  );
+  }
+
+
+
+
+
+
+ function digitalobjects_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+    $element = array();
+
+
+    switch ($display['type']) {
+
+      case 'digitalobjects_image_viewer':
+        foreach ($items as $delta => $item) {
+
+          $value = $item['value'];
+
+          $linkbase= variable_get('digitalobjects_imagebase_digilib_path');
+          
+          $value = str_replace(' ', '_', $value);
+
+          $link = $linkbase . $value;
+
+          $srcbase=variable_get('digitalobjects_imagebase_scaler_path');
+
+          $src= $srcbase . $value;
+
+
+          $element[$delta]['#markup'] = theme('digitalobjects_image_src_link_viewer', array("src" => $src,"link" => $link));
+
+
+        }
+        break;
+
+  case 'digitalobjects_image_viewer_large':
+        foreach ($items as $delta => $item) {
+
+          $value = $item['value'];
+
+          $linkbase= variable_get('digitalobjects_imagebase_digilib_path');
+          
+          $value = str_replace(' ', '_', $value);
+
+          $link = $linkbase . $value;
+
+          $srcbase=variable_get('digitalobjects_imagebase_scaler_path_large');
+
+          $src= $srcbase . $value;
+
+
+          $element[$delta]['#markup'] = theme('digitalobjects_image_src_link_viewer_large', array("src" => $src,"link" => $link));
+
+
+        }
+        break;
+
+
+
+
+      case 'digitalobjects_fullmetadata':
+        foreach ($items as $delta => $item) {
+          if ($item['objid']!=""){
+            $element[$delta]['#markup'] = theme('digitalobjects_item_tools', array("objid" => $item['objid']));
+            $element[$delta]['#markup'] .= theme('digitalobjects_item', array("objid" => $item['objid']));
+
+          }
+        }
+
+        break;
+
+      case 'digitalobjects_label':
+        foreach ($items as $delta => $item) {
+          if ($item['objid']!=""){
+
+            $element[$delta]['#markup'] = theme('digitalobjects_item_short', array("objid" => $item['objid']));
+            $element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid']));
+          }
+        }
+        break;
+
+        case 'digitalobjects_thumbnail':
+          foreach ($items as $delta => $item) {
+            if ($item['objid']!=""){
+
+              $element[$delta]['#markup'] = theme('digitalobjects_item_thumbnail', array("objid" => $item['objid']));
+              #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid']));
+            }
+          }
+          break;
+
+  case 'digitalobjects_thumbnail_large':
+          foreach ($items as $delta => $item) {
+            if ($item['objid']!=""){
+
+              $element[$delta]['#markup'] = theme('digitalobjects_item_thumbnail_large', array("objid" => $item['objid']));
+              #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid']));
+            }
+          }
+          break;
+
+
+          case 'digitalobjects_objid':
+            foreach ($items as $delta => $item) {
+              if ($item['objid']!=""){
+
+                $element[$delta]['#markup'] = theme('digitalobjects_item_objid', array("objid" => $item['objid']));
+                #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid']));
+              }
+            }
+            break;
+
+        case 'digitalobjects_xml':
+          foreach ($items as $delta => $item) {
+            if ($item['objid']!=""){
+              $element[$delta]['#markup'] = theme('digitalobjects_item_xml', array("objid" => $item['objid']));
+          }
+          }
+          break;
+
+         case 'digitalobjects_collection_xml':
+            foreach ($items as $delta => $item) {
+              if ($item['objid']!=""){
+
+                $path=$item['objid'];
+                //path is node, d.h. beginnt mit node/
+
+                if (!strncmp($path, "node/", strlen("node/"))){
+                  $nid = str_replace("node/","",$path);
+                  $entities = entity_load("node",array($nid));
+
+                  $element[$delta]['#markup'] = theme('digitalobjects_collection_nodeLink_xml', array("entities" => $entities));
+
+                } else {
+
+
+                  $element[$delta]['#markup'] = theme('digitalobjects_collection_simple_xml', array("objid" => $item['objid']));
+
+                }
+              }
+            }
+            break;
+
+
+          case 'digitalobjects_image_src_link_viewer':
+	  case 'digitalobjects_image_src_link_viewer_large':
+            #nimmt den link aus dem link feld und macht unter der Annahme er geht auf diglib ein Bild daraus
+            foreach ($items as $delta => $item) {
+
+                #title feld ist leer, dann:
+                #$scal="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?";
+
+                $scal = variable_get('digitalobjects_scaler_path');
+
+                #$img="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?";
+
+                $img=variable_get('digitalobjects_digilib_path');
+                $src= str_replace($img, $scal, $item['url']);
+
+                $src=$src . "&dw=500";
+
+		
+
+              $element[$delta]['#markup'] = theme($display['type'], array("src" => $src,"link" => $item['url']));
+
+
+            }
+            break;
+
+          case 'digitalobjects_pdf_link_viewer':
+            #nimmt link aus link field und zeigt dieses mit externem pdf viewer an
+            foreach ($items as $delta => $item) {
+              #$pdfViewer="http://content.mpiwg-berlin.mpg.de/pdfViewer/pdf.js-master/web/viewer.html?file=";
+              $pdfViewer=variable_get('digitalobjects_pdfviewer_path');
+              $pdfpath=variable_get('digitalobjects_repository_path');
+
+              #url contains $base root should be removed
+              global $base_root;
+
+              $url = str_replace($base_root,"",$item['url']);
+              $pdfLink=$pdfViewer . $pdfpath . $url;
+
+              $element[$delta]['#markup'] = theme('digitalobjects_pdf_link_viewer', array("title" => $item['title'],"link" => $pdfLink));
+            }
+            break;
+
+
+
+
+
+    }
+    return $element;
+ }
+
+function template_preprocess_digitalobjects_items(&$variables) {
+   $variables['search_results'] = '';
+
+   $viewMode="shortX";
+
+   foreach ($variables['results'] as $result) {
+
+   switch ($viewMode) {
+
+     case "short":
+       $variables['search_results']  .= theme('digitalobjects_item_tools', array("objid" => $result['objid']));
+       $variables['search_results'] .= theme('digitalobjects_item_short', array('objid' => $result['objid']));
+
+       break;
+
+
+     default:
+         $variables['search_results']  .= theme('digitalobjects_item_tools', array("objid" => $result['objid'], 'objidcss' => digitalobjects_clean_css_identifier($result['objid'])));
+         $variables['search_results'] .= theme('digitalobjects_item', array('objid' => $result['objid']));
+
+         break;
+   }
+
+   }
+   $variables['pager'] = theme('pager', array('tags' => NULL,'quantity'=> 2));
+
+ }
+
+
+
+function digitalobjects_field_widget_info() {
+  #TODO:both types should check if field is valid
+   return array(
+       'digitalobject_default_textfield' => array(
+           'label' => t('digitalobject id'),
+           'field types' => array('digitalobjects_digitalobject'),
+       ),
+       'digitalcollection_default_textfield' => array(
+           'label' => t('digital collection id'),
+           'field types' => array('digitalobjects_digitalcollection'),
+       ),
+       'digitalobjects_objpager_default' => array(
+           'label' => t('No edit widget'),
+           'field types' => array('digitalobjects_itemView'),
+           'behaviors' => array(
+               'multiple values' => FIELD_BEHAVIOR_CUSTOM,
+               )
+       ),
+
+       );
+  }
+
+ function digitalobjects_field_postrender($string){
+  /* String is:
+   * <div class="form-item form-type-textfield form-item-field-objid-und-0-objid">
+  <input type="text" id="edit-field-objid-und-0-objid" name="field_objid[und][0][objid]" value="" size="20" maxlength="20" class="form-text" />
+</div>
+*/
+
+   // get value:
+
+   preg_match('/value="([^"]*)"/',$string,$matches);
+   $value = $matches[1];
+   $bib = digitalobjects_readMetadata($value,"short");
+   $string = $string . "<div>" . $bib['bibdata'] . "</div>";
+   return $string;
+ }
+
+ function digitalobjects_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+
+
+   $field_name = $field['field_name'];
+   $field_type = $field['type'];
+
+
+   $value = isset($items[$delta]['objid']) ? $items[$delta]['objid'] : '';
+
+   $widget = $element;
+   $widget['#delta'] = $delta;
+
+   switch ($instance['widget']['type']) {
+
+
+
+     case 'digitalobject_default_textfield':
+       $widget += array(
+       '#type' => 'textfield',
+       '#default_value' => $value,
+       '#size' => 20,
+       '#maxlength' => 20,
+       '#post_render' => array('digitalobjects_field_postrender'),
+           );
+
+
+
+       $element['objid'] = $widget;
+
+           break;
+
+     case 'digitalcollection_default_textfield':
+             $widget += array(
+             '#type' => 'textfield',
+             '#default_value' => $value,
+             '#size' => 20,
+             '#maxlength' => 20,
+             );
+
+             $element['objid'] = $widget;
+             break;
+
+
+   }
+
+
+
+
+   return $element;
+ }
+
+
+ function digitalobjects_field_is_empty($item, $field){
+
+   return empty($item['objid']);
+ }
+
+
+
+ /*admin current collection for a user */
+
+function digitalobjects_user_admin_form_submit($form,$formstate){
+  $value = $formstate['values']['digitalcollection'];
+  $userid = $formstate['values']['userid'];
+
+  $user=user_load($userid);
+
+
+  $user->field_digitalobjects_cid['und'][0]['objid'] = $value;
+
+  user_save($user);
+
+}
+
+
+/* show current collection of the current user as block */
+function digitalobjects_block_info(){
+  $blocks['digitalobjects_currentCollection'] = array(
+      'info' => t('Current Collection'),
+      'visibility' => BLOCK_VISIBILITY_PHP,
+      'pages' => '<?php global $user; if ($user->uid == 0) return FALSE; else return TRUE; ?>'
+  );
+
+  $blocks['digitalobjects_collection_usedIn'] = array(
+      'info' => t('Collection used in')
+  );
+
+  $blocks['digitalobjects_block_items'] = array(
+      'info' => t('Items of a collection (if page is a collection)')
+  );
+
+
+  return $blocks;
+}
+
+function digitalobjects_block_view($delta){
+
+  switch($delta){
+
+  case 'digitalobjects_currentCollection':
+    /* display current cullection */
+
+    global $user;
+
+    $user_full=user_load($user->uid);
+
+    if (isset($user_full->field_digitalobjects_cid['und'][0]['objid'])){
+    $val = $user_full->field_digitalobjects_cid['und'][0]['objid'];
+    } else {
+      return;
+    }
+    $node = node_load($val);
+
+    #$title = $node=>title;
+
+   $block['content'] = theme('digitalobjects_currentCollection_block',array('node' => $node));
+
+   $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
+   $form['submit']['#submit'][] = 'digitalobjects_user_admin_collection';
+
+   $submitForm=drupal_get_form('digitalobjects_change_collection_button_form');
+   $block['content'] .= drupal_render($submitForm);
+   return $block;
+   break;
+
+
+  case 'digitalobjects_collection_usedIn':
+    if ($node = menu_get_object()) {
+      // Get the nid
+      $nid = $node->nid;
+      $entities = digitalcollection_used_id($nid);
+
+      $block['content'] = theme('digitalobjects_collection_usedIn',array('entities'=> $entities));
+      return $block;
+    }
+
+  case 'digitalobjects_block_items':
+    if ($entity = menu_get_object()) {
+
+    #$element[$delta]['prefix']['#markup'] = '<ol class="search-results">';
+
+      if(!isset($entity->field_objid[LANGUAGE_NONE])){
+        break;
+      }
+
+      $resultsAll = $entity->field_objid[LANGUAGE_NONE];
+
+
+
+      $nums_per_page = 10;
+
+      $params = drupal_get_query_parameters();
+      if (isset($params['page'])){
+        $page = $params['page'];
+      } else {
+        $page = 0;
+      }
+
+
+      $start=$nums_per_page * intval($page);
+
+      if ($resultsAll==null){
+        break;
+      }
+
+      $results = array_slice($resultsAll,$start,$nums_per_page);
+
+
+
+      pager_default_initialize(sizeof($resultsAll),$nums_per_page);
+
+
+
+      #foreach ($results as $entry) {
+      #  $element[$delta][]['#markup'] = $entry;
+      #}
+
+      #$element[$delta]['suffix']['#markup'] = '</ol>' . theme('pager');
+
+       $block['content']  = theme('digitalobjects_items', array('results' => $results));
+
+      // Finally, display the pager controls, and return.
+      #$element[$delta]['#markup']  .= theme('pager');
+
+
+    #dpm(theme('pager'));
+    return $block;
+    break;
+    }
+
+
+  }
+
+  //return $block;
+}
+
+function digitalobjects_change_collection_button_form(){
+  include_once 'digitalobjects.collections.inc';
+  global $user;
+  $form['userid'] = array(
+
+      '#type' => 'hidden',
+      '#value' => $user->uid
+  );
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('change'));
+  $form['submit']['#submit'][] = 'digitalobjects_user_admin_collection_submit';
+
+  return $form;
+}
+
+function digitalobjects_permission() {
+  return array(
+      'manage private collections' => array(
+          'title' => t('Manage private collections'),
+          'description' => t('Allow users create and manage private collections.'),
+      ),
+      'administrate digitalobjects' => array(
+          'title' => t('Administrate digitalobjects'),
+          'description' => t('Can add commentaries to digital objects.'),
+      ),
+  );
+}
+
+
+function digitalobjects_pathologic_alter(&$url_params, $parts, $settings){
+#bilder ohne jegliche pfad angaben werden auf sites/default/files/..
+  if (preg_match('~^([^/]*)\.(png|gif|jpe?g)$~', $url_params['path'])){
+
+    $url_params['path'] = 'sites/default/files/' . $url_params['path'];
+  }
+
+  if (preg_match('~^./([^/]*)\.pt$~', $url_params['path'],$matches)){
+
+    $url_params['path'] = 'harriot/maps/' . $matches[1] . '.pt';
+  }
+
+}
+
+function digitalobjects_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
+
+    foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
+        $info = field_info_field($name);
+        #map the whole attr
+
+        if ($info['type'] == 'digitalobjects_digitalobject') {
+            $targets[$name] = array(
+                    'name' => t('@name', array('@name' => $instance['label'])),
+                    'callback' => 'digitalobjects_feeds_set_target',
+                    'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
+                    'real_target' => $name,
+            );
+        }
+    }
+}
+
+function digitalobjects_feeds_set_target($source, $entity, $target, $value) {
+
+    if (empty($value)) {
+        return;
+    }
+
+    // Handle non-multiple value fields.
+    if (!is_array($value)) {
+        $value = array($value);
+    }
+
+    // Iterate over all values.
+    #list($field_name, $column) = explode(':', $target);
+
+    $field_name=$target;
+    $info = field_info_field($field_name);
+
+    $field = isset($entity->$field_name) ? $entity->$field_name : array();
+    $delta = 0;
+
+    foreach ($value as $v) {
+
+        if ($info['cardinality'] == $delta) {
+            break;
+        }
+
+        if (is_object($v) && ($v instanceof FeedsElement)) {
+            $v = $v->getValue();
+        }
+
+        if (is_scalar($v)) {
+            $field['und'][$delta]['objid'] = $v;
+            $delta++;
+        }
+
+        if (is_array($v)){
+            $newVal = array();
+
+            $newVal['objid'] = $v;
+            $field['und'][$delta]= $newVal;
+            $delta++;
+        }
+    }
+    $entity->$field_name = $field;
+}
+
+//Provide a function to generate a valid identifier from the objectid
+//taken from views module
+
+function digitalobjects_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) {
+  // By default, we filter using Drupal's coding standards.
+  $identifier = strtr($identifier, $filter);
+
+  // Valid characters in a CSS identifier are:
+  // - the hyphen (U+002D)
+  // - a-z (U+0030 - U+0039)
+  // - A-Z (U+0041 - U+005A)
+  // - the underscore (U+005F)
+  // - 0-9 (U+0061 - U+007A)
+  // - ISO 10646 characters U+00A1 and higher
+  // We strip out any character not in the above list.
+  $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier);
+
+  return $identifier;
+}