diff --git a/CollectionPolicy.inc b/CollectionPolicy.inc index be92f8b7..15a0392c 100644 --- a/CollectionPolicy.inc +++ b/CollectionPolicy.inc @@ -392,13 +392,13 @@ class CollectionPolicy extends XMLDatastream { $ret=array(); $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); for ($i=0;$i<$content_models->length;$i++) { - $cm=ContentModel::loadFromModel($content_models->item($i)->getAttribute('pid'), + $cm=ContentModel::loadFromModel($content_models->item($i)->getAttribute('pid'), $content_models->item($i)->getAttribute('dsid'), $content_models->item($i)->getAttribute('namespace'), $content_models->item($i)->getAttribute('name')); - if ($cm !== FALSE) { - $ret[]=$cm; - } + if ($cm !== FALSE) { + $ret[]=$cm; + } } } diff --git a/api/fedora_collection.inc b/api/fedora_collection.inc index c0dce02a..3db41018 100644 --- a/api/fedora_collection.inc +++ b/api/fedora_collection.inc @@ -65,7 +65,7 @@ function export_collection($collection_pid, $relationship = 'isMemberOfCollectio * @param $query * @param $query_format R */ -function get_related_items_as_xml($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL) { +function get_related_items_as_xml($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $collection_item = new Fedora_Item($collection_pid); @@ -104,7 +104,7 @@ function get_related_items_as_xml($collection_pid, $relationship = array('isMemb $query_string .= ') minus $content - order by $title'; + order by '.$orderby; $query_string = htmlentities(urlencode($query_string)); @@ -117,8 +117,8 @@ function get_related_items_as_xml($collection_pid, $relationship = array('isMemb return $content; } -function get_related_items_as_array($collection_pid, $relationship = 'isMemberOfCollection', $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL) { - $content = get_related_items_as_xml($collection_pid, $relationship, $limit, $offset, $active_objects_only, $cmodel); +function get_related_items_as_array($collection_pid, $relationship = 'isMemberOfCollection', $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { + $content = get_related_items_as_xml($collection_pid, $relationship, $limit, $offset, $active_objects_only, $cmodel, $orderby); if (empty($content)) { return array(); } diff --git a/fedora_repository.module b/fedora_repository.module index 8d96500d..59b3d936 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1758,3 +1758,70 @@ function fedora_repository_display_schema($file) { } return; } + +/** + * Implementation of hook_requirements(). + * + * @return + * An array describing the status of the site regarding available updates. + * If there is no update data, only one record will be returned, indicating + * that the status of core can't be determined. If data is available, there + * will be two records: one for core, and another for all of contrib + * (assuming there are any contributed modules or themes enabled on the + * site). In addition to the fields expected by hook_requirements ('value', + * 'severity', and optionally 'description'), this array will contain a + * 'reason' attribute, which is an integer constant to indicate why the + * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or + * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail + * notification messages during update_cron(), and might be useful for other + * modules that invoke update_requirements() to find out if the site is up + * to date or not. + * + * @see _update_message_text() + * @see _update_cron_notify() + */ +function fedora_repository_requirements($phase) { + global $base_url; + if ($phase == 'runtime') { + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $requirements = array(); + $requirements['fedora-repository']['title'] = t("Fedora server"); + if (!fedora_available()) { + $requirements['fedora-repository']['value'] = t("Not available"); + $requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR; + $requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the collection settings are correct.', + array('@collection-settings' => $base_url.'/admin/settings/fedora_repository')); + } + else { + $requirements['fedora-repository']['value'] = t("Available"); + $requirements['fedora-repository']['severity'] = REQUIREMENT_OK; + } + + // Check for ImageMagick + $requirements['fedora-imagemagick']['title'] = t("ImageMagick convert in \$PATH"); + system('which convert', $res); + if ($res != 0) { + $requirements['fedora-imagemagick']['value'] = t('Not in $PATH'); + $requirements['fedora-imagemagick']['description'] = t('Islandora will not be able to create thumbnails. Ensure that ImageMagick is installed and the convert command is executable by the web server user.'); + $requirements['fedora-imagemagick']['severity'] = REQUIREMENT_WARNING; + } + else { + $requirements['fedora-imagemagick']['value'] = t("Available"); + $requirements['fedora-imagemagick']['severity'] = REQUIREMENT_OK; + } + + $requirements['fedora-kakadu']['title'] = 'Kakadu kdu_compress in $PATH'; + system('which kdu_compress', $kdu_res); + if ($kdu_res != 0) { + $requirements['fedora-kakadu']['value'] = ('Not in $PATH'); + $requirements['fedora-kakadu']['description'] = t('Islandora cannot convert TIFF image files to JPEG2000 format. Ensure Kakadu is installed and the kdu_compress command is executable by the web server user.'); + $requirements['fedora-kakadu']['severity'] = REQUIREMENT_WARNING; + } + else { + $requirements['fedora-kakadu']['value'] = t("Available"); + $requirements['fedora-kakadu']['severity'] = REQUIREMENT_OK; + } + } + + return $requirements; +} \ No newline at end of file diff --git a/form_elements/includes/autocomplete.inc b/form_elements/includes/autocomplete.inc index d585b995..90ead4cc 100644 --- a/form_elements/includes/autocomplete.inc +++ b/form_elements/includes/autocomplete.inc @@ -3,17 +3,19 @@ // $Id$ function ife_autocomplete_person($string) { - $string=strtolower($string); + $string=trim(strtolower($string)); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('php', 'islandora_solr_search', 'Solr/Service'); $host = variable_get('islandora_solr_search_block_host','localhost'); $port = variable_get('islandora_solr_search_block_port','8080'); $appName = variable_get('islandora_solr_search_block_app_name','solr'); - $requestHandler = variable_get("islandora_solr_search_block_request_handler",t("standard")); - - $query = 'name_personal_t:'.$string.'* OR name_organization_t:'.$string.'* OR name_conference_t:'.$string.'*'; + $requestHandler = variable_get("islandora_solr_search_block_request_handler",t("standard")); + $solr = new Apache_Solr_Service($host, $port, '/'.$appName.'/'); + + $string=$solr->escape($string); + $query = 'name_personal_t:'.$string.'* OR name_organization_t:'.$string.'* OR name_conference_t:'.$string.'*'; $additionalParams = array( 'facet' => 'false', @@ -129,7 +131,7 @@ function ife_autocomplete_gacs($collection, $string='') { $collection = FALSE; } - $string=ucwords($string); + $string=ucwords(trim($string)); $dom = DOMDocument::load ( $moduleRoot .'/xml/gacs.xml' ); $rootEl = $dom->getElementsByTagName('codelist'); @@ -159,7 +161,7 @@ function ife_autocomplete_language($collection, $string='') { $collection = FALSE; } - $string=ucwords($string); + $string=ucwords(trim($string)); $dom = DOMDocument::load ( $moduleRoot .'/xml/languages.xml' ); $rootEl = $dom->getElementsByTagName('codelist'); @@ -197,7 +199,7 @@ function ife_autocomplete($field, $collection, $string='') { 'fl' => $field ); - $query = $field .':'. $solr->escape(strtolower($string)) .'*'; + $query = $field .':'. $solr->escape(strtolower(trim($string))) .'*'; if ($collection != FALSE) { $query .= ' AND related_item_identifier_t:'. $solr->escape($collection); diff --git a/form_elements/includes/people.inc b/form_elements/includes/people.inc index f19bf9b8..43cf52ad 100644 --- a/form_elements/includes/people.inc +++ b/form_elements/includes/people.inc @@ -41,7 +41,6 @@ function _ife_find_people_element($form, &$keys = array()) { function ife_people_ahah() { - if (!isset($_POST['form_build_id'])) return; @@ -58,10 +57,9 @@ function ife_people_ahah() { $_POST = _dummy_post_info($form, $_POST); $form_state['post'] = $_POST; $form['#post'] = $_POST; - drupal_process_form($form_id, $form, $form_state); -// ob_start(); echo '
';   echo $_POST['form_build_id']."\n"; var_dump($form_state);   echo '
'; $dump = ob_get_contents(); ob_end_clean(); + //ob_start(); echo '
'; echo $_POST['form_build_id']."\n"; var_dump($form_state);   echo '
'; $dump = ob_get_contents(); ob_end_clean(); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); $qt_form = _ife_find_people_element($form); @@ -109,7 +107,7 @@ function ife_remove_person_submit($form, &$form_state) { unset($form_state['submit_handlers']); form_execute_handlers('submit', $form, $form_state); $form_state['storage']['people'] = $people; - //$form_state['rebuild'] = TRUE; + $form_state['rebuild'] = TRUE; } @@ -136,14 +134,14 @@ function ife_add_person_submit($form, &$form_state) { } //only add new person if we are not adding from repository. - if (!isset($form_state['post']['add_from_repository']) || trim($form_state['post']['add_from_repository']) == '') { + $elName = isset($qt_form['entity0']['#parents'][0])?$qt_form['entity0']['#parents'][0]:null; + if ($elName == null || !isset($form_state['clicked_button']['#post'][$elName]['add_from_repository']) || trim($form_state['clicked_button']['#post'][$elName]['add_from_repository']) == '') { $people[] = array('name' => '', 'date'=>'', 'role' => '', 'subject' => ''); } - unset($form_state['submit_handlers']); form_execute_handlers('submit', $form, $form_state); $form_state['storage']['people'] = $people; - // $form_state['rebuild'] = TRUE; + $form_state['rebuild'] = TRUE; } @@ -200,6 +198,7 @@ function ife_add_conf_submit($form, &$form_state) { foreach ($peopleVals['people'] as $val) { $people[] = $val; } + $people[] = array('role' => '', 'conference' => '', 'subject' => ''); unset($form_state['submit_handlers']); diff --git a/form_elements/islandora_form_elements.module b/form_elements/islandora_form_elements.module index e174693b..094eff67 100644 --- a/form_elements/islandora_form_elements.module +++ b/form_elements/islandora_form_elements.module @@ -145,15 +145,16 @@ function ife_people_process($element,$edit,&$form_state) $people= array(); if (isset($form_state['storage']['people']) && !empty($form_state['storage']['people'])) { - foreach ($form_state['storage']['people'] as $ent) { - if ( trim($ent['name']) != '' || trim($ent['organization']) != '' || trim($ent['conference']) != '' || trim($ent['role']) != '' || trim($ent['date']) != '') { - $people[]=$ent; - } - } + foreach ($form_state['storage']['people'] as $ent) { + if ( trim($ent['name']) != '' || trim($ent['organization']) != '' || trim($ent['conference']) != '' || trim($ent['role']) != '' || trim($ent['date']) != '') { + $people[]=$ent; + } + } } $json = json_decode($form_state['post'][$element['#name']]['add_from_repository']); + $form_state['post'][$element['#name']]['add_from_repository'] = ''; // clear so that if the form is processed multiple times, it does not add twice. $person=array(); @@ -182,7 +183,6 @@ function ife_people_process($element,$edit,&$form_state) $form_state['storage']['people']=$people; - } else if (!isset($form_state['storage']['people']) || empty($form_state['storage']['people'])) { if ( (!isset($form_state['clicked_button']) || count($form_state['clicked_button']) == 0) && isset($element['#default_value']) && is_array($element['#default_value']) ) { diff --git a/form_elements/js/people_ahah.js b/form_elements/js/people_ahah.js index 9b89b0bb..0c545ba3 100755 --- a/form_elements/js/people_ahah.js +++ b/form_elements/js/people_ahah.js @@ -3,11 +3,13 @@ if (Drupal.jsEnabled) { $(document).ready(function() { - if (Drupal.ahah != undefined) { + $('#edit-mods-people-add-from-repository').blur(function () { + if ($('#edit-mods-people-add-from-repository').val() != '') { + $('#edit-mods-people-add-person').mousedown(); + } + }); - $('#edit-mods-people-add-from-repository').change(function () { - $('#edit-mods-people-add-person').mousedown(); - }); + if (Drupal.ahah != undefined) { /** * Override of Drupal.ahah.prototype.success. The only difference is that we @@ -87,4 +89,4 @@ Drupal.ahah.prototype.success = function (response, status) { }); } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/ilives/fedora_ilives.module b/ilives/fedora_ilives.module index 0f92d6b8..46022943 100644 --- a/ilives/fedora_ilives.module +++ b/ilives/fedora_ilives.module @@ -593,5 +593,52 @@ function install_book_content_model_objects() { if (!Fedora_Item::fedora_item_exists('ilives:CollectionModel')) { Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_CollectionModel.xml'); } +} + +/** + * Implementation of hook_requirements(). + * + * @return + * An array describing the status of the site regarding available updates. + * If there is no update data, only one record will be returned, indicating + * that the status of core can't be determined. If data is available, there + * will be two records: one for core, and another for all of contrib + * (assuming there are any contributed modules or themes enabled on the + * site). In addition to the fields expected by hook_requirements ('value', + * 'severity', and optionally 'description'), this array will contain a + * 'reason' attribute, which is an integer constant to indicate why the + * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or + * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail + * notification messages during update_cron(), and might be useful for other + * modules that invoke update_requirements() to find out if the site is up + * to date or not. + * + * @see _update_message_text() + * @see _update_cron_notify() + */ +function fedora_ilives_requirements($phase) { + global $base_url; + if ($phase == 'runtime') { + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $requirements['iiv-war'] = array(); + $requirements['iiv-war']['title'] = t("Islandora OpenLayers image viewer web app"); + if (!_fedora_ilives_viewer_available()) { + $requirements['iiv-war']['value'] = ("Not available"); + $requirements['iiv-war']['severity'] = REQUIREMENT_ERROR; + $requirements['iiv-war']['description'] = t('Ensure that Fedora is running and that the IIV app is deployed.', + array('@iiv-home' => 'http://github.com/islandora/iiv')); + } + else { + $requirements['iiv-war']['value'] = ("Available"); + $requirements['iiv-war']['severity'] = REQUIREMENT_OK; + } + } + return $requirements; +} +function _fedora_ilives_viewer_available() { + $url = parse_url(variable_get('fedora_base_url', 'http://localhost:8080/fedora')); + $fedora_host = ("{$url['scheme']}://{$url['host']}" . (!empty($url['port']) ? ":{$url['port']}/" : '/')); + $response = drupal_http_request("$fedora_host/iiv/images/loading.gif"); + return empty($response->error); } \ No newline at end of file diff --git a/plugins/ModsFormBuilder.inc b/plugins/ModsFormBuilder.inc index d3907d38..6eb36d1b 100644 --- a/plugins/ModsFormBuilder.inc +++ b/plugins/ModsFormBuilder.inc @@ -69,9 +69,9 @@ class ModsFormBuilder extends FormBuilder { ); $includeEl = true; - $name = explode('][', $element['name']); + $elname = explode('][', $element['name']); $elLocation = &$form['indicator2']; - while (isset($elLocation[$name[0]]) && ($partial = array_shift($name)) != NULL) { + while (isset($elLocation[$name[0]]) && ($partial = array_shift($elname)) != NULL) { $elLocation = &$elLocation[$partial]; } @@ -136,13 +136,13 @@ class ModsFormBuilder extends FormBuilder { $nameParts = $mname->getElementsByTagName('namePart'); foreach ($nameParts as $namePart) { - switch ($namePart->getAttribute('type')) { - case 'given': $given = $namePart->nodeValue; break; - case 'family': $family = $namePart->nodeValue; break; - case 'termsOfAddress': $title = $namePart->nodeValue; break; - case 'date': $date = $namePart->nodeValue; break; - default: $name = $namePart->nodeValue; break; - } + switch ($namePart->getAttribute('type')) { + case 'given': $given = $namePart->nodeValue; break; + case 'family': $family = $namePart->nodeValue; break; + case 'termsOfAddress': $title = $namePart->nodeValue; break; + case 'date': $date = $namePart->nodeValue; break; + default: $name = $namePart->nodeValue; break; + } } $person=array('role'=>$role); @@ -213,8 +213,8 @@ class ModsFormBuilder extends FormBuilder { $el['#options']= isset($element['authoritative_list'])?$element['authoritative_list']:array(); } - if ($includeEl) { - $elLocation[join('][', $name)] = $el; + if ($includeEl) { + $elLocation[join('][', $elname)] = $el; } } @@ -272,8 +272,8 @@ class ModsFormBuilder extends FormBuilder { } $this->createPolicy($collectionPid, &$dom, &$rootElement); -// header('Content-type: application/xml'); -// echo $dom->saveXML(); exit(); +// header('Content-type: application/xml'); +// echo $dom->saveXML(); exit(); try { $object = Fedora_Item::ingest_from_FOXML($dom); @@ -661,7 +661,7 @@ class ModsFormBuilder extends FormBuilder { if (isset($form_values['mods_people']) && isset($form_values['mods_people']['people']) && is_array($form_values['mods_people']['people']) ) { foreach ($form_values['mods_people']['people'] as $key => $val) { $name = $dom->createElement('mods:name'); - + $appendName=FALSE; if (isset($val['role'])) { $role = $dom->createElement('mods:role'); $roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role']))); @@ -676,6 +676,7 @@ class ModsFormBuilder extends FormBuilder { if (trim($val['organization']) != '') { $namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization']))); $name->appendChild($namePart); + $appendName=TRUE; } } elseif (isset($val['conference'])) { @@ -683,6 +684,7 @@ class ModsFormBuilder extends FormBuilder { if (trim($val['conference']) != '') { $namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference']))); $name->appendChild($namePart); + $appendName=TRUE; } } else { @@ -690,22 +692,24 @@ class ModsFormBuilder extends FormBuilder { if (trim($val['name']) != '') { $namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['name']))); $name->appendChild($namePart); + $appendName=TRUE; } } - if (isset($val['date'])) { - $namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['date']))); - $namePart->setAttribute('type','date'); - $name->appendChild($namePart); - } - - if (isset($val['subject'])) { + if (isset($val['date'])) { + $namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['date']))); + $namePart->setAttribute('type','date'); + $name->appendChild($namePart); + } + + if ($appendName) { + if (isset($val['subject'])) { $subject->appendChild($name); - $hasSubject=TRUE; - } else - { + $hasSubject=TRUE; + } else { $mods->appendChild($name); - } + } + } } }