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 <?php
/** /**
* @file islandora.admin.inc * @file
* islandora.admin.inc: This file contains the general islandora admin form and callback functions.
*/
/**
* Create admin form * Create admin form
* @return array * @return array
*/ */
function islandora_repository_admin($form, &$form_state) { function islandora_repository_admin($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
@ -77,7 +80,7 @@ function islandora_repository_admin($form, &$form_state) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fedora base URL'), '#title' => t('Fedora base URL'),
'#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'), '#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, '#required' => TRUE,
'#ajax' => array( '#ajax' => array(
'callback' => 'islandora_update_url_div', 'callback' => 'islandora_update_url_div',
@ -134,7 +137,7 @@ function islandora_repository_admin($form, &$form_state) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'), '#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), '#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, '#weight' => 0,
); );
} }

5
includes/breadcrumb.inc

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

36
includes/datastream.inc

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

5
includes/islandora.ingest.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains ingest callback functions
*/
function islandora_ingest_get_information(AbstractFedoraObject $collection_object) { function islandora_ingest_get_information(AbstractFedoraObject $collection_object) {
$models = $collection_object->models; $models = $collection_object->models;
$collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object); $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; $value = $values;
} }
$dc_label = explode(':', $field); $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]['label'] = $element_label;
$dc_array[$field]['value'] = $value; $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) { public function getMimetype($filename, $debug = FALSE) {
$file_name_and_extension = explode('.', $filename); $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 (!empty($this->protectedMimeTypes[$ext])) {
if (TRUE === $debug) { if (TRUE === $debug) {

16
includes/object_properties.inc

@ -1,7 +1,14 @@
<?php <?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 * 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 * an xsd:string there maybe further restrictions such as length but they aren't
* defined in the schema. * 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
* @param array $form_state * @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) { function islandora_edit_properties_form_delete($form, &$form_state) {
$islandora_object = $form_state['values']['pid']; $islandora_object = $form_state['values']['pid'];
drupal_goto("islandora/object/$islandora_object/delete"); drupal_goto("islandora/object/$islandora_object/delete");
} }
/** /**
* Object properties admin form.
* *
* @param array $form * @param array $form
* @param array $form_state * @param array $form_state
@ -111,5 +123,3 @@ function islandora_edit_properties_form($form, &$form_state, $object) {
); );
return $form; return $form;
} }
?>

5
includes/purge.form.inc

@ -1,5 +1,10 @@
<?php <?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. * Gives the option of deleting or purging and object.
* *

10
includes/tuque.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains a class to include the Tuque php library.
*/
$islandora_module_path = drupal_get_path('module', 'islandora'); $islandora_module_path = drupal_get_path('module', 'islandora');
//do this until we expost these in a module or library //do this until we expost these in a module or library
@ -61,7 +66,8 @@ class IslandoraTuque {
if (!isset($user) || $user->uid == 0) { if (!isset($user) || $user->uid == 0) {
$user_string = 'anonymous'; $user_string = 'anonymous';
$pass_string = 'anonymous'; $pass_string = 'anonymous';
} else { }
else {
$user_string = $user->name; $user_string = $user->name;
$pass_string = $user->pass; $pass_string = $user->pass;
} }
@ -87,7 +93,7 @@ class IslandoraTuque {
$islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora'); $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'); $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)); $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 <?php
/**
* @file
* Contains islandora utility functions
*/
/** /**
* Convert bytes to human readable format * Convert bytes to human readable format
* *
* @param integer bytes Size in bytes to convert * @param integer bytes Size in bytes to convert
* @return string * @return string
*/ */
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
{
$kilobyte = 1024; $kilobyte = 1024;
$megabyte = $kilobyte * 1024; $megabyte = $kilobyte * 1024;
$gigabyte = $megabyte * 1024; $gigabyte = $megabyte * 1024;
@ -15,19 +19,20 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2)
if (($bytes >= 0) && ($bytes < $kilobyte)) { if (($bytes >= 0) && ($bytes < $kilobyte)) {
return $bytes . ' B'; return $bytes . ' B';
}
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
return round($bytes / $kilobyte, $precision) . ' KB'; return round($bytes / $kilobyte, $precision) . ' KB';
}
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
return round($bytes / $megabyte, $precision) . ' MB'; return round($bytes / $megabyte, $precision) . ' MB';
}
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
return round($bytes / $gigabyte, $precision) . ' GB'; return round($bytes / $gigabyte, $precision) . ' GB';
}
} elseif ($bytes >= $terabyte) { elseif ($bytes >= $terabyte) {
return round($bytes / $terabyte, $precision) . ' TB'; return round($bytes / $terabyte, $precision) . ' TB';
} else { }
else {
return $bytes . ' B'; return $bytes . ' B';
} }
} }
@ -54,7 +59,7 @@ function islandora_control_group_to_human_readable($control_group) {
*/ */
function islandora_validate_pid($pid) { function islandora_validate_pid($pid) {
$valid = FALSE; $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; $valid = TRUE;
} }
@ -68,7 +73,7 @@ function islandora_validate_pid($pid) {
*/ */
function islandora_validate_dsid($dsid) { function islandora_validate_dsid($dsid) {
$valid = FALSE; $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; $valid = TRUE;
} }

6
islandora.api.php

@ -1,4 +1,10 @@
<?php <?php
/**
* @file
* This file lists and documents all available hook functions to manipulate data.
*/
/** /**
* remove a datastream from a repository object * remove a datastream from a repository object
* @param object $fedora_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 <?php
/* /*
* @file islandora.module * @file
* defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
* *
* 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. * This file is part of Islandora.
* *
@ -36,7 +36,7 @@ define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
define('ISLANDORA_EDIT_HOOK', 'islandora_edit_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 * we need some standard entry points so we can have consistent urls for different Object actions
*/ */
function islandora_menu() { function islandora_menu() {

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

@ -1,30 +1,9 @@
<?php <?php
/* /**
* islandora-object-edit.tpl.php * @file
* * islandora-object-edit.tpl.php: This is a template for objects that do not have
* * a module to registered to build their display.
*
* 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.
* *
* islandora_object is a fedora tuque Object * islandora_object is a fedora tuque Object
* $object->label * $object->label
@ -37,14 +16,9 @@
* and each element has an array of values. dc.title can have none, one or many titles * 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. * 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 <?php
/* /*
* islandora-object.tpl.php * @file
* * This is a template for objects that do not have a module to registered to build their display.
*
*
* 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.
* *
* islandora_object is a fedora tuque Object * islandora_object is a fedora tuque Object
* $object->label - The label for this object. * $object->label - The label for this object.

11
theme/islandora.theme.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains all theme and preprocess functions.
*/
/** /**
* preprocess the edit template * preprocess the edit template
* @global string $base_url * @global string $base_url
@ -72,9 +77,11 @@ function islandora_preprocess_islandora_default(&$variables) {
$datastreams[$id]['mimetype'] = $ds->mimetype; $datastreams[$id]['mimetype'] = $ds->mimetype;
$datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds); $datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds);
$datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d"); $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; $variables['datastreams'] = $datastreams;
try { try {

Loading…
Cancel
Save