Browse Source

coder cleanup

pull/165/head
DannyJoris 12 years ago
parent
commit
cd8e9d8df0
  1. 11
      admin/islandora.admin.inc
  2. 5
      includes/breadcrumb.inc
  3. 36
      includes/datastream.inc
  4. 5
      includes/islandora.ingest.inc
  5. 4
      includes/islandora_dublin_core.inc
  6. 2
      includes/mime.detect.inc
  7. 16
      includes/object_properties.inc
  8. 5
      includes/purge.form.inc
  9. 10
      includes/tuque.inc
  10. 31
      includes/utilities.inc
  11. 6
      islandora.api.php
  12. 6
      islandora.install
  13. 6
      islandora.module
  14. 40
      theme/islandora-object-edit.tpl.php
  15. 26
      theme/islandora-object.tpl.php
  16. 11
      theme/islandora.theme.inc

11
admin/islandora.admin.inc

@ -1,11 +1,14 @@
<?php
/**
* @file islandora.admin.inc
* @file
* islandora.admin.inc: This file contains the general islandora admin form and callback functions.
*/
/**
* Create admin form
* @return array
*/
function islandora_repository_admin($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/tuque');
module_load_include('inc', 'islandora', 'includes/utilities');
@ -77,7 +80,7 @@ function islandora_repository_admin($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Fedora base URL'),
'#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST connections <br>' . $confirmation_message),
'#description' => t('The URL to use for REST connections <br />' . $confirmation_message),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'islandora_update_url_div',
@ -134,7 +137,7 @@ function islandora_repository_admin($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '),
'#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos. <br> islandora: is reserved and is always allowed.'),
'#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos. <br /> islandora: is reserved and is always allowed.'),
'#weight' => 0,
);
}

5
includes/breadcrumb.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* This file contains functions to create breadcrumbs on Islandora object pages.
*/
function islandora_get_breadcrumbs($object) {
$breadcrumbs = array();

36
includes/datastream.inc

@ -1,11 +1,13 @@
<?php
/**
* @file datastream.inc
* @file
* This file contains the admin form and callback functions for datastream manipulations.
*/
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
/**
* Callback function to view or download a datastream.
*
* @global object $user
* @param string $object_id
@ -55,7 +57,9 @@ function islandora_datastream_get_parents($islandora_object) {
$parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
}
catch (RepositoryException $e) {}
catch (RepositoryException $e) {
}
}
return $parent_collections;
@ -168,9 +172,9 @@ function islandora_get_add_datastream_form($object, &$form_state) {
);
if (!empty($unused_dsids)) {
$dsidsForForm = array();
$dsids_for_form = array();
foreach ($unused_dsids as $key => $value) {
$dsidsForForm[$key] = $key;
$dsids_for_form[$key] = $key;
}
$form['add_fieldset']['stream_id'] = array(
'#type' => 'select',
@ -179,7 +183,7 @@ function islandora_get_add_datastream_form($object, &$form_state) {
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
);
$form['add_fieldset']['stream_id']['#options'] = $dsidsForForm;
$form['add_fieldset']['stream_id']['#options'] = $dsids_for_form;
}
else {
$form['add_fieldset']['stream_id'] = array(
@ -220,11 +224,11 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
$dsid = $form_state['values']['stream_id'];
$ds_label = $form_state['values']['stream_label'];
$dformat = $mimetype->getMimeType($file);
$controlGroup = "M";
$control_group = "M";
try {
$fedora_object = islandora_object_load($object_id);
$ds = $fedora_object->constructDatastream($dsid, $controlGroup);
$ds = $fedora_object->constructDatastream($dsid, $control_group);
$ds->label = $ds_label;
$ds->mimetype = $dformat;
$ds->setContentFromFile($file);
@ -235,7 +239,7 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return;
}
drupal_set_message("Successfully Added Datastream!");
drupal_set_message(t("Successfully Added Datastream!"));
drupal_goto("islandora/object/$object_id");
}
@ -254,8 +258,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
return;
}
$dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label'];
if (strlen($dsid) > 64) {
$ds_label = $form_state['values']['stream_label'];
if (drupal_strlen($dsid) > 64) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE;
}
@ -263,11 +267,11 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
return FALSE;
}
if (strlen($dsLabel) > 64) {
if (drupal_strlen($ds_label) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
}
if (strpos($dsLabel, '/')) {
if (strpos($ds_label, '/')) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
}
@ -356,19 +360,19 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
);
$unused_dsids = islandora_get_unused_dsids($object);
$dsidsForForm = '';
$dsids_for_form = '';
$i = 0;
foreach ($unused_dsids as $key => $value) {
if ($i++) {
$dsidsForForm .= ", ";
$dsids_for_form .= ", ";
}
$dsidsForForm .= "'$key'";
$dsids_for_form .= "'$key'";
}
$form['add_fieldset']['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. Datastreams that are defined by the content model dont currently exist: <b>' . $dsidsForForm . '</b>.'),
'#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. Datastreams that are defined by the content model dont currently exist: <b>' . $dsids_for_form . '</b>.'),
'#type' => 'textfield',
'#weight' => -1,
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",

5
includes/islandora.ingest.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* This file contains ingest callback functions
*/
function islandora_ingest_get_information(AbstractFedoraObject $collection_object) {
$models = $collection_object->models;
$collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object);

4
includes/islandora_dublin_core.inc

@ -121,10 +121,10 @@ class Dublin_Core {
$value = $values;
}
$dc_label = explode(':', $field);
$element_label = ucfirst($dc_label[1]);
$element_label = drupal_ucfirst($dc_label[1]);
$dc_array[$field]['label'] = $element_label;
$dc_array[$field]['value'] = $value;
$dc_array[$field]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field));
$dc_array[$field]['class'] = drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field));
}
}
}

