Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.x #126

Merged
merged 81 commits into from
Jun 4, 2012
Merged

6.x #126

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d36fdd2
Fix Headers for FlowPlayer
adam-vessey Jul 12, 2011
5aefe46
Use wrapping modify_datastream wrapper in replace datastream callback.
adam-vessey Apr 24, 2012
fa77552
Get the extension without exploding.
adam-vessey Apr 25, 2012
01ac63a
Allow the addition of Redirect and External datastreams.
adam-vessey Apr 25, 2012
8cfdc90
Fix issue with downloading versioned datastreams.
adam-vessey Apr 25, 2012
7bc755f
Make control group selection optional.
adam-vessey Apr 25, 2012
1322489
Fix error when label contains an extension.
adam-vessey Apr 25, 2012
5b3fe1e
Use Sparql query for breadcrumbs.
adam-vessey Apr 26, 2012
3696cab
Generate the download form.
adam-vessey Apr 26, 2012
27fdb97
Merge branch '6.x' of github.com:Islandora/islandora into 6.x
adam-vessey Apr 26, 2012
6006eff
Make a little closed to convertQDC.xsl
adam-vessey Apr 26, 2012
278afdf
Fix syntax error involving reference.
adam-vessey Apr 26, 2012
08545aa
Fix error message.
adam-vessey Apr 26, 2012
62e4351
Merge branch '6.x' of github.com:adam-vessey/islandora into 6.x
adam-vessey Apr 26, 2012
27d6c76
Fix syntax error.
adam-vessey Apr 27, 2012
2ac5ad4
Try to use covertQDC.xsl before using the Drupal's table generating b…
adam-vessey Apr 27, 2012
1460b8e
Fix error.
adam-vessey Apr 27, 2012
7645a7b
Format XSLT and pass parameters.
adam-vessey Apr 27, 2012
47d85f6
Add comments and rename XSLT so it is not used by default...
adam-vessey Apr 27, 2012
01c5a47
Fix error in CollectionClass.
adam-vessey Apr 27, 2012
6d57165
Avoid warning/error when file does not exist.
adam-vessey Apr 30, 2012
5655a51
Extract Drupal collection view assembly into separate function.
adam-vessey Apr 30, 2012
ee2477d
Add the page parameter to the islandora_tabs hook call.
adam-vessey Apr 30, 2012
5714ef7
Merge branch '6.x' of github.com:adam-vessey/islandora into 6.x
adam-vessey Apr 30, 2012
d2b0a11
Truncate titles for regular display to 60 character +/- a word.
adam-vessey May 1, 2012
ee2b6a9
Use hook_islandora_tabs() to add ALL the tabs.
adam-vessey May 1, 2012
83cd4b8
Introduce hook_islandora_tabs_alter().
adam-vessey May 1, 2012
73c55ca
Use hook_islandora_tabs_alter() to ensure that fedora_object_details …
adam-vessey May 1, 2012
c7e05f4
Improve code documentation.
adam-vessey May 1, 2012
61204b9
Fix datastream replacement errors.
adam-vessey May 2, 2012
48c1551
Fix Headers for FlowPlayer
adam-vessey Jul 12, 2011
2d9c55f
Make a little closed to convertQDC.xsl
adam-vessey Apr 26, 2012
fe76285
Use wrapping modify_datastream wrapper in replace datastream callback.
adam-vessey Apr 24, 2012
842b8b5
Get the extension without exploding.
adam-vessey Apr 25, 2012
c3ccdec
Allow the addition of Redirect and External datastreams.
adam-vessey Apr 25, 2012
b609a8f
Make control group selection optional.
adam-vessey Apr 25, 2012
c76891f
Use Sparql query for breadcrumbs.
adam-vessey Apr 26, 2012
948bba9
Generate the download form.
adam-vessey Apr 26, 2012
373c390
Try to use covertQDC.xsl before using the Drupal's table generating b…
adam-vessey Apr 27, 2012
d44aca6
Format XSLT and pass parameters.
adam-vessey Apr 27, 2012
1068dbd
Add comments and rename XSLT so it is not used by default...
adam-vessey Apr 27, 2012
0d6c34e
Avoid warning/error when file does not exist.
adam-vessey Apr 30, 2012
ee44279
Extract Drupal collection view assembly into separate function.
adam-vessey Apr 30, 2012
c014959
Add the page parameter to the islandora_tabs hook call.
adam-vessey Apr 30, 2012
6d6342c
Truncate titles for regular display to 60 character +/- a word.
adam-vessey May 1, 2012
f51cdfe
Use hook_islandora_tabs() to add ALL the tabs.
adam-vessey May 1, 2012
67bd855
Introduce hook_islandora_tabs_alter().
adam-vessey May 1, 2012
828c696
Use hook_islandora_tabs_alter() to ensure that fedora_object_details …
adam-vessey May 1, 2012
1463c78
Improve code documentation.
adam-vessey May 1, 2012
2d1e640
Add usage of imagecache_external, if available.
adam-vessey May 4, 2012
1314b09
Merge branch '6.x-merged' of github.com:adam-vessey/islandora into 6.x
adam-vessey May 4, 2012
830b597
Add parameter to suppress error messages on get_datastream
adam-vessey May 4, 2012
f674a99
Use url() to build query.
adam-vessey May 4, 2012
7749a2f
Introduce and use function to render an image.
adam-vessey May 4, 2012
9a52580
Comment refinement.
adam-vessey May 7, 2012
933d0bc
Fix stream addition with language prefixes.
adam-vessey May 7, 2012
8bd4b29
Test and add configuration.
adam-vessey May 7, 2012
c1615e4
Use Drupal functions in XSLT to generate URLs.
adam-vessey May 7, 2012
536c6e5
Add missing include.
adam-vessey May 8, 2012
1c76668
invoke custom hooks to retrieve metadata display instead of hard-codi…
jmacwilliams May 11, 2012
6701587
added menu path to load object profile configurations, setup admin pa…
jmacwilliams May 11, 2012
a88fee9
added core object details code
jmacwilliams May 11, 2012
c05e3da
add the mod2html stylesheet for testing transforms
jmacwilliams May 11, 2012
55a355f
removed 'jason' code guards
jmacwilliams May 14, 2012
a0891d6
remove 'jason' code guards
jmacwilliams May 14, 2012
672179a
remove an erroneous text widget (from development) and completed the …
jmacwilliams May 14, 2012
2e427bb
moved alert message to watchdog and fixed an incorrect default value
jmacwilliams May 14, 2012
1fcdfbd
added menu hook so table config works, fixed an incorrect default val…
jmacwilliams May 14, 2012
48c63fa
Simplify logic in get datastream list and allow multiple pids to be o…
adam-vessey May 14, 2012
7b5d3cb
Fix move_to_trash function.
adam-vessey May 17, 2012
3c31229
Merge branch '6.x' of github.com:Islandora/islandora into 6.x
adam-vessey May 17, 2012
3d09a8d
Merge branch '6.x' of git://github.com/jmacwilliams/islandora into HEAD
adam-vessey May 17, 2012
582d735
Minor cleanup.
adam-vessey May 17, 2012
be55312
Clean up renderCollection function.
adam-vessey May 17, 2012
6370a12
Fix breadcrumbs, so that an entry for the current object is not added.
adam-vessey May 23, 2012
94c73ff
Suppress warnings for XSLTs that do not exist for Object Details tab.
adam-vessey May 23, 2012
d2474b9
Set the title.
adam-vessey May 23, 2012
c636034
Improve relationship management.
adam-vessey May 23, 2012
b14ba23
Stop setting the title.
adam-vessey May 23, 2012
694c403
Bit safer with labels and minor optimization.
adam-vessey Jun 4, 2012
61dcfa0
Merge branch '6.x' of github.com:Islandora/islandora into 6.x
adam-vessey Jun 4, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 93 additions & 62 deletions CollectionClass.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ class CollectionClass {
* @return CollectionClass
*/
function __construct($pid = NULL) {
if (!empty($pid)) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$this->collectionObject = new ObjectHelper($pid);
$this->pid = $pid;
}
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$this->collectionObject = new ObjectHelper();
$this->pid = $pid;
}

