Mercurial > hg > digitalobjects
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6f6e07baad80 |
---|---|
1 <?php | |
2 /* Implements hook_menu */ | |
3 | |
4 | |
5 /* TODOS | |
6 * | |
7 * | |
8 */ | |
9 include('digitalobject_reader.php'); | |
10 include('digitalobjects.import.php'); | |
11 include('digitalobjects.collections.inc'); | |
12 | |
13 | |
14 | |
15 /** implement hook init experimental**/ | |
16 | |
17 | |
18 | |
19 #function digitalobjects_init() { | |
20 # dpm("HUH"); | |
21 # drupal_add_js(drupal_get_path('module', 'digitalobjects') .'/chooser.js'); | |
22 #} | |
23 | |
24 /** | |
25 * Implementation of hook_enable(). | |
26 */ | |
27 | |
28 function digitalobjects_enable() { | |
29 | |
30 #adds a field for the current collection to the user bundle | |
31 #every user can select a current collection, where objects are added to | |
32 // Check if our field is not already created. | |
33 if (!field_info_field('field_digitalobjects_cid')) { | |
34 dpm("create field:field_digitalobjects_cidfor user"); | |
35 $field = array( | |
36 'field_name' => 'field_digitalobjects_cid', | |
37 'type' => 'digitalobjects_digitalcollection', | |
38 ); | |
39 field_create_field($field); | |
40 | |
41 // Create the instance on the bundle. | |
42 $instance = array( | |
43 'field_name' => 'field_digitalobjects_cid', | |
44 'entity_type' => 'user', | |
45 'label' => 'Current collection', | |
46 'bundle' => 'user', | |
47 // If you don't set the "required" property then the field wont be required by default. | |
48 'required' => False, | |
49 'settings' => array( | |
50 // Here you inform either or not you want this field showing up on the registration form. | |
51 'user_register_form' => 1, | |
52 ), | |
53 'widget' => array( | |
54 'type' => 'digitalcollection_default_textfield', | |
55 ), | |
56 ); | |
57 field_create_instance($instance); | |
58 } | |
59 } | |
60 | |
61 function digitalobjects_menu(){ | |
62 | |
63 $items['digitalcollections/manageCurrent'] = array( | |
64 'description' => 'show an object.', | |
65 'page callback' => 'digitalobjects_digitalcollectionsManage', | |
66 'access arguments' => array('access content'), | |
67 'file' => 'digitalobjects.collections.inc', | |
68 | |
69 ); | |
70 | |
71 | |
72 $items['digitalobject'] = array( | |
73 'description' => 'show an object.', | |
74 'page callback' => 'digitalobjects_page', | |
75 'access arguments' => array('access content'), | |
76 | |
77 ); | |
78 $items['admin/config/media/digitalobjects'] = array( | |
79 'title' => 'Digitalobject', | |
80 'description' => 'Set path to the metadaprovider for digitalobjects', | |
81 'weight' => 10, | |
82 'page callback' => 'drupal_get_form', | |
83 'page arguments' => array('digitalobjects_settings'), | |
84 'access arguments' => array('administrate digitalobjects'), | |
85 'file' => 'digitalobjects.admin.inc', | |
86 | |
87 ); | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 $items['user/%/collections'] = array( | |
94 'title' => 'Collections', | |
95 'description' => 'Set path to the metadaprovider for digitalobjects', | |
96 'weight' => 10, | |
97 'page callback' => 'digitalobjects_user_admin_collection', | |
98 'page arguments' => array(1), | |
99 'access arguments' => array('manage private collections'), | |
100 'file' => 'digitalobjects.collections.inc', | |
101 'type' => MENU_LOCAL_TASK, | |
102 ); | |
103 | |
104 | |
105 | |
106 $items['digitalobject/%/view'] = array( | |
107 'title' => 'View', | |
108 'description' => 'show an object.', | |
109 'page callback' => 'digitalobjects_page', | |
110 'access arguments' => array('access content'), | |
111 'page arguments' => array(1), | |
112 | |
113 'access arguments' => array('access content'), | |
114 'type' => MENU_LOCAL_TASK, | |
115 | |
116 ); | |
117 | |
118 $items['digitalobject/%/edit'] = array( | |
119 'title' => 'Edit', | |
120 'description' => 'Set path to the metadaprovider for digitalobjects', | |
121 'weight' => 10, | |
122 'page callback' => 'digitalobjects_edit', | |
123 'page arguments' => array(1), | |
124 | |
125 'access arguments' => array('administrate digitalobjects'), | |
126 'type' => MENU_LOCAL_TASK, | |
127 | |
128 ); | |
129 | |
130 $items['digitalobject/%/usage'] = array( | |
131 'title' => 'Usage', | |
132 'description' => 'Set path to the metadaprovider for digitalobjects', | |
133 'weight' => 10, | |
134 'page callback' => 'digitalobjects_show_usage', | |
135 'page arguments' => array(1), | |
136 | |
137 'access arguments' => array('access content'), | |
138 'type' => MENU_LOCAL_TASK, | |
139 | |
140 ); | |
141 | |
142 $items['digitalobject/%/add'] = array( | |
143 'title' => 'Add', | |
144 'description' => 'Add an object to the current collection', | |
145 'weight' => 10, | |
146 'page callback' => 'digitalobjects_addToCurrentCollection', | |
147 'page arguments' => array(1), | |
148 | |
149 'access arguments' => array('administrate digitalobjects'), | |
150 'file' => 'digitalobjects.collections.inc', | |
151 'type' => MENU_LOCAL_TASK, | |
152 | |
153 ); | |
154 return $items; | |
155 | |
156 } | |
157 | |
158 | |
159 function digitalobjects_create_primary_node($objid){ | |
160 $node = new stdClass(); | |
161 $node->type = 'digitalobject'; | |
162 node_object_prepare($node); | |
163 global $user; | |
164 #dpm($user); | |
165 #$node->uid=$user->uid; | |
166 $node->field_single_objid['und'][0]['objid']=$objid; | |
167 | |
168 $node->title = $objid; | |
169 | |
170 $node->language = LANGUAGE_NONE; | |
171 #$node = node_submit($node); | |
172 | |
173 #$node->field_object_type['und'][0]=array('tid'=> '6'); | |
174 | |
175 $foo = taxonomy_get_term_by_name('primary'); | |
176 foreach($foo as $term) { | |
177 | |
178 if(($term->vocabulary_machine_name) == 'digitalobject_types') { | |
179 | |
180 $node->field_object_type['und'][]['tid'] = $term->tid; | |
181 } | |
182 } | |
183 $node = node_submit($node); | |
184 | |
185 node_save($node); | |
186 | |
187 return $node; | |
188 } | |
189 | |
190 function digitalobjects_edit($objid){ | |
191 #suche ob es schon ein locales object zu dieser id gibt. | |
192 $query = new EntityFieldQuery(); | |
193 $entities = $query->entityCondition('entity_type', 'node') | |
194 ->entityCondition('bundle', 'digitalobject') | |
195 ->fieldCondition('field_single_objid', 'objid', $objid,"=") | |
196 ->execute(); | |
197 | |
198 if ($entities == null) #existiert noch nicht, dann anlegen | |
199 { | |
200 $node =digitalobjects_create_primary_node($objid); | |
201 #$node->field_object_type['und'][0]=array('tid'=> 'autocreate', | |
202 #'name' => "primary", | |
203 #'vocabulary_machine_name' => 'digitialobject_types'); | |
204 | |
205 } else { | |
206 | |
207 | |
208 $nodes = node_load_multiple(array_keys($entities['node'])); | |
209 | |
210 #gibt es eins, dann gib dieses zum editieren zurück | |
211 #TODO falls mehrere existieren, was dann?? | |
212 | |
213 #gehe durch alle gefundene | |
214 foreach ($nodes as $node){ | |
215 #$typeTag = $entity->object_type['und'] | |
216 | |
217 if (isset($node->field_object_type['und'])){ | |
218 $tid = $node->field_object_type['und'][0]['tid']; | |
219 $tax =taxonomy_term_load($tid); | |
220 if ($tax->name == "primary"){ #'primary gefunden' | |
221 module_load_include('inc', 'node', 'node.pages'); | |
222 return drupal_get_form('digitalobject_node_form', $node); | |
223 }} | |
224 } # keine primary dann lege diese an: | |
225 | |
226 $node =digitalobjects_create_primary_node($objid); | |
227 | |
228 #$vals = array_values($nodes); | |
229 #$node= array_shift($vals); | |
230 } | |
231 | |
232 $node = node_submit($node); | |
233 | |
234 #node_save($node); | |
235 module_load_include('inc', 'node', 'node.pages'); | |
236 | |
237 return drupal_get_form('digitalobject_node_form', $node); | |
238 | |
239 } | |
240 | |
241 | |
242 function digitalobjects_show_usage($objid){ | |
243 $query = new EntityFieldQuery(); | |
244 $entities = $query->entityCondition('entity_type', 'node') | |
245 ->fieldCondition('field_objid', 'objid', $objid,"=") | |
246 ->execute(); | |
247 | |
248 | |
249 $data = array(); | |
250 | |
251 #treffer gefunden | |
252 if (isset($entities['node'])){ | |
253 | |
254 $nodes = node_load_multiple(array_keys($entities['node'])); | |
255 | |
256 | |
257 foreach ($nodes as $node){ | |
258 $data[$node->nid] = $node->title; | |
259 | |
260 } | |
261 | |
262 | |
263 $output['digitalobjects_item_usage']= array( | |
264 '#theme' => 'digitalobjects_item_usage', | |
265 '#data' => $data); | |
266 | |
267 return $output; | |
268 } | |
269 | |
270 return "<h2> object not used in a collection </h2>"; | |
271 } | |
272 | |
273 | |
274 function digitalobjects_page($keys = ''){ | |
275 | |
276 | |
277 #suche ob es schon ein locales object zu dieser id gibt. | |
278 $query = new EntityFieldQuery(); | |
279 $entities = $query->entityCondition('entity_type', 'node') | |
280 ->entityCondition('bundle', 'digitalobject') | |
281 ->fieldCondition('field_single_objid', 'objid', $keys,"=") | |
282 ->execute(); | |
283 | |
284 if ($entities == null) #existiert noch nicht, dann generische Anzeige | |
285 { | |
286 | |
287 $output['digitalobjects_item']= array( | |
288 '#theme' => 'digitalobjects_item', | |
289 '#objid' => $keys); | |
290 | |
291 return $output; | |
292 } else { | |
293 $nodes = node_load_multiple(array_keys($entities['node'])); | |
294 | |
295 #gibt es eins, dann gib dieses zum editieren zurück | |
296 #TODO falls mehrere existieren, was dann?? | |
297 | |
298 #gehe durch alle gefundene | |
299 foreach ($nodes as $node){ | |
300 if (isset($node->field_object_type['und'])){ | |
301 $tid = $node->field_object_type['und'][0]['tid']; | |
302 $tax =taxonomy_term_load($tid); | |
303 | |
304 if ($tax->name == "primary"){ #'primary gefunden' | |
305 return node_view($node, $view_mode = 'full'); | |
306 } | |
307 } | |
308 } | |
309 #keine primary node gefunden, generische ausgabe | |
310 $output['digitalobjects_item']= array( | |
311 '#theme' => 'digitalobjects_item', | |
312 '#objid' => $keys); | |
313 return $output; | |
314 } | |
315 } | |
316 | |
317 /* implements digitalobject_theme */ | |
318 | |
319 function digitalobjects_theme(){ | |
320 | |
321 return array( | |
322 'digitalobjects_item' => array( | |
323 'variables' => array('objid' => NULL), | |
324 'file' => 'digitalobjects.item.inc', | |
325 'template' => 'digitalobjects-item', | |
326 ), | |
327 'digitalobjects_item_short' => array( | |
328 'variables' => array('objid' => NULL), | |
329 'file' => 'digitalobjects.item.inc', | |
330 'template' => 'digitalobjects-item-short', | |
331 ), | |
332 | |
333 'digitalobjects_item_thumbnail' => array( | |
334 'variables' => array('objid' => NULL), | |
335 'file' => 'digitalobjects.item.inc', | |
336 'template' => 'digitalobjects-item-thumbnail', | |
337 ), | |
338 | |
339 'digitalobjects_item_thumbnail_large' => array( | |
340 'variables' => array('objid' => NULL), | |
341 'file' => 'digitalobjects.item.inc', | |
342 'template' => 'digitalobjects-item-thumbnail', | |
343 ), | |
344 | |
345 'digitalobjects_item_objid' => array( | |
346 'variables' => array('objid' => NULL), | |
347 'template' => 'digitalobjects-item-objid', | |
348 ), | |
349 'digitalobjects_item_tools' => array( | |
350 'variables' => array('objid' => NULL), | |
351 'template' => 'digitalobjects-item-tools', | |
352 ), | |
353 'digitalobjects_item_usage' => array( | |
354 'variables' => array('data' => NULL), | |
355 'template' => 'digitalobjects-item-usage', | |
356 ), | |
357 'digitalobjects_collection_simple' => array( | |
358 'variables' => array('objid' => NULL), | |
359 'template' => 'digitalobjects-collection-simple', | |
360 ), | |
361 'digitalobjects_currentCollection_block' => array( | |
362 'variables' => array('node' => NULL), | |
363 'template' => 'digitalobjects-current-collection', | |
364 ), | |
365 'digitalobjects_collection_nodeLink' => array( | |
366 'variables' => array("entities" => $NULL), | |
367 'template' => 'digitalobjects-collection-nodeLink', | |
368 ), | |
369 | |
370 | |
371 | |
372 'digitalobjects_item_xml' => array( | |
373 'variables' => array('objid' => NULL), | |
374 'file' => 'digitalobjects.item.inc', | |
375 'template' => 'digitalobjects-item-xml', | |
376 ), | |
377 | |
378 'digitalobjects_collection_usedIn' => array( | |
379 | |
380 'template' => 'digitalobjects-collection-usedIn', | |
381 ), | |
382 | |
383 'digitalobjects_items' => array( | |
384 'variables' => array('search_results' => NULL), | |
385 'template' => 'digitalobjects-items', | |
386 ), | |
387 | |
388 'digitalobjects_image_src_link_viewer' => array( | |
389 'variables' => array('src' => NULL,'link' => NULL), | |
390 'template' => 'digitalobjects-image_src_link_viewer', | |
391 ), | |
392 | |
393 'digitalobjects_image_src_link_viewer_large' => array( | |
394 'variables' => array('src' => NULL,'link' => NULL), | |
395 'template' => 'digitalobjects-image_src_link_viewer_large', | |
396 ), | |
397 | |
398 'digitalobjects_pdf_link_viewer' => array( | |
399 'variables' => array('title' => NULL,'link' => NULL), | |
400 'template' => 'digitalobjects-pdf_link_viewer', | |
401 ), | |
402 | |
403 /* 'digitalobjects_user_admin_page' => array( | |
404 'variables' => array('digitalobjects_user_admin','uid' =>1), | |
405 'template' => 'digitalobjects-user-admin-form' | |
406 ),*/ | |
407 ); | |
408 } | |
409 | |
410 function digitalobjects_forms($form_id, $args) { | |
411 | |
412 $forms['digitalobjects_user_admin_form']= array( | |
413 'callback' => 'digitalobjects_user_admin', | |
414 'callback arguments' => array('digitalobjects_user_admin_page'), | |
415 ); | |
416 return $forms; | |
417 }; | |
418 | |
419 | |
420 | |
421 | |
422 function digitalobjects_user_admin(array $form, array &$form_state) { | |
423 | |
424 $form['digitalcollection'] = array( | |
425 '#type' => 'textfield', | |
426 '#title' => t('Active collection'), | |
427 '#size' => 15, | |
428 '#default_value' => 'xxxx', | |
429 '#attributes' => array('title' => t('Enter the terms id of the current collection.')), | |
430 ); | |
431 | |
432 | |
433 $form['userid'] = array( | |
434 '#type' => 'hidden', | |
435 ); | |
436 #$form['actions'] = array('#type' => 'actions'); | |
437 $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); | |
438 $form['submit']['#submit'][] = 'digitalobjects_user_admin_form_submit'; | |
439 | |
440 return $form; | |
441 } | |
442 /* implements a new field type for the digitalobject id */ | |
443 | |
444 function digitalobjects_field_info(){ | |
445 | |
446 return array('digitalobjects_digitalobject' => array ( | |
447 'label' => t('Digital Object ID'), | |
448 'description' => t('This field stores a digital object ID'), | |
449 'settings' => array('max_length' =>20), | |
450 'instance_settings' => array('text_processing' => 0), | |
451 'default_widget' => 'digitalobject_default_textfield', | |
452 'default_formatter' => 'digitalobjects_fullmetadata', | |
453 ), | |
454 'digitalobjects_digitalcollection' => array ( | |
455 'label' => t('Digital Collection ID'), | |
456 'description' => t('This field stores a digital collection ID'), | |
457 'settings' => array('max_length' =>20), | |
458 'instance_settings' => array('text_processing' => 0), | |
459 'default_widget' => 'digitalcollection_default_textfield', | |
460 'default_formatter' => 'digitalcollection_fullmetadata', | |
461 ), | |
462 | |
463 | |
464 ); | |
465 | |
466 | |
467 } | |
468 | |
469 | |
470 | |
471 | |
472 function digitalobjects_field_formatter_info() { | |
473 | |
474 return array( | |
475 // This formatter shows the obejct with fullmetadata | |
476 'digitalobjects_fullmetadata' => array( | |
477 'label' => t('Fullmetadata formatter'), | |
478 'field types' => array('digitalobjects_digitalobject'), | |
479 ), | |
480 'digitalobjects_label' => array( | |
481 'label' => t('Label formatter'), | |
482 'field types' => array('digitalobjects_digitalobject'), | |
483 ), | |
484 'digitalobjects_thumbnail' => array( | |
485 'label' => t('Thumbnail formatter (100px'), | |
486 'field types' => array('digitalobjects_digitalobject'), | |
487 ), | |
488 | |
489 'digitalobjects_thumbnail_large' => array( | |
490 'label' => t('Thumbnail formatter (l200px)'), | |
491 'field types' => array('digitalobjects_digitalobject'), | |
492 ), | |
493 'digitalobjects_objid' => array( | |
494 'label' => t('Objid as String formatter'), | |
495 'field types' => array('digitalobjects_digitalobject'), | |
496 ), | |
497 | |
498 'digitalobjects_xml' => array( | |
499 'label' => t('Objids as XML formatter'), | |
500 'field types' => array('digitalobjects_digitalobject'), | |
501 ), | |
502 | |
503 'digitalobjects_collection_simple' => array( | |
504 'label' => t('Simple formatter'), | |
505 'field types' => array('digitalobjects_digitalcollection'), | |
506 ), | |
507 'digitalobjects_image_src_link_viewer' => array( | |
508 'label' => t('View Image and Link from URL'), | |
509 'field types' => array('link_field'), | |
510 ), | |
511 | |
512 'digitalobjects_image_src_link_viewer_large' => array( | |
513 'label' => t('View Image and Link from URL (200px)'), | |
514 'field types' => array('link_field'), | |
515 ), | |
516 'digitalobjects_image_viewer' => array( | |
517 'label' => t('View filename as image with link to digilib'), | |
518 'field types' => array('text'), | |
519 ), | |
520 'digitalobjects_image_viewer_large' => array( | |
521 'label' => t('View filename as image (200px) with link to digilib'), | |
522 'field types' => array('text'), | |
523 ), | |
524 'digitalobjects_pdf_link_viewer' => array( | |
525 'label' => t('View PDF in external viewer'), | |
526 'field types' => array('link_field'), | |
527 ), | |
528 | |
529 ); | |
530 } | |
531 | |
532 | |
533 | |
534 | |
535 | |
536 | |
537 function digitalobjects_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { | |
538 $element = array(); | |
539 | |
540 | |
541 switch ($display['type']) { | |
542 | |
543 case 'digitalobjects_image_viewer': | |
544 foreach ($items as $delta => $item) { | |
545 | |
546 $value = $item['value']; | |
547 | |
548 $linkbase= variable_get('digitalobjects_imagebase_digilib_path'); | |
549 | |
550 $value = str_replace(' ', '_', $value); | |
551 | |
552 $link = $linkbase . $value; | |
553 | |
554 $srcbase=variable_get('digitalobjects_imagebase_scaler_path'); | |
555 | |
556 $src= $srcbase . $value; | |
557 | |
558 | |
559 $element[$delta]['#markup'] = theme('digitalobjects_image_src_link_viewer', array("src" => $src,"link" => $link)); | |
560 | |
561 | |
562 } | |
563 break; | |
564 | |
565 case 'digitalobjects_image_viewer_large': | |
566 foreach ($items as $delta => $item) { | |
567 | |
568 $value = $item['value']; | |
569 | |
570 $linkbase= variable_get('digitalobjects_imagebase_digilib_path'); | |
571 | |
572 $value = str_replace(' ', '_', $value); | |
573 | |
574 $link = $linkbase . $value; | |
575 | |
576 $srcbase=variable_get('digitalobjects_imagebase_scaler_path_large'); | |
577 | |
578 $src= $srcbase . $value; | |
579 | |
580 | |
581 $element[$delta]['#markup'] = theme('digitalobjects_image_src_link_viewer_large', array("src" => $src,"link" => $link)); | |
582 | |
583 | |
584 } | |
585 break; | |
586 | |
587 | |
588 | |
589 | |
590 case 'digitalobjects_fullmetadata': | |
591 foreach ($items as $delta => $item) { | |
592 if ($item['objid']!=""){ | |
593 $element[$delta]['#markup'] = theme('digitalobjects_item_tools', array("objid" => $item['objid'])); | |
594 $element[$delta]['#markup'] .= theme('digitalobjects_item', array("objid" => $item['objid'])); | |
595 | |
596 } | |
597 } | |
598 | |
599 break; | |
600 | |
601 case 'digitalobjects_label': | |
602 foreach ($items as $delta => $item) { | |
603 if ($item['objid']!=""){ | |
604 | |
605 $element[$delta]['#markup'] = theme('digitalobjects_item_short', array("objid" => $item['objid'])); | |
606 $element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid'])); | |
607 } | |
608 } | |
609 break; | |
610 | |
611 case 'digitalobjects_thumbnail': | |
612 foreach ($items as $delta => $item) { | |
613 if ($item['objid']!=""){ | |
614 | |
615 $element[$delta]['#markup'] = theme('digitalobjects_item_thumbnail', array("objid" => $item['objid'])); | |
616 #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid'])); | |
617 } | |
618 } | |
619 break; | |
620 | |
621 case 'digitalobjects_thumbnail_large': | |
622 foreach ($items as $delta => $item) { | |
623 if ($item['objid']!=""){ | |
624 | |
625 $element[$delta]['#markup'] = theme('digitalobjects_item_thumbnail_large', array("objid" => $item['objid'])); | |
626 #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid'])); | |
627 } | |
628 } | |
629 break; | |
630 | |
631 | |
632 case 'digitalobjects_objid': | |
633 foreach ($items as $delta => $item) { | |
634 if ($item['objid']!=""){ | |
635 | |
636 $element[$delta]['#markup'] = theme('digitalobjects_item_objid', array("objid" => $item['objid'])); | |
637 #$element[$delta]['#markup'] .= theme('digitalobjects_item_tools', array("objid" => $item['objid'])); | |
638 } | |
639 } | |
640 break; | |
641 | |
642 case 'digitalobjects_xml': | |
643 foreach ($items as $delta => $item) { | |
644 if ($item['objid']!=""){ | |
645 $element[$delta]['#markup'] = theme('digitalobjects_item_xml', array("objid" => $item['objid'])); | |
646 } | |
647 } | |
648 break; | |
649 | |
650 case 'digitalobjects_collection_xml': | |
651 foreach ($items as $delta => $item) { | |
652 if ($item['objid']!=""){ | |
653 | |
654 $path=$item['objid']; | |
655 //path is node, d.h. beginnt mit node/ | |
656 | |
657 if (!strncmp($path, "node/", strlen("node/"))){ | |
658 $nid = str_replace("node/","",$path); | |
659 $entities = entity_load("node",array($nid)); | |
660 | |
661 $element[$delta]['#markup'] = theme('digitalobjects_collection_nodeLink_xml', array("entities" => $entities)); | |
662 | |
663 } else { | |
664 | |
665 | |
666 $element[$delta]['#markup'] = theme('digitalobjects_collection_simple_xml', array("objid" => $item['objid'])); | |
667 | |
668 } | |
669 } | |
670 } | |
671 break; | |
672 | |
673 | |
674 case 'digitalobjects_image_src_link_viewer': | |
675 case 'digitalobjects_image_src_link_viewer_large': | |
676 #nimmt den link aus dem link feld und macht unter der Annahme er geht auf diglib ein Bild daraus | |
677 foreach ($items as $delta => $item) { | |
678 | |
679 #title feld ist leer, dann: | |
680 #$scal="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?"; | |
681 | |
682 $scal = variable_get('digitalobjects_scaler_path'); | |
683 | |
684 #$img="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?"; | |
685 | |
686 $img=variable_get('digitalobjects_digilib_path'); | |
687 $src= str_replace($img, $scal, $item['url']); | |
688 | |
689 $src=$src . "&dw=500"; | |
690 | |
691 | |
692 | |
693 $element[$delta]['#markup'] = theme($display['type'], array("src" => $src,"link" => $item['url'])); | |
694 | |
695 | |
696 } | |
697 break; | |
698 | |
699 case 'digitalobjects_pdf_link_viewer': | |
700 #nimmt link aus link field und zeigt dieses mit externem pdf viewer an | |
701 foreach ($items as $delta => $item) { | |
702 #$pdfViewer="http://content.mpiwg-berlin.mpg.de/pdfViewer/pdf.js-master/web/viewer.html?file="; | |
703 $pdfViewer=variable_get('digitalobjects_pdfviewer_path'); | |
704 $pdfpath=variable_get('digitalobjects_repository_path'); | |
705 | |
706 #url contains $base root should be removed | |
707 global $base_root; | |
708 | |
709 $url = str_replace($base_root,"",$item['url']); | |
710 $pdfLink=$pdfViewer . $pdfpath . $url; | |
711 | |
712 $element[$delta]['#markup'] = theme('digitalobjects_pdf_link_viewer', array("title" => $item['title'],"link" => $pdfLink)); | |
713 } | |
714 break; | |
715 | |
716 | |
717 | |
718 | |
719 | |
720 } | |
721 return $element; | |
722 } | |
723 | |
724 function template_preprocess_digitalobjects_items(&$variables) { | |
725 $variables['search_results'] = ''; | |
726 | |
727 $viewMode="shortX"; | |
728 | |
729 foreach ($variables['results'] as $result) { | |
730 | |
731 switch ($viewMode) { | |
732 | |
733 case "short": | |
734 $variables['search_results'] .= theme('digitalobjects_item_tools', array("objid" => $result['objid'])); | |
735 $variables['search_results'] .= theme('digitalobjects_item_short', array('objid' => $result['objid'])); | |
736 | |
737 break; | |
738 | |
739 | |
740 default: | |
741 $variables['search_results'] .= theme('digitalobjects_item_tools', array("objid" => $result['objid'], 'objidcss' => digitalobjects_clean_css_identifier($result['objid']))); | |
742 $variables['search_results'] .= theme('digitalobjects_item', array('objid' => $result['objid'])); | |
743 | |
744 break; | |
745 } | |
746 | |
747 } | |
748 $variables['pager'] = theme('pager', array('tags' => NULL,'quantity'=> 2)); | |
749 | |
750 } | |
751 | |
752 | |
753 | |
754 function digitalobjects_field_widget_info() { | |
755 #TODO:both types should check if field is valid | |
756 return array( | |
757 'digitalobject_default_textfield' => array( | |
758 'label' => t('digitalobject id'), | |
759 'field types' => array('digitalobjects_digitalobject'), | |
760 ), | |
761 'digitalcollection_default_textfield' => array( | |
762 'label' => t('digital collection id'), | |
763 'field types' => array('digitalobjects_digitalcollection'), | |
764 ), | |
765 'digitalobjects_objpager_default' => array( | |
766 'label' => t('No edit widget'), | |
767 'field types' => array('digitalobjects_itemView'), | |
768 'behaviors' => array( | |
769 'multiple values' => FIELD_BEHAVIOR_CUSTOM, | |
770 ) | |
771 ), | |
772 | |
773 ); | |
774 } | |
775 | |
776 function digitalobjects_field_postrender($string){ | |
777 /* String is: | |
778 * <div class="form-item form-type-textfield form-item-field-objid-und-0-objid"> | |
779 <input type="text" id="edit-field-objid-und-0-objid" name="field_objid[und][0][objid]" value="" size="20" maxlength="20" class="form-text" /> | |
780 </div> | |
781 */ | |
782 | |
783 // get value: | |
784 | |
785 preg_match('/value="([^"]*)"/',$string,$matches); | |
786 $value = $matches[1]; | |
787 $bib = digitalobjects_readMetadata($value,"short"); | |
788 $string = $string . "<div>" . $bib['bibdata'] . "</div>"; | |
789 return $string; | |
790 } | |
791 | |
792 function digitalobjects_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { | |
793 | |
794 | |
795 $field_name = $field['field_name']; | |
796 $field_type = $field['type']; | |
797 | |
798 | |
799 $value = isset($items[$delta]['objid']) ? $items[$delta]['objid'] : ''; | |
800 | |
801 $widget = $element; | |
802 $widget['#delta'] = $delta; | |
803 | |
804 switch ($instance['widget']['type']) { | |
805 | |
806 | |
807 | |
808 case 'digitalobject_default_textfield': | |
809 $widget += array( | |
810 '#type' => 'textfield', | |
811 '#default_value' => $value, | |
812 '#size' => 20, | |
813 '#maxlength' => 20, | |
814 '#post_render' => array('digitalobjects_field_postrender'), | |
815 ); | |
816 | |
817 | |
818 | |
819 $element['objid'] = $widget; | |
820 | |
821 break; | |
822 | |
823 case 'digitalcollection_default_textfield': | |
824 $widget += array( | |
825 '#type' => 'textfield', | |
826 '#default_value' => $value, | |
827 '#size' => 20, | |
828 '#maxlength' => 20, | |
829 ); | |
830 | |
831 $element['objid'] = $widget; | |
832 break; | |
833 | |
834 | |
835 } | |
836 | |
837 | |
838 | |
839 | |
840 return $element; | |
841 } | |
842 | |
843 | |
844 function digitalobjects_field_is_empty($item, $field){ | |
845 | |
846 return empty($item['objid']); | |
847 } | |
848 | |
849 | |
850 | |
851 /*admin current collection for a user */ | |
852 | |
853 function digitalobjects_user_admin_form_submit($form,$formstate){ | |
854 $value = $formstate['values']['digitalcollection']; | |
855 $userid = $formstate['values']['userid']; | |
856 | |
857 $user=user_load($userid); | |
858 | |
859 | |
860 $user->field_digitalobjects_cid['und'][0]['objid'] = $value; | |
861 | |
862 user_save($user); | |
863 | |
864 } | |
865 | |
866 | |
867 /* show current collection of the current user as block */ | |
868 function digitalobjects_block_info(){ | |
869 $blocks['digitalobjects_currentCollection'] = array( | |
870 'info' => t('Current Collection'), | |
871 'visibility' => BLOCK_VISIBILITY_PHP, | |
872 'pages' => '<?php global $user; if ($user->uid == 0) return FALSE; else return TRUE; ?>' | |
873 ); | |
874 | |
875 $blocks['digitalobjects_collection_usedIn'] = array( | |
876 'info' => t('Collection used in') | |
877 ); | |
878 | |
879 $blocks['digitalobjects_block_items'] = array( | |
880 'info' => t('Items of a collection (if page is a collection)') | |
881 ); | |
882 | |
883 | |
884 return $blocks; | |
885 } | |
886 | |
887 function digitalobjects_block_view($delta){ | |
888 | |
889 switch($delta){ | |
890 | |
891 case 'digitalobjects_currentCollection': | |
892 /* display current cullection */ | |
893 | |
894 global $user; | |
895 | |
896 $user_full=user_load($user->uid); | |
897 | |
898 if (isset($user_full->field_digitalobjects_cid['und'][0]['objid'])){ | |
899 $val = $user_full->field_digitalobjects_cid['und'][0]['objid']; | |
900 } else { | |
901 return; | |
902 } | |
903 $node = node_load($val); | |
904 | |
905 #$title = $node=>title; | |
906 | |
907 $block['content'] = theme('digitalobjects_currentCollection_block',array('node' => $node)); | |
908 | |
909 $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); | |
910 $form['submit']['#submit'][] = 'digitalobjects_user_admin_collection'; | |
911 | |
912 $submitForm=drupal_get_form('digitalobjects_change_collection_button_form'); | |
913 $block['content'] .= drupal_render($submitForm); | |
914 return $block; | |
915 break; | |
916 | |
917 | |
918 case 'digitalobjects_collection_usedIn': | |
919 if ($node = menu_get_object()) { | |
920 // Get the nid | |
921 $nid = $node->nid; | |
922 $entities = digitalcollection_used_id($nid); | |
923 | |
924 $block['content'] = theme('digitalobjects_collection_usedIn',array('entities'=> $entities)); | |
925 return $block; | |
926 } | |
927 | |
928 case 'digitalobjects_block_items': | |
929 if ($entity = menu_get_object()) { | |
930 | |
931 #$element[$delta]['prefix']['#markup'] = '<ol class="search-results">'; | |
932 | |
933 if(!isset($entity->field_objid[LANGUAGE_NONE])){ | |
934 break; | |
935 } | |
936 | |
937 $resultsAll = $entity->field_objid[LANGUAGE_NONE]; | |
938 | |
939 | |
940 | |
941 $nums_per_page = 10; | |
942 | |
943 $params = drupal_get_query_parameters(); | |
944 if (isset($params['page'])){ | |
945 $page = $params['page']; | |
946 } else { | |
947 $page = 0; | |
948 } | |
949 | |
950 | |
951 $start=$nums_per_page * intval($page); | |
952 | |
953 if ($resultsAll==null){ | |
954 break; | |
955 } | |
956 | |
957 $results = array_slice($resultsAll,$start,$nums_per_page); | |
958 | |
959 | |
960 | |
961 pager_default_initialize(sizeof($resultsAll),$nums_per_page); | |
962 | |
963 | |
964 | |
965 #foreach ($results as $entry) { | |
966 # $element[$delta][]['#markup'] = $entry; | |
967 #} | |
968 | |
969 #$element[$delta]['suffix']['#markup'] = '</ol>' . theme('pager'); | |
970 | |
971 $block['content'] = theme('digitalobjects_items', array('results' => $results)); | |
972 | |
973 // Finally, display the pager controls, and return. | |
974 #$element[$delta]['#markup'] .= theme('pager'); | |
975 | |
976 | |
977 #dpm(theme('pager')); | |
978 return $block; | |
979 break; | |
980 } | |
981 | |
982 | |
983 } | |
984 | |
985 //return $block; | |
986 } | |
987 | |
988 function digitalobjects_change_collection_button_form(){ | |
989 include_once 'digitalobjects.collections.inc'; | |
990 global $user; | |
991 $form['userid'] = array( | |
992 | |
993 '#type' => 'hidden', | |
994 '#value' => $user->uid | |
995 ); | |
996 | |
997 $form['submit'] = array('#type' => 'submit', '#value' => t('change')); | |
998 $form['submit']['#submit'][] = 'digitalobjects_user_admin_collection_submit'; | |
999 | |
1000 return $form; | |
1001 } | |
1002 | |
1003 function digitalobjects_permission() { | |
1004 return array( | |
1005 'manage private collections' => array( | |
1006 'title' => t('Manage private collections'), | |
1007 'description' => t('Allow users create and manage private collections.'), | |
1008 ), | |
1009 'administrate digitalobjects' => array( | |
1010 'title' => t('Administrate digitalobjects'), | |
1011 'description' => t('Can add commentaries to digital objects.'), | |
1012 ), | |
1013 ); | |
1014 } | |
1015 | |
1016 | |
1017 function digitalobjects_pathologic_alter(&$url_params, $parts, $settings){ | |
1018 #bilder ohne jegliche pfad angaben werden auf sites/default/files/.. | |
1019 if (preg_match('~^([^/]*)\.(png|gif|jpe?g)$~', $url_params['path'])){ | |
1020 | |
1021 $url_params['path'] = 'sites/default/files/' . $url_params['path']; | |
1022 } | |
1023 | |
1024 if (preg_match('~^./([^/]*)\.pt$~', $url_params['path'],$matches)){ | |
1025 | |
1026 $url_params['path'] = 'harriot/maps/' . $matches[1] . '.pt'; | |
1027 } | |
1028 | |
1029 } | |
1030 | |
1031 function digitalobjects_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { | |
1032 | |
1033 foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { | |
1034 $info = field_info_field($name); | |
1035 #map the whole attr | |
1036 | |
1037 if ($info['type'] == 'digitalobjects_digitalobject') { | |
1038 $targets[$name] = array( | |
1039 'name' => t('@name', array('@name' => $instance['label'])), | |
1040 'callback' => 'digitalobjects_feeds_set_target', | |
1041 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), | |
1042 'real_target' => $name, | |
1043 ); | |
1044 } | |
1045 } | |
1046 } | |
1047 | |
1048 function digitalobjects_feeds_set_target($source, $entity, $target, $value) { | |
1049 | |
1050 if (empty($value)) { | |
1051 return; | |
1052 } | |
1053 | |
1054 // Handle non-multiple value fields. | |
1055 if (!is_array($value)) { | |
1056 $value = array($value); | |
1057 } | |
1058 | |
1059 // Iterate over all values. | |
1060 #list($field_name, $column) = explode(':', $target); | |
1061 | |
1062 $field_name=$target; | |
1063 $info = field_info_field($field_name); | |
1064 | |
1065 $field = isset($entity->$field_name) ? $entity->$field_name : array(); | |
1066 $delta = 0; | |
1067 | |
1068 foreach ($value as $v) { | |
1069 | |
1070 if ($info['cardinality'] == $delta) { | |
1071 break; | |
1072 } | |
1073 | |
1074 if (is_object($v) && ($v instanceof FeedsElement)) { | |
1075 $v = $v->getValue(); | |
1076 } | |
1077 | |
1078 if (is_scalar($v)) { | |
1079 $field['und'][$delta]['objid'] = $v; | |
1080 $delta++; | |
1081 } | |
1082 | |
1083 if (is_array($v)){ | |
1084 $newVal = array(); | |
1085 | |
1086 $newVal['objid'] = $v; | |
1087 $field['und'][$delta]= $newVal; | |
1088 $delta++; | |
1089 } | |
1090 } | |
1091 $entity->$field_name = $field; | |
1092 } | |
1093 | |
1094 //Provide a function to generate a valid identifier from the objectid | |
1095 //taken from views module | |
1096 | |
1097 function digitalobjects_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) { | |
1098 // By default, we filter using Drupal's coding standards. | |
1099 $identifier = strtr($identifier, $filter); | |
1100 | |
1101 // Valid characters in a CSS identifier are: | |
1102 // - the hyphen (U+002D) | |
1103 // - a-z (U+0030 - U+0039) | |
1104 // - A-Z (U+0041 - U+005A) | |
1105 // - the underscore (U+005F) | |
1106 // - 0-9 (U+0061 - U+007A) | |
1107 // - ISO 10646 characters U+00A1 and higher | |
1108 // We strip out any character not in the above list. | |
1109 $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); | |
1110 | |
1111 return $identifier; | |
1112 } |