Browse Source

refactored some variables and templates

pull/108/head
Paul Pound 13 years ago
parent
commit
e35a2b48a3
  1. 1
      RestConnection.inc
  2. 5
      islandora-object-default-view.tpl.php
  3. 3
      islandora.module
  4. 4
      islandora_basic_image/islandora-basic-image.tpl.php
  5. 36
      islandora_basic_image/islandora_basic_image.module
  6. 125
      utils/islandora_dublin_core.inc

1
RestConnection.inc

@ -9,6 +9,7 @@ require_once 'sites/all/libraries/tuque/RepositoryConnection.php';
require_once 'sites/all/libraries/tuque/Cache.php'; require_once 'sites/all/libraries/tuque/Cache.php';
require_once 'sites/all/libraries/tuque/RepositoryException.php'; require_once 'sites/all/libraries/tuque/RepositoryException.php';
require_once 'sites/all/libraries/tuque/Repository.php'; require_once 'sites/all/libraries/tuque/Repository.php';
require_once 'sites/all/libraries/tuque/FedoraRelationships.php';
class RestConnection { class RestConnection {

5
islandora-object-default-view.tpl.php

@ -33,11 +33,10 @@
* *
*/ */
$mods = $variables['object'];
$title = $mods['title'];
//dsm($object); //dsm($object);
print('this is the default view for '. $object->label .' ' .$object->id); print('this is the default view for '. $object->label .' ' .$object->id);
//print($object['MODS']->contentasJson->'key')
?> ?>

3
islandora.module

@ -316,9 +316,6 @@ function islandora_theme() {
function islandora_datastream_as_attachment($object_id, $dsid){ function islandora_datastream_as_attachment($object_id, $dsid){
module_load_include('inc', 'islandora', 'RestConnection'); module_load_include('inc', 'islandora', 'RestConnection');
//$user = new stdClass();
//$user->name = 'fedoraAdmin';
//$user->password = 'islandora';
global $user; global $user;
try { try {
$restConnection = new RestConnection($user); $restConnection = new RestConnection($user);

4
islandora_basic_image/islandora-basic-image-view-object.tpl.php → islandora_basic_image/islandora-basic-image.tpl.php

@ -24,7 +24,9 @@
?> ?>
<?php <?php
$object = $variables['object']; $object = $variables['islandora_object'];
$image_url = $variables['islandora_image_url'];
print($object->label); print($object->label);
print('<img src = "'.$image_url.'"/>');
?> ?>

36
islandora_basic_image/islandora_basic_image.module

@ -77,13 +77,13 @@ function theme_islandora_basic_image_view_object($variables) {
*/ */
function islandora_basic_image_theme() { function islandora_basic_image_theme() {
return array( return array(
'islandora_basic_image_view_objects' => array( 'islandora_basic_image_objects' => array(
'template' => 'islandora-basic-image-view-objects', 'template' => 'islandora-basic-image-view-objects',
'variables' => array('objects' => NULL), 'variables' => array('islandor_objects' => NULL),
), ),
'islandora_basic_image_view_object' => array( 'islandora_basic_image' => array(
'template' => 'islandora-basic-image-view-object', 'template' => 'islandora-basic-image',
'variables' => array('object' => NULL), 'variables' => array('islandora_object' => NULL),
) )
); );
} }
@ -118,26 +118,28 @@ function islandora_basic_image_islandora_view_object($object, $user, $page_numbe
if (empty($combined_list)) { if (empty($combined_list)) {
return NULL;//we don't handle any of this objects cmodels return NULL;//we don't handle any of this objects cmodels
} }
$output = theme('islandora_basic_image_view_object', array('object' => $object)); $output = theme('islandora_basic_image', array('islandora_object' => $object));
return $output; return $output;
} }
function islandora_preprocess_islandora_basic_image_view_object(&$variables){ function islandora_preprocess_islandora_basic_image(&$variables){
$object = $variables['object']; $islandora_object = $variables['islandora_object'];
module_load_include('inc','islandora','utils/islandora_dublin_core');
try{ try{
$dc = $object['DC']->content; $dc = $islandora_object['DC']->content;
$dc_xml = simplexml_load_string($dc); //$dc_xml = simplexml_load_string($dc);
$dc_json = json_decode(json_encode((array)simplexml_load_string($dc)),1); $dc_object = Dublin_Core::import_from_xml_string($dc);
}catch(Exception $e){ }catch(Exception $e){
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $object->id,'%t'=>$e->getMessage())),'error'); drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id,'%t'=>$e->getMessage())),'error');
} }
$variables['dc'] = $dc_json; $variables['islandora_dublin_core'] = $dc_object;
$variables['label'] = $object->label; $variables['islandora_object_label'] = $islandora_object->label;
global $base_url; global $base_url;
$variables['image_url'] = $base_url.'islandora/object/'.$object->id.'/datastream/OBJ/view'; $variables['islandora_image_url'] = $base_url.'/islandora/object/'.$islandora_object->id.'/datastream/OBJ/view';
$variables['thumbnail_url'] = $base_url.'islandora/object/'.$object->id.'datastream/TN/view'; $variables['islandora_thumbnail_url'] = $base_url.'/islandora/object/'.$islandora_object->id.'/datastream/TN/view';
//return; $variables['islandora_medium_size_url'] = $base_url . '/islandora/object/'.$islandora_object->id.'/datastream/MEDIUM/view';
} }
?> ?>

125
utils/islandora_dublin_core.inc

@ -0,0 +1,125 @@
<?php
/**
* @file
* Implements a simple class for working with Dublin Core data and exporting it
* back to XML. Inspiration and design shamelessly stolen from the pyfedora
* project at http://pypi.python.org/pypi/pyfedora/0.1.0
*/
/**
* Dublin Core Class
*/
class Dublin_Core {
public $dc = array(
'dc:title' => array(),
'dc:creator' => array(),
'dc:subject' => array(),
'dc:description' => array(),
'dc:publisher' => array(),
'dc:contributor' => array(),
'dc:date' => array(),
'dc:type' => array(),
'dc:format' => array(),
'dc:identifier' => array(),
'dc:source' => array(),
'dc:language' => array(),
'dc:relation' => array(),
'dc:coverage' => array(),
'dc:rights' => array(),
);
public $owner;
/**
* Constructs a Dublin_Core object from a Fedora_Item object and populates
* the $dc array.
* @param <type> $item
*/
function Dublin_Core($dc_xml = NULL) {
if (!empty($dc_string)) {
$this->dc = self::import_from_xml_string($dc_xml);
}
}
/**
* Add Elements
* @param <type> $element_name
* @param <type> $value
*/
function add_element($element_name, $value) {
if (is_string($value) && is_array($this->dc[$element_name])) {
$this->dc[$element_name][] = $value;
}
}
/**
* Replace the given DC element with the values in $values
* @param string $elemnt_name
* @param array $values
*/
function set_element($element_name, $values) {
if (is_array($values)) {
$this->dc[$element_name] = $values;
}
elseif (is_string($values)) {
$this->dc[$element_name] = array($values);
}
}
/**
* Serialize this object to XML and return it.
* @param type $with_preamble
* @return type
*/
function as_xml($with_preamble = FALSE) {
$dc_xml = new DomDocument();
$oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc');
$oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
foreach ($this->dc as $dc_element => $values) {
if (is_array($values) && !empty($values)) {
foreach ($values as $value) {
$new_item = $dc_xml->createElement($dc_element, $value);
$oai_dc->appendChild($new_item);
}
}
else {
$new_item = $dc_xml->createElement($dc_element);
$oai_dc->appendChild($new_item);
}
}
$dc_xml->appendChild($oai_dc);
return $dc_xml->saveXML();
}
/**
* Create dc from dict ( does nothing )
*/
static function create_dc_from_dict() {
}
/**
* Creates a new instance of the class by parsing dc_xml
* @param string $dc_xml
* @return Dublin_Core
*/
static function import_from_xml_string($dc_xml) {
$dc_doc = new DomDocument();
if ($dc_doc->loadXML($dc_xml)) {
$oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*');
$new_dc = new Dublin_Core();
foreach ($oai_dc as $child) {
array_push($new_dc->dc[$child->nodeName], $child->nodeValue);
}
return $new_dc;
}
else {
return NULL;
}
}
}
Loading…
Cancel
Save