public static function getCollectionQuery($pid) {
Expand Down Expand Up @@ -672,6 +670,86 @@ class CollectionClass {
return $page;
}

/**
* Assemble results in a somewhat more logical manner...
*
* ... Compared to generating a table in XSLT to contain a list (as
* renderCollection() used to do/does by default).
*
* @param $sparql_results array
* The array of results as yielded by ObjectHelper::parseSparqlResults()
* (and those associated functions which make use of it).
* Each result must contain:
* - 'object': The PID/URI of the child object.
* - 'title': A title for the child object.
* and may contain:
* - 'thumbnail': URI to a datastream. (will default to the 'TN' stream on the child)
* @return
* An array to be passed to drupal_render, containing a pager, an unordered
* list of items, and another pager.
*/
public static function assembleCollectionView($sparql_results) {
$per_page = 20; //XXX: Make this configurable.
$pager_name = 0;
$total = count($sparql_results);
$pager_page = self::hackPager($pager_name, $per_page, $total);
$max_title_length = 60;

$results = array();
foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) {
$title = $result['title'];
$truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5);
$obj_path = "fedora/repository/{$result['object']}";

//Get a thumbnail
$tn_path = ($result['thumbnail'] ?
"fedora/repository/{$result['thumbnail']}":
"$obj_path/TN");

$thumbnail = _fedora_repository_render_image($tn_path);

$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
'attributes' => array(
'class' => 'results-image',
),
)) . l($truncated_title, $obj_path, array('attributes' => array('class' => 'results-text'))),
);
}
if (!$results) {
drupal_set_message(t("No objects in this collection (or bad query)."));
}
else {
$first = $per_page * $pager_page;
$last = (($total - $first) > $per_page)?
($first + $per_page):
$total;
$results_range_text = t('Results @first to @last of @total', array(
'@first' => $first + 1,
'@last' => $last,
'@total' => $total,
));

return array(
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name),
),
array(
'#type' => 'markup',
'#value' => theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
))
),
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name)
),
);
}
}

