diff --git a/includes/datastream.inc b/includes/datastream.inc index 2f271e60..6fa95ddc 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -12,6 +12,9 @@ * @return stream * prints datastream to browser */ + +define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); + function islandora_datastream_as_attachment($object_id, $dsid) { module_load_include('inc', 'islandora', 'RestConnection'); global $user; @@ -33,3 +36,158 @@ function islandora_datastream_as_attachment($object_id, $dsid) { exit(); } + +/** + * + * @param array $arr + * an array of dsids that are defined by this objects cmodels + * @param string $ds_comp_stream + * the dscomposite stream as xml + */ +function islandora_update_available_dsids_array(&$arr, $ds_comp_stream){ + $sxml = new SimpleXMLElement($ds_comp_stream); + foreach($sxml->dsTypeModel as $ds){ + //$arr[$ds['ID']] + $mimes = array(); + foreach($ds->form as $form){ + $mimetype = (string)$form['MIME']; + $mimes[] = $mimetype; + } + $dsid = (string)$ds['ID']; + if($dsid != 'AUDIT'){ + $arr[(string)$ds['ID']] = $mimes; + } + } +} + +/** + * this function may not be being used + * @param type $pid + * @param type $form_state + * @return string + */ +function islandora_add_datastream_form($object_id, &$form_state) { + //dump_vars($form_state); + // Populate the list of datastream IDs. + module_load_include('inc', 'islandora', 'RestConnection'); + global $user; + try { + $restConnection = new RestConnection($user); + $fedora_object = new FedoraObject($object_id, $restConnection->repository); + } catch (Exception $e) { + drupal_set_message(t('Error getting Islandora object %s ', array('%s' => $object_id)), 'error'); + return ""; + } + if (!isset($fedora_object)) { + drupal_set_message(t('Could not create add datastream form for %s'), array('%s' => $object_id)); + return; + } + $models = $fedora_object->models; + $available_dsids = array(); + if (isset($models)) { + foreach ($models as $model) { + try { + $model_object = new FedoraObject($model, $restConnection->repository); + $dscomposite_stream = $model_object[DS_COMP_STREAM]->content; + islandora_update_available_dsids_array($available_dsids, $dscomposite_stream); + } catch (Exception $e) { + //do nothing as other objects may have a dscompsite stream + } + //$model_ds_comp = + } + } + + /*if (!empty($content_models)) { + foreach ($content_models as $content_model) { + + + $newElements = $content_model->listDatastreams(); + if (!empty($newElements)) { + $available_dsids = array_merge($available_dsids, $newElements); + } + } + } + + $item = new Fedora_Item($pid); + $used_datastreams = $item->get_datastreams_list_as_SimpleXML(); + $used_datastream_ids = array(); + foreach ($used_datastreams->datastreamDef as $used_datastream) { + array_push($used_datastream_ids, $used_datastream->ID); + } + $unused_dsids = array(); + + if ($form_state['submitted'] && $form_state['clicked_button']['#value'] != 'OK') { + $form['add_datastream_label'] = array( + '#value' => t('

The datastream has been uploaded.

'), + '#weight' => -10, + ); + $form['#redirect'] = "fedora/repository/$pid/"; + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('OK') + ); + return $form; + } + if (!empty($available_dsids)) { + $unused_dsids = array_diff($available_dsids, $used_datastream_ids); + if (empty($unused_dsids)) { + return; + } + } + + $form['add_datastream_label'] = array( + '#value' => t('

Add Datastream:

'), + '#weight' => -10, + ); + + $form['pid'] = array( + '#type' => 'hidden', + '#value' => "$pid" + ); + + $form['stream_label'] = array( + '#title' => 'Datastream Label', + '#required' => 'TRUE', + '#description' => t('A Human readable label'), + '#type' => 'textfield' + ); + + $form['#attributes']['enctype'] = 'multipart/form-data'; + $form['add-stream-file-location'] = array( + '#type' => 'file', + '#title' => t('Upload Document'), + '#size' => 48, + // '#required'=>'TRUE', + '#description' => t('The file to upload.') + ); + $form['#redirect'] = "fedora/repository/$pid/"; + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Add Datastream') + ); + + if (!empty($unused_dsids)) { + $dsidsForForm = array(); + foreach ($unused_dsids as $dsid) { + $dsidsForForm[$dsid] = $dsid; + } + $form['stream_id'] = array( + '#type' => 'select', + '#title' => t('Datastream ID'), + '#default_value' => variable_get('feed_item_length', 'teaser'), + '#weight' => '-1', + '#description' => t('Datastream IDs defined by the content model.'), + ); + $form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids); + } + else { + $form['stream_id'] = array( + '#title' => 'Datastream ID', + '#required' => 'TRUE', + '#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'), + '#type' => 'textfield', + '#weight' => -1, + ); + } + return $form;*/ +} diff --git a/includes/islandora_dublin_core.inc b/includes/islandora_dublin_core.inc index 9ea4aa35..c59c89f2 100644 --- a/includes/islandora_dublin_core.inc +++ b/includes/islandora_dublin_core.inc @@ -99,6 +99,25 @@ class Dublin_Core { } + function as_formatted_array() { + $dc_array = array(); + foreach ($this as $element) { + if (!empty($element)) { + foreach ($element as $field => $value) { + // split value if the result value is an array + if (is_array($value)) { + $value = implode(", ", $value); + } + $dc_label = explode(':', $field); + $element_label = ucfirst($dc_label[1]); + $dc_array[$field]['label'] = $element_label; + $dc_array[$field]['value'] = strip_tags($value); + $dc_array[$field]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field)); + } + } + } + return $dc_array; + } /** diff --git a/islandora_basic_collection/Crystal_Clear_filesystem_folder_grey.png b/islandora_basic_collection/Crystal_Clear_filesystem_folder_grey.png new file mode 100644 index 00000000..f4c80d83 Binary files /dev/null and b/islandora_basic_collection/Crystal_Clear_filesystem_folder_grey.png differ diff --git a/islandora_basic_collection/islandora_basic_collection.install b/islandora_basic_collection/islandora_basic_collection.install new file mode 100644 index 00000000..6b90190d --- /dev/null +++ b/islandora_basic_collection/islandora_basic_collection.install @@ -0,0 +1,95 @@ + $e)), 'error'); + return; + } + + $content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel'); + if (empty($content_model_query['results'])) { + try { + $xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_collection_CModel.xml'); + $restConnection->api->m->ingest(array('string' => $xml)); + } catch (Exception $e) { + drupal_set_message(t('Unable to install content models %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Content models installed!')); + } + else { + drupal_set_message(t('Content models already exist!'), 'warning'); + } + + $collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root'); + if (empty($collection_query['results'])) { + try { + $xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_root_collection.xml'); + $restConnection->api->m->ingest(array('string' => $xml)); + $fedora_object = new FedoraObject('islandora:root', $restConnection->repository); + $datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $restConnection->repository); + $file_path = $base_root . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png'; + $datastream->label = 'Thumbnail'; + $datastream->mimetype = 'image/png'; + $datastream->setContentFromUrl($file_path); + $fedora_object->ingestDatastream($datastream); + + } catch (Exception $e) { + drupal_set_message(t('Unable to install collections %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Collections installed!')); + } + else { + drupal_set_message(t('Collections already exist!'), 'warning'); + } +} + +function islandora_basic_collection_uninstall() { + module_load_include('inc', 'islandora', 'RestConnection'); + global $user; + try { + $restConnection = new RestConnection($user); + } catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + return; + } + + $content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel'); + if (!empty($content_model_query['results'])) { + try { + $restConnection->repository->purgeObject('islandora:collectionCModel'); + } catch (Exception $e) { + drupal_set_message(t('Unable to purge content models %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Content models purged!')); + } + else { + drupal_set_message(t('Content models don\'t exist!'), 'warning'); + } + + $collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root'); + if (!empty($collection_query['results'])) { + try { + $restConnection->repository->purgeObject('islandora:root'); + } catch (Exception $e) { + drupal_set_message(t('Unable to purge collections %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Collections purged!')); + } + else { + drupal_set_message(t('Collections don\'t exist!'), 'warning'); + } +} \ No newline at end of file diff --git a/islandora_basic_collection/xml/islandora_collection_CModel.xml b/islandora_basic_collection/xml/islandora_collection_CModel.xml new file mode 100644 index 00000000..06966bdf --- /dev/null +++ b/islandora_basic_collection/xml/islandora_collection_CModel.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + Islandora Collection Content Model + islandora:collectionCModel + + + + + + + + + +
+
+ +
+
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/islandora_basic_collection/xml/islandora_root_collection.xml b/islandora_basic_collection/xml/islandora_root_collection.xml new file mode 100644 index 00000000..ac276efd --- /dev/null +++ b/islandora_basic_collection/xml/islandora_root_collection.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + Islandora Top-level Collection + islandora:root + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dc.title + dc.creator + dc.description + dc.date + dc.identifier + dc.language + dc.publisher + dc.rights + dc.subject + dc.relation + dcterms.temporal + dcterms.spatial + Full Text + + isMemberOfCollection + + + + + \ No newline at end of file diff --git a/islandora_basic_image/Crystal_Clear_filesystem_folder_grey.png b/islandora_basic_image/Crystal_Clear_filesystem_folder_grey.png new file mode 100644 index 00000000..f4c80d83 Binary files /dev/null and b/islandora_basic_image/Crystal_Clear_filesystem_folder_grey.png differ diff --git a/islandora_basic_image/islandora_basic_image.install b/islandora_basic_image/islandora_basic_image.install new file mode 100644 index 00000000..f900d247 --- /dev/null +++ b/islandora_basic_image/islandora_basic_image.install @@ -0,0 +1,98 @@ + $e)), 'error'); + return; + } + + $content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:sp_basic_image'); + if (empty($content_model_query['results'])) { + try { + $xml = file_get_contents(drupal_get_path('module', 'islandora_basic_image') . '/xml/simple_islandora_basic_imageCM.xml'); + $restConnection->api->m->ingest(array('string' => $xml)); + } catch (Exception $e) { + drupal_set_message(t('Unable to install content models %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Content models installed!')); + } + else { + drupal_set_message(t('Content models already exist!'), 'warning'); + } + + $collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:sp_basic_image_collection'); + if (empty($collection_query['results'])) { + try { + $xml = file_get_contents(drupal_get_path('module', 'islandora_basic_image') . '/xml/islandora_basic_image_collection.xml'); + $restConnection->api->m->ingest(array('string' => $xml)); + $fedora_object = new FedoraObject('islandora:sp_basic_image_collection', $restConnection->repository); + $datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $restConnection->repository); + $file_path = $base_root . '/' . drupal_get_path('module', 'islandora_basic_image') . '/Crystal_Clear_filesystem_folder_grey.png'; + $datastream->label = 'Thumbnail'; + $datastream->mimetype = 'image/png'; + $datastream->setContentFromUrl($file_path); + $fedora_object->ingestDatastream($datastream); + + } catch (Exception $e) { + drupal_set_message(t('Unable to install collections %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Collections installed!')); + } + else { + drupal_set_message(t('Collections already exist!'), 'warning'); + } +} + +function islandora_basic_image_uninstall() { + module_load_include('inc', 'islandora', 'RestConnection'); + global $user; + try { + $restConnection = new RestConnection($user); + } catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + return; + } + + $content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:sp_basic_image'); + if (!empty($content_model_query['results'])) { + try { + $restConnection->repository->purgeObject('islandora:sp_basic_image'); + } catch (Exception $e) { + drupal_set_message(t('Unable to purge content models %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Content models purged!')); + } + else { + drupal_set_message(t('Content models don\'t exist!'), 'warning'); + } + + $collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:sp_basic_image_collection'); + if (!empty($collection_query['results'])) { + try { + $restConnection->repository->purgeObject('islandora:sp_basic_image_collection'); + } catch (Exception $e) { + drupal_set_message(t('Unable to purge collections %e', array('%e' => $e)), 'error'); + return; + } + drupal_set_message(t('Collections purged!')); + } + else { + drupal_set_message(t('Collections don\'t exist!'), 'warning'); + } +} \ No newline at end of file diff --git a/islandora_basic_image/islandora_basic_image.module b/islandora_basic_image/islandora_basic_image.module index 372d80dd..ff952c64 100644 --- a/islandora_basic_image/islandora_basic_image.module +++ b/islandora_basic_image/islandora_basic_image.module @@ -102,23 +102,24 @@ function islandora_basic_image_preprocess_islandora_basic_image(&$variables) { //create a nicer array for themers //TODO: give this a better home - $dc_array = array(); - foreach ($dc_object as $element) { - if (!empty($element)) { - foreach ($element as $field => $value) { - // split value if the result value is an array - if (is_array($value)) { - $value = implode(", ", $value); - } - $dc_label = explode(':', $field); - $element_label = ucfirst($dc_label[1]); - $dc_array[$field]['label'] = $element_label; - $dc_array[$field]['value'] = strip_tags($value); - $dc_array[$field]['class'] = strtolower( preg_replace('/[^A-Za-z0-9]/', '-', $field)); - } - } - } - $variables['dc_array'] = $dc_array; + //$dc_array = array(); + //foreach ($dc_object as $element) { + // if (!empty($element)) { + // foreach ($element as $field => $value) { + // // split value if the result value is an array + // if (is_array($value)) { + // $value = implode(", ", $value); + // } + // $dc_label = explode(':', $field); + // $element_label = ucfirst($dc_label[1]); + // $dc_array[$field]['label'] = $element_label; + // $dc_array[$field]['value'] = strip_tags($value); + // $dc_array[$field]['class'] = strtolower( preg_replace('/[^A-Za-z0-9]/', '-', $field)); + // } + // } + //} + + $variables['dc_array'] = $dc_object->as_formatted_array(); $variables['islandora_object_label'] = $islandora_object->label; $variables['theme_hook_suggestions'][] = 'islandora_basic_image__' . str_replace(':', '_', $islandora_object->id); global $base_url; diff --git a/islandora_basic_image/xml/islandora_basic_imageCM.xml b/islandora_basic_image/xml/islandora_basic_imageCM.xml new file mode 100644 index 00000000..cb3fae77 --- /dev/null +++ b/islandora_basic_image/xml/islandora_basic_imageCM.xml @@ -0,0 +1,818 @@ + + + + + + + + + + + + + + + +
+ + + +
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ + + + + + + + + + + + + + + + Islandora basic image content model + islandora:sp_basic_image + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML Schema 2002-03-18 by Pete Johnston. + Adjusted for usage in the OAI-PMH. + Schema imports the Dublin Core elements from the DCMI schema for unqualified Dublin Core. + 2002-12-19 updated to use simpledc20021212.xsd (instead of simpledc20020312.xsd) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Simple DC XML Schema, 2002-10-09 + by Pete Johnston (p.johnston@ukoln.ac.uk), + Carl Lagoze (lagoze@cs.cornell.edu), Andy Powell (a.powell@ukoln.ac.uk), + Herbert Van de Sompel (hvdsomp@yahoo.com). + This schema defines terms for Simple Dublin Core, i.e. the 15 + elements from the http://purl.org/dc/elements/1.1/ namespace, with + no use of encoding schemes or element refinements. + Default content type for all elements is xs:string with xml:lang + attribute available. + + Supercedes version of 2002-03-12. + Amended to remove namespace declaration for http://www.w3.org/XML/1998/namespace namespace, + and to reference lang attribute via built-in xml: namespace prefix. + xs:appinfo also removed. + + + + + + + + + + + + This is the default type for all of the DC elements. + It permits text content only with optional + xml:lang attribute. + Text is allowed because mixed="true", but sub-elements + are disallowed because minOccurs="0" and maxOccurs="0" + are on the xs:any tag. + + This complexType allows for restriction or extension permitting + child elements. + + + + + + + + + + + + + + + + + + + + + + + + + + + invisible + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + See http://www.w3.org/XML/1998/namespace.html and + http://www.w3.org/TR/REC-xml for information about this namespace. + + This schema document describes the XML namespace, in a form + suitable for import by other schema documents. + + Note that local names in this namespace are intended to be defined + only by the World Wide Web Consortium or its subgroups. The + following names are currently defined in this namespace and should + not be used with conflicting semantics by any Working Group, + specification, or document instance: + + base (as an attribute name): denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification. + + lang (as an attribute name): denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification. + + space (as an attribute name): denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification. + + Father (in any context at all): denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: + + In appreciation for his vision, leadership and dedication + the W3C XML Plenary on this 10th day of February, 2000 + reserves for Jon Bosak in perpetuity the XML name + xml:Father + + + + + + In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + http://www.w3.org/2001/03/xml.xsd. + At the date of issue it can also be found at + http://www.w3.org/2001/xml.xsd. + The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML Schema + itself. In other words, if the XML Schema namespace changes, the version + of this document at + http://www.w3.org/2001/xml.xsd will change + accordingly; the version at + http://www.w3.org/2001/03/xml.xsd will not change. + + + + + + In due course, we should install the relevant ISO 2- and 3-letter + codes as the enumerated possible values . . . + + + + + + + + + + + + + + + + + See http://www.w3.org/TR/xmlbase/ for + information about this attribute. + + + + + + + + + + + + + + + + + + + + + + + + + Islandora Content Model Schema + Islandora, Robertson Library, University of Prince Edward Island, 550 University Ave., Charlottetown, Prince Edward Island + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/islandora_basic_image/xml/islandora_basic_image_collection.xml b/islandora_basic_image/xml/islandora_basic_image_collection.xml new file mode 100644 index 00000000..adb21ca8 --- /dev/null +++ b/islandora_basic_image/xml/islandora_basic_image_collection.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + Islandora Basic Image Collection + islandora:sp_basic_image_collection + + + + + + + + + + + + + + + + + + + + + + + + + isMemberOfCollection + + + + + \ No newline at end of file diff --git a/islandora_basic_image/xml/islandora_basic_image_collection_policy.xml b/islandora_basic_image/xml/islandora_basic_image_collection_policy.xml new file mode 100644 index 00000000..c259bab3 --- /dev/null +++ b/islandora_basic_image/xml/islandora_basic_image_collection_policy.xml @@ -0,0 +1,11 @@ + + + + + + + isMemberOfCollection + \ No newline at end of file diff --git a/islandora_basic_image/xml/simple_islandora_basic_imageCM.xml b/islandora_basic_image/xml/simple_islandora_basic_imageCM.xml new file mode 100644 index 00000000..356f6d52 --- /dev/null +++ b/islandora_basic_image/xml/simple_islandora_basic_imageCM.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + + + + + + + Islandora basic image content model + islandora:sp_basic_image + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file