2
includes/mime.detect.inc

@ -227,7 +227,7 @@ class MimeDetect {
public function getMimetype($filename, $debug = FALSE) {
$file_name_and_extension = explode('.', $filename);
$ext = strtolower(array_pop($file_name_and_extension));
$ext = drupal_strtolower(array_pop($file_name_and_extension));
if (!empty($this->protectedMimeTypes[$ext])) {
if (TRUE === $debug) {

16
includes/object_properties.inc

@ -1,7 +1,14 @@
<?php
/**
* may want more validation here the only restrictions i see on
* @file
* Contains admin form functions for object properties
*/
/**
* Validate function for object properties admin form.
*
* @TODO: may want more validation here the only restrictions i see on
* the object label and owner is the foxml schema says they should be
* an xsd:string there maybe further restrictions such as length but they aren't
* defined in the schema.
@ -18,6 +25,7 @@ function islandora_edit_properties_form_validate($form, &$form_state) {
}
/**
* Submit function for object properties admin form.
*
* @param array $form
* @param array $form_state
@ -53,12 +61,16 @@ function islandora_edit_properties_form_submit($form, &$form_state) {
}
}
/**
* Callback function for object properties admin form delete button.
*/
function islandora_edit_properties_form_delete($form, &$form_state) {
$islandora_object = $form_state['values']['pid'];
drupal_goto("islandora/object/$islandora_object/delete");
}
/**
* Object properties admin form.
*
* @param array $form
* @param array $form_state
@ -111,5 +123,3 @@ function islandora_edit_properties_form($form, &$form_state, $object) {
);
return $form;
}
?>

5
includes/purge.form.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* This file contains the admin (confirmation) form and callback functions to purge an object.
*/
/**
* Gives the option of deleting or purging and object.
*

10
includes/tuque.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* This file contains a class to include the Tuque php library.
*/
$islandora_module_path = drupal_get_path('module', 'islandora');
//do this until we expost these in a module or library
@ -61,7 +66,8 @@ class IslandoraTuque {
if (!isset($user) || $user->uid == 0) {
$user_string = 'anonymous';
$pass_string = 'anonymous';
} else {
}
else {
$user_string = $user->name;
$pass_string = $user->pass;
}
@ -87,7 +93,7 @@ class IslandoraTuque {
$islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora');
$tuque_link = l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque');
$message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link));
drupal_set_message($message, 'error', FALSE);
drupal_set_message(filter_xss($message), 'error', FALSE);
}
}

31
includes/utilities.inc

@ -1,13 +1,17 @@
<?php
/**
* @file
* Contains islandora utility functions
*/
/**
* Convert bytes to human readable format
*
* @param integer bytes Size in bytes to convert
* @return string
*/
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2)
{
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
$kilobyte = 1024;
$megabyte = $kilobyte * 1024;
$gigabyte = $megabyte * 1024;
@ -15,19 +19,20 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2)
if (($bytes >= 0) && ($bytes < $kilobyte)) {
return $bytes . ' B';
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
}
elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
return round($bytes / $kilobyte, $precision) . ' KB';
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
}
elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
return round($bytes / $megabyte, $precision) . ' MB';
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
}
elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
return round($bytes / $gigabyte, $precision) . ' GB';
} elseif ($bytes >= $terabyte) {
}
elseif ($bytes >= $terabyte) {
return round($bytes / $terabyte, $precision) . ' TB';
} else {
}
else {
return $bytes . ' B';
}
}
@ -54,7 +59,7 @@ function islandora_control_group_to_human_readable($control_group) {
*/
function islandora_validate_pid($pid) {
$valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
if (drupal_strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
$valid = TRUE;
}
@ -68,7 +73,7 @@ function islandora_validate_pid($pid) {
*/
function islandora_validate_dsid($dsid) {
$valid = FALSE;
if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
if (drupal_strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
$valid = TRUE;
}

6
islandora.api.php

@ -1,4 +1,10 @@
<?php
/**
* @file
* This file lists and documents all available hook functions to manipulate data.
*/
/**
* remove a datastream from a repository object
* @param object $fedora_object

6
islandora.install

@ -0,0 +1,6 @@
<?php
/**
* @file
* This file contains all install functions.
*/

6
islandora.module

@ -1,9 +1,9 @@
<?php
/*
* @file islandora.module
* defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
* @file
*
* islandora.module: defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
*
* This file is part of Islandora.
*
@ -36,7 +36,7 @@ define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object');
/**
* Implementation of hook_menu.
* Implements hook_menu().
* we need some standard entry points so we can have consistent urls for different Object actions
*/
function islandora_menu() {

40
theme/islandora-object-edit.tpl.php

@ -1,30 +1,9 @@
<?php
/*
* islandora-object-edit.tpl.php
*
*
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
?>
<?php
/*
* this is a template for objects that do not have a module to registered to build their display.
/**
* @file
* islandora-object-edit.tpl.php: This is a template for objects that do not have
* a module to registered to build their display.
*
* islandora_object is a fedora tuque Object
* $object->label
@ -37,14 +16,9 @@
* and each element has an array of values. dc.title can have none, one or many titles
* this is the case for all dc elements.
*
*
*
*/
//dsm($object);
drupal_set_title($islandora_object->label);
//print($islandora_object->label . ' ' . $islandora_object->id);
print (theme_table($variables['datastream_table']));
?>
<?php drupal_set_title($islandora_object->label); ?>
<?php print (theme_table($variables['datastream_table'])); ?>

26
theme/islandora-object.tpl.php

@ -1,30 +1,8 @@
<?php
/*
* islandora-object.tpl.php
*
*
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
?>
<?php
/*
* this is a template for objects that do not have a module to registered to build their display.
* @file
* This is a template for objects that do not have a module to registered to build their display.
*
* islandora_object is a fedora tuque Object
* $object->label - The label for this object.

11
theme/islandora.theme.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* This file contains all theme and preprocess functions.
*/
/**
* preprocess the edit template
* @global string $base_url
@ -72,9 +77,11 @@ function islandora_preprocess_islandora_default(&$variables) {
$datastreams[$id]['mimetype'] = $ds->mimetype;
$datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds);
$datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d");
$datastreams[$id]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id));
$datastreams[$id]['class'] = drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id));
}
catch (RepositoryException $e) {
}
catch (RepositoryException $e) {}
}
$variables['datastreams'] = $datastreams;
try {

Loading…
Cancel
Save