/**
* render collection
* @global type $base_url
Expand All @@ -685,17 +763,8 @@ class CollectionClass {
function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository');
global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe
$parsedContent = NULL;
if(!isset($this->collectionObject)){
$this->collectionObject = new ObjectHelper($pid);
}

$contentModels = $this->collectionObject->get_content_models_list($pid);
$isCollection = FALSE;
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.

$fedoraItem = NULL;

if (empty($collectionName)) {
$collectionName = menu_get_active_title();
Expand All @@ -706,48 +775,13 @@ class CollectionClass {
$objectList = '';
if (isset($content) && $content != FALSE) {
if (!$xslContent) { //Didn't find an XSLT.
$intermediate_results = ObjectHelper::parse_sparql_results($content);
unset($content);

$per_page = 20; //XXX: Make this configurable.
$pager_name = 0;
$total = count($intermediate_results);
$pager_page = self::hackPager($pager_name, $per_page, $total);

$results = array();
foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) {
$title = $result['title'];
$obj_path = "fedora/repository/{$result['object']}";
$thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE);
$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
'attributes' => array(
'class' => 'results-image',
),
)) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))),
);
}
if (!$results) {
drupal_set_message(t("No objects in this collection (or bad query)."));
}
else {
$first = $per_page * $pager_page;
$last = (($total - $first) > $per_page)?
($first + $per_page):
$total;
$results_range_text = t('Results @first to @last of @total', array(
'@first' => $first + 1,
'@last' => $last,
'@total' => $total,
));
//$objectList = '<h3>' . $results_range_text . '</h3>';
$objectList .= theme('pager', array(), $per_page, $pager_name);
$objectList .= theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
));
$objectList .= theme('pager', array(), $per_page, $pager_name);
}
return drupal_render(
self::assembleCollectionView(
$this->collectionObject->parseSparqlResults(
$content
)
)
);
}
else {
if (!$pageNumber) {
Expand All @@ -762,7 +796,7 @@ class CollectionClass {
try {
$proc = new XsltProcessor();
$options = array( //Could make this the return of a hook?
'collectionPid' => $collection_pid,
'collectionPid' => $pid,
'collectionTitle' => $collectionName,
'baseUrl' => $base_url,
'path' => "$base_url/$path",
Expand All @@ -774,10 +808,7 @@ class CollectionClass {
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$xsl->loadXML($xslContent);
// php xsl does not seem to work with namespaces so removing it below
// I may have just been being stupid here
// $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content);


$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);

Expand Down
4 changes: 1 addition & 3 deletions MimeClass.inc
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ class MimeClass {
* @return type
*/
public function get_mimetype($filename, $debug = FALSE) {

$file_name_and_extension = explode('.', $filename);
$ext = strtolower(array_pop($file_name_and_extension));
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));

