Browse Source

updated object details page

pull/127/head
Jason MacWilliams 13 years ago
parent
commit
8ed4573edd
  1. 109
      ObjectDetails.inc
  2. 28
      formClass.inc
  3. 33
      object_details_xslts/convertQDC.xsl
  4. 232
      object_details_xslts/mods2html.xsl
  5. 3
      plugins/FedoraObjectDetailedContent.inc

109
ObjectDetails.inc

@ -1,5 +1,17 @@
<?php
/**
* @file ObjectDetails.inc
* The functions required to define and respond to all the default object
* details display modes.
*/
/**
* Islandora core object details display modes. These are the default display
* modes that are always available.
* @return A list of display modes that can be used to render the object details
* page.
*/
function fedora_repository_islandora_object_details_display() {
$profiles = array(
'hidden' => array(
@ -29,11 +41,25 @@ function fedora_repository_islandora_object_details_display() {
return $profiles;
}
/**
* The renderer for the "hidden" display mode. In this mode, no data is
* displayed. This is supplied so you can disable the object details metadata
* display without disabling the tab entirely.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_hidden($item) {
// do nothing
return "";
}
/**
* The renderer for the "xslt" display mode. In this mode, an xslt is applied
* to the selected datastream to produce a user defined look and feel to the
* output data.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_XSLT($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
@ -47,13 +73,13 @@ function fedora_repository_object_details_XSLT($item) {
$xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr)) {
return '';
return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.',
array('@dsid' => $dsid, '@pid' => $item->pid));
}
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;
}
@ -61,25 +87,27 @@ function fedora_repository_object_details_XSLT($item) {
$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();
$xsl = new DomDocument();
try {
$xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'));
$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,
));
} catch (Exception $e) {
watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR);
}
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
$output = $newdom->saveHTML();
return $output;
}
/**
* The renderer for the "table" display mode. In this mode, the requested
* datastream is rendered using a simple table with keys(tags) on the left and
* values on the right.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_table($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
@ -93,7 +121,8 @@ function fedora_repository_object_details_table($item) {
$xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr)) {
return '';
return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.',
array('@dsid' => $dsid, '@pid' => $item->pid));
}
$simplexml = new SimpleXMLElement($xmlstr);
@ -123,7 +152,11 @@ function fedora_repository_object_details_table($item) {
return theme('table', $headers, $rows, array('class' => 'dc-table'));
}
// configuration pages
/**
* Configuration page for the xslt display mode. This mode requires two
* parameters: the datastream to render, and the xslt to apply to it.
* @return The configuration page.
*/
function fedora_repository_object_details_XSLT_config() {
$form = array();
$form['config'] = array(
@ -131,10 +164,22 @@ function fedora_repository_object_details_XSLT_config() {
'#title' => t("XSLT display options"),
);
// locate the xslts available
$xslt_folder = "object_details_xslts/";
$folder = drupal_get_path("module", "fedora_repository") ."/". $xslt_folder;
// retrieve the filenames from the system
$xslts = file_scan_directory($folder, ".xsl");
$options = array();
foreach ($xslts as $xsl) {
$options[$xslt_folder . $xsl->basename] = $xsl->basename;
}
$form['config']['xslt'] = array(
'#type' => 'textfield',
'#type' => 'select',
'#title' => t("XSL transform to use"),
'#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'),
'#options' => $options,
'#key_type' => 'associative',
'#required' => TRUE,
);
$form['config']['dsid'] = array(
@ -151,7 +196,21 @@ function fedora_repository_object_details_XSLT_config() {
return $form;
}
/**
* Custom submit handler for the xslt configuration page.
* @param form
* @pararm form_state The user supplied values for the 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']);
}
/**
* Configuration page for the table display mode. This mode requires only one
* parameter: the datastream to render.
* @return The configuration page.
*/
function fedora_repository_object_details_table_config() {
$form = array();
$form['config'] = array(
@ -174,11 +233,11 @@ function fedora_repository_object_details_table_config() {
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']);
}
/**
* Custom submit handler for the table configuration page.
* @param form
* @pararm form_state The user supplied values for the form.
*/
function fedora_repository_object_details_table_config_submit($form, &$form_state) {
variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']);
}

28
formClass.inc

@ -317,11 +317,19 @@ class formClass {
$profiles = module_invoke_all("islandora_object_details_display");
$display_options = array();
foreach ($profiles as $machine_name => $profile) {
$display_options[$machine_name] = $profile['name'];
$config_path = $profile['config'];
if (isset($config_path) && $config_path != ""){
$display_options[$machine_name] .= " (". l("config", $config_path, array()) .")";
// suppress php warnings from empty lists
if ($profiles) {
foreach ($profiles as $machine_name => $profile) {
// make sure the name exists (the bare minimum)
if (array_key_exists('name', $profile)) {
$display_options[$machine_name] = $profile['name'];
if (array_key_exists('config', $profile)) {
$config_path = $profile['config'];
if (isset($config_path) && $config_path != "") {
$display_options[$machine_name] .= " (". l("config", $config_path, array()) .")";
}
}
}
}
}
$form['tabs']['islandora_object_details_display_table'] = array(
@ -362,10 +370,10 @@ class formClass {
'#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'),
);
$form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array(
'#type' => 'checkbox',
'#title' => t('Allow imagecache_external use for thumbnails in collection view'),
'#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE),
$form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array(
'#type' => 'checkbox',
'#title' => t('Allow imagecache_external use for thumbnails in collection view'),
'#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE),
'#description' => t('If enabled, the default collection list view (or ' .
'anywhere the function "@function" is used) will try to use ' .
'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' .
@ -374,7 +382,7 @@ class formClass {
'@function' => '_fedora_repository_render_image()',
'@preset' => 'fedora_repository_collection_thumbnail',
'@xsl' => 'sparql_to_html.xsl',
)),
)),
);
$form['advanced']['fedora_collection_display_list'] = array(

33
object_details_xslts/convertQDC.xsl

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="BASEURL">
<xsl:value-of select="$baseUrl"/>
</xsl:variable>
<xsl:variable name="PATH">
<xsl:value-of select="$path"/>
</xsl:variable>
<xsl:template match="/">
<div><table cellspacing="3" cellpadding="3"><tbody>
<tr><th colspan="3"><h3>MetaData</h3></th></tr>
<xsl:for-each select="/*/*">
<xsl:variable name="FULLFIELD" select="name()"/>
<xsl:variable name="FIELD" select="local-name()"/>
<xsl:variable name="DATA" select="text()"/>
<xsl:if test="$DATA != ' '">
<tr><td><strong><xsl:value-of select="local-name()"/></strong></td><td><xsl:value-of select="text()"/>
<xsl:for-each select="*">
<div>
<xsl:value-of select="local-name()"/> = <xsl:value-of select="text()"/>
</div>
</xsl:for-each>
</td></tr>
</xsl:if>
</xsl:for-each>
</tbody></table></div>
</xsl:template>
</xsl:stylesheet>

232
object_details_xslts/mods2html.xsl

@ -0,0 +1,232 @@
<xsl:stylesheet xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="mods" version="1.0">
<xsl:output indent="yes" method="html"/>
<xsl:variable name="dictionary" select="document('http://www.loc.gov/standards/mods/modsDictionary.xml')/dictionary"/>
<xsl:template match="/">
<html>
<head>
<style type="text/css">
.modsLabelTop {
}
.modsLabelLevel2 {
padding-left: 10px;
}
.modsLabelLevel3 {
padding-left: 20px;
}
.modsLabelLevel4 {
padding-left: 30px;
}
.modsValueTop {
}
.modsValueLevel2 {
}
.modsValueLevel3 {
}
</style>
</head>
<body>
<xsl:choose>
<xsl:when test="mods:modsCollection">
<xsl:apply-templates select="mods:modsCollection"/>
</xsl:when>
<xsl:when test="mods:mods">
<xsl:apply-templates select="mods:mods"/>
</xsl:when>
</xsl:choose>
</body>
</html>
</xsl:template>
<xsl:template match="mods:modsCollection">
<xsl:apply-templates select="mods:mods"/>
</xsl:template>
<xsl:template match="mods:mods">
<table class="modsContainer">
<xsl:apply-templates/>
</table>
<!--hr/-->
</xsl:template>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelTop">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>:
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level2"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelTop">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueTop">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="formatValue">
<xsl:choose>
<xsl:when test="@type='uri'">
<a href="{text()}" class="modsLink">
<xsl:value-of select="text()"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level2">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelLevel2">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level3"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelLevel2">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel2">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level3">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelLevel3">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level4"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelLevel3">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel3">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level4">
<tr><td>
<span class="modsLabelLevel4">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel4">
<xsl:value-of select="text()"/>
</span>
</td></tr>
</xsl:template>
<xsl:template name="longName">
<xsl:param name="name"/>
<xsl:choose>
<xsl:when test="$dictionary/entry[@key=$name]">
<xsl:value-of select="$dictionary/entry[@key=$name]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="attr">
<xsl:for-each select="@type|@point">:
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="."/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="@authority or @edition">
<xsl:for-each select="@authority">(<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="."/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="@edition">
Edition <xsl:value-of select="@edition"/>
</xsl:if>)
</xsl:if>
<xsl:variable name="attrStr">
<xsl:for-each select="@*[local-name()!='edition' and local-name()!='type' and local-name()!='authority' and local-name()!='point']">
<xsl:value-of select="local-name()"/>="<xsl:value-of select="."/>",
</xsl:for-each>
</xsl:variable>
<xsl:variable name="nattrStr" select="normalize-space($attrStr)"/>
<xsl:if test="string-length($nattrStr)">
(<xsl:value-of select="substring($nattrStr,1,string-length($nattrStr)-1)"/>)
</xsl:if>
</xsl:template>
</xsl:stylesheet>

3
plugins/FedoraObjectDetailedContent.inc

@ -65,7 +65,8 @@ class FedoraObjectDetailedContent {
$dc_html = $details_function($this->item);
}
else {
// problem
// problem - display profile not found
watchdog('fedora_repository', "Error - could not find object details display function @function", array('@function' => $details_function), WATCHDOG_WARNING);
}
}

Loading…
Cancel
Save