diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 42612ea0..51116f5c 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -68,6 +68,12 @@ function islandora_repository_admin(array $form, array &$form_state) { useful if derivatives are to be created by an external service.'), '#default_value' => variable_get('islandora_defer_derivatives_on_ingest', FALSE), ), + 'islandora_show_print_option' => array( + '#type' => 'checkbox', + '#title' => t('Show print option on objects'), + '#description' => t('Displays an extra print tab, allowing an object to be printed'), + '#default_value' => variable_get('islandora_show_print_option', FALSE), + ), ), 'islandora_namespace' => array( '#type' => 'fieldset', diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index c83b140c..6893511a 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -80,10 +80,6 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura */ function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) { if (empty($form_state['islandora'])) { - $objects = isset($configuration['objects']) ? $configuration['objects'] : array(); - if (empty($objects)) { - $objects[] = islandora_ingest_form_prepare_new_object($configuration); - } $configuration['models'] = isset($configuration['models']) ? $configuration['models'] : array(); // Make sure the models actually exist. foreach ($configuration['models'] as $key => $model) { @@ -91,15 +87,15 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array unset($configuration['models'][$key]); } } - // No need to persist the 'objects' within the configuration. - unset($configuration['objects']); // Required for step hooks. $form_state['islandora'] = array( 'step_id' => NULL, - 'objects' => $objects, + 'objects' => $configuration['objects'], 'shared_storage' => $configuration, 'step_storage' => array(), ); + // No need to persist the 'objects' within the configuration. + unset($configuration['objects']); // Must be called after $form_state['islandora'] is initialized, otherwise, // the values in 'islandora' would not be availible to the step hooks. $form_state['islandora']['step_id'] = islandora_ingest_form_get_first_step_id($form_state); @@ -136,33 +132,6 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { return array_pop($keys); } -/** - * Prepares a new object based on the given configuration. - * - * @param array $configuration - * The list of key/value pairs of configuration. - * - * @return NewFedoraObject - * The new object. - */ -function islandora_ingest_form_prepare_new_object(array $configuration) { - module_load_include('inc', 'islandora', 'includes/utilities'); - if (empty($configuration['object'])) { - $message = islandora_deprecated('7.x-1.2', t('Please use "objects" as the default ingest form configuration property.')); - trigger_error(filter_xss($message), E_USER_DEPRECATED); - // ID is more specific than namespace so it will take precedence. - $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; - $id = isset($configuration['id']) ? $configuration['id'] : $id; - $label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; - $relationship_map = function($o) { - return array('relationship' => 'isMemberOfCollection', 'pid' => $o); - }; - $relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']); - return islandora_prepare_new_object($id, $label, array(), array(), $relationships); - } - return $configuration['object']; -} - /** * Gets the given/current step. * @@ -762,6 +731,7 @@ function islandora_ingest_form_ingest_button_process(array $element) { "$islandora_path/js/spinner.js", ), ); + $element['#attributes']['class'][] = 'islandora-spinner-submit'; return $element; } diff --git a/includes/utilities.inc b/includes/utilities.inc index 7476948b..8682a4bc 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -72,6 +72,9 @@ function islandora_temp_file_entry($file_uri, $mime = NULL) { if (isset($mime)) { $file->filemime = $mime; } + else { + $file->filemime = file_get_mimetype($file_uri); + } } $file->status = 0; return file_save($file); @@ -194,11 +197,14 @@ function islandora_invoke_hook_list($hook, array $refinements, array $args) { $return = array_merge_recursive($return, $result); array_shift($args); } - if (module_exists('rules') && $event = rules_get_cache("event_$hook")) { - $parameters = $event->parameterInfo(); - $rule_args = array_slice($args, 0, count($parameters)); - array_unshift($rule_args, $hook); - $result = call_user_func_array('rules_invoke_event', $rule_args); + if (module_exists('rules')) { + $event_info = rules_get_event_info($hook); + if (isset($event_info['module'])) { + $parameters = $event_info['variables']; + $rule_args = array_slice($args, 0, count($parameters)); + array_unshift($rule_args, $hook); + $result = call_user_func_array('rules_invoke_event', $rule_args); + } } return $return; } @@ -655,53 +661,6 @@ function islandora_system_settings_form_default_value($name, $default_value, arr return isset($form_state['values'][$name]) ? $form_state['values'][$name] : variable_get($name, $default_value); } -/** - * Checks that the given/current account has all the given permissions. - * - * @param array $perms - * The permissions to check. - * @param mixed $account - * (optional) The account to check, if not given use currently logged in user. - * - * @return bool - * TRUE if the account has all the given permissions, FALSE otherwise. - */ -function islandora_user_access_all(array $perms, $account = NULL) { - $message = islandora_deprecated('7.x-1.2', 'Roll your own code or use islandora_user_access().'); - trigger_error(filter_xss($message), E_USER_DEPRECATED); - - foreach ($perms as $perm) { - if (!user_access($perm, $account)) { - return FALSE; - } - } - return TRUE; -} - -/** - * Checks that the given/current account has at one of the given permissions. - * - * @param array $perms - * The permissions to check. - * @param mixed $account - * (optional) The account to check, if not given use currently logged in user. - * - * @return bool - * TRUE if the account has at least one of the given permissions, FALSE - * otherwise. - */ -function islandora_user_access_any(array $perms, $account = NULL) { - $message = islandora_deprecated('7.x-1.2', 'Roll your own code or use islandora_user_access().'); - trigger_error(filter_xss($message), E_USER_DEPRECATED); - - foreach ($perms as $perm) { - if (user_access($perm, $account)) { - return TRUE; - } - } - return FALSE; -} - /** * Gets the list of allowed namespaces as defined by 'islandora_pids_allowed'. * diff --git a/islandora.module b/islandora.module index 31986877..567a39bd 100644 --- a/islandora.module +++ b/islandora.module @@ -147,7 +147,7 @@ function islandora_menu() { 'page callback' => 'islandora_printer_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, - 'access callback' => 'islandora_object_access', + 'access callback' => 'islandora_print_object_access', 'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2), ); $items['islandora/object/%islandora_object/print'] = array( @@ -663,6 +663,31 @@ function islandora_print_object(AbstractObject $object) { return theme('islandora_object_print', array('object' => $object)); } +/** + * View print tab access. + * + * Configurable option in islandora configuration. + * + * @param string $op + * String identifying an operation to check. Should correspond to a + * permission declared via hook_permission(). + * @param AbstractObject $object + * An object to check for permissions. + * + * @return bool + * TRUE if at least one implementation of hook_islandora_object_access() + * returned TRUE, and no implementation return FALSE; FALSE otherwise, or + * FALSE if 'islandora_show_print_option' is not selected in islandora + * configuraton. + */ +function islandora_print_object_access($op, $object) { + if (!variable_get('islandora_show_print_option', FALSE)) { + return FALSE; + } + $access = islandora_object_access($op, $object); + return $access; +} + /** * Implements hook_forms(). */ @@ -815,34 +840,6 @@ function islandora_object_access_callback($perm, $object = NULL) { return islandora_object_access($perm, $object); } -/** - * Checks whether the user can access the given object and datastream. - * - * Checks for object existance, accessiblitly, namespace permissions, - * and user permissions - * - * @param string $perm - * The user permission to test for. - * @param AbstractObject $object - * The object to test, if NULL given the object doesn't exist or is - * inaccessible. - * @param AbstractDatastream $datastream - * The datastream to test, if NULL given the datastream doesn't exist - * or is inaccessible. - * @param StdObject $account - * The account to test permissions as or NULL for current user. - * - * @return bool - * TRUE if the user is allowed to access this object, FALSE otherwise. - */ -function islandora_object_datastream_access_callback($perm, $object = NULL, $datastream = NULL, $account = NULL) { - module_load_include('inc', 'islandora', 'includes/utilities'); - $message = islandora_deprecated('7.x-1.2', 'Use islandora_datastream_access().'); - trigger_error(filter_xss($message), E_USER_DEPRECATED); - - return islandora_datastream_access($perm, $datastream, $account); -} - /** * Checks whether the user can access the given object and datastream. * @@ -1070,6 +1067,7 @@ function islandora_view_object(AbstractObject $object) { function islandora_printer_object(AbstractObject $object) { $output = array(); $temp_arr = array(); + // Dispatch print hook. foreach (islandora_build_hook_list(ISLANDORA_PRINT_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); @@ -1091,19 +1089,20 @@ function islandora_printer_object(AbstractObject $object) { * Title callback for drupal title. * * Changes the drupal title to be the objects label. - * models that their modules want to provide a view for. * * @param AbstractObject $object * The object to view. * * @return string - * The objects label. + * The objects label. Note that we return the raw value to prevent + * double encoding, as we expect drupal_set_title() to check_plain() down + * the road. */ function islandora_drupal_title(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); - return filter_xss($object->label); + return $object->label; } /** @@ -1950,7 +1949,7 @@ function islandora_islandora_datastream_access($op, AbstractDatastream $datastre $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); $hooks = islandora_filter_derivatives($hooks, array('force' => TRUE), $object); foreach ($hooks as $hook) { - if ($hook['destination_dsid'] == $datastream->id && + if (isset($hook['destination_dsid']) && $hook['destination_dsid'] == $datastream->id && (is_null($hook['source_dsid']) || islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[$hook['source_dsid']], $user))) { $applicable_hook = TRUE; break; @@ -2010,7 +2009,7 @@ function islandora_menu_local_tasks_alter(&$data, $router_item, $root_path) { if ($tab['#link']['path'] == 'islandora/object/%/print_object') { if ($root_path == 'islandora/object/%') { $islandora_path = drupal_get_path('module', 'islandora'); - $tab['#prefix'] = '