if (!empty($this->private_mime_types[$ext])) {
if (TRUE === $debug)
Expand Down
184 changes: 184 additions & 0 deletions ObjectDetails.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

function fedora_repository_islandora_object_details_display() {
$profiles = array(
'hidden' => array(
"name" => "Hidden",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_hidden",
"description" => t("No object details page"),
),
'xslt' => array(
"name" => "XSLT",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_xslt",
"description" => t("Show a datastream with an XSLT"),
"config" => "admin/settings/fedora_repository/object_details_xslt",
),
'table' => array(
"name" => "Table",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_table",
"description" => t("Show a datastream with a table"),
"config" => "admin/settings/fedora_repository/object_details_table",
)
);
return $profiles;
}

function fedora_repository_object_details_hidden($item) {
// do nothing
return "";
}

function fedora_repository_object_details_XSLT($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');

$dsid = variable_get('islandora_object_details_xslt_datastream', 'DC');
// special case for DC+QDC for backward compatibility
if ($dsid == 'DC' || $dsid == 'QDC') {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
}
$xmlstr = $item->get_datastream_dissemination($dsid);

if (empty($xmlstr)) {
return '';
}

try {
$proc = new XsltProcessor();
} catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error');
watchdog('fedora_repository', "Error while creating XSLT processor: @e", array('@e' => $e->getMessage()), WATCHDOG_ERROR);
return;
}

$proc->setParameter('', 'baseUrl', $base_url);
$proc->setParameter('', 'path', $base_url . '/' . $path);
$input = NULL;

$xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl');
if (is_readable($xsl_file)) {
$xsl = new DOMDocument();
$xsl->load($xsl_file);
$input = new DOMDocument();
$input->loadXML(trim($xmlstr));
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
$output = $newdom->saveHTML();
return $output;
}
else {
watchdog('fedora_repository', 'The XSLT file @xslt_name is not readable.', array(
'@xslt_name' => $xsl_file,
));
}
}

function fedora_repository_object_details_table($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');

$dsid = variable_get('islandora_object_details_table_datastream', 'DC');
// special case for DC+QDC for backward compatibility
if ($dsid == 'DC' || $dsid == 'QDC') {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
}
$xmlstr = $item->get_datastream_dissemination($dsid);

if (empty($xmlstr)) {
return '';
}

$simplexml = new SimpleXMLElement($xmlstr);

$headers = array(
array(
'data' => t('Metadata'),
'colspan' => 2,
),
);
$rows = array();
foreach ($simplexml->getNamespaces(TRUE) as $ns) {
foreach ($simplexml->children($ns) as $child) {
$rows[] = array(
array(
'data' => $child->getName(),
'class' => 'dc-tag-name',
),
array(
'data' => (string)$child,
'class' => 'dc-content',
),
);
}
}

return theme('table', $headers, $rows, array('class' => 'dc-table'));
}

// configuration pages
function fedora_repository_object_details_XSLT_config() {
$form = array();
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t("XSLT display options"),
);

$form['config']['xslt'] = array(
'#type' => 'textfield',
'#title' => t("XSL transform to use"),
'#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'),
'#required' => TRUE,
);
$form['config']['dsid'] = array(
'#type' => 'textfield',
'#title' => t("Datastream to transform"),
'#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Submit"),
'#weight' => 1,
);

return $form;
}

function fedora_repository_object_details_table_config() {
$form = array();
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t("Table display options"),
);

$form['config']['dsid'] = array(
'#type' => 'textfield',
'#title' => t("Datastream to transform"),
'#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Submit"),
'#weight' => 1,
);

return $form;
}

function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) {
variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']);
variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']);
}

function fedora_repository_object_details_table_config_submit($form, &$form_state) {
variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']);
}
Loading