Browse Source

Merge branch '6.x-merged' of github.com:adam-vessey/islandora into 6.x

Conflicts:
	CollectionClass.inc
	ObjectHelper.inc
pull/126/head
Adam Vessey 13 years ago
parent
commit
1314b0992b
  1. 101
      ObjectHelper.inc
  2. 36
      fedora_repository.module

101
ObjectHelper.inc

@ -34,15 +34,35 @@ class ObjectHelper {
$connectionHelper = new ConnectionHelper(); $connectionHelper = new ConnectionHelper();
} }
private static function getBinaryLength($bin) { /**
$has_mbstring = extension_loaded('mbstring') ||@dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX); * Get the size of the indicated datastream.
$has_mb_shadow = (int) ini_get('mbstring.func_overload'); *
* Note that this only works for Inline XML and Managed datastream, as Fedora
if ($has_mbstring && ($has_mb_shadow & 2) ) { * does not know anything about external or redirect streams, other than a URI.
return mb_strlen($bin,'latin1'); * If run on an external or redirect stream, Fedora (and therefore this
} else { * function) will return the integer value '0'.
return strlen($bin); * This function requires the use of the API-M method getDatastream, and defaults
} * to returning '0' if it is not accessible.
*
* @param $pid string
* A string containing the PID of a Fedora object.
* @param $dsid string
* A string containing the datastream ID of datastream on the Fedora object
* indicated by the PID.
* @param $quiet boolean
* A boolean indicating whether SOAP errors should be displayed.
* @return integer
* An integer representing the size of the datastream, or zero if it could not be determined.
*/
static function getDatastreamSize($pid, $dsid, $quiet = FALSE) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($ds_info = $item->get_datastream($dsid, '', $quiet)) {
return $ds_info->size;
}
else {
return 0;
}
} }
/** /**
@ -133,21 +153,23 @@ class ObjectHelper {
'query' => $query_options, 'query' => $query_options,
)); ));
} }
$ch = curl_init(); $ch = curl_init($url);
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $curl_opts = array(
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors CURLOPT_SSL_VERIFYPEER => FALSE,
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects CURLOPT_SSL_VERIFYHOST => FALSE,
//curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s CURLOPT_FAILONERROR => TRUE, // Fail on errors
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); CURLOPT_FOLLOWLOCATION => TRUE, // allow redirects
curl_setopt($ch, CURLOPT_URL, $url); //CURLOPT_TIMEOUT => 15, // times out after 15s
curl_setopt($ch, CURLOPT_USERPWD, "$fedoraUser:$fedoraPass"); CURLOPT_USERAGENT => $user_agent,
// There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error. CURLOPT_URL => $url,
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); CURLOPT_USERPWD => "$fedoraUser:$fedoraPass",
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable // There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error.
//CURLOPT_HTTPAUTH => CURLAUTH_ANY,
curl_setopt($ch, CURLOPT_URL, $url); CURLOPT_RETURNTRANSFER => TRUE, // return into a variable; need to at first, so additional headers can be set later.
);
curl_setopt_array($ch, $curl_opts);
if ($filePath !== FALSE) { if ($filePath !== FALSE) {
$fp = fopen($filePath, 'w'); $fp = fopen($filePath, 'w');
@ -158,9 +180,9 @@ class ObjectHelper {
} }
else { else {
curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$curl_out = curl_exec($ch); $curl_stat = curl_exec($ch);
if ($curl_out !== FALSE) { if ($curl_stat !== FALSE) {
$info = curl_getinfo($ch); $info = curl_getinfo($ch);
//Set what headers we can... //Set what headers we can...
@ -212,24 +234,31 @@ class ObjectHelper {
elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS
//Have the webserver mediate the transfer (download and restream) //Have the webserver mediate the transfer (download and restream)
curl_setopt($ch, CURLOPT_NOBODY, FALSE); if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) {
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); //CURLOPT_NOBODY sets it to 'HEAD' header("Content-Length: $contentSize");
$toReturn = curl_exec($ch);
if (($contentSize = self::getBinaryLength($toReturn)) > 0) {
header("Content-Length: $contentSize");
} }
//Done applying headers...
echo $toReturn; $opts = array(
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPGET => TRUE, //CURLOPT_NOBODY sets it to 'HEAD'
CURLOPT_RETURNTRANSFER => FALSE, //Want to output as efficiently as possible now...
);
$curl_stat = curl_exec($ch);
if (!$curl_stat) {
watchdog('fedora_repository', 'Error in ObjectHelper->makeObject() for @pid/@dsid. See link for attempted URL.', array(
'@pid' => $pid,
'@dsid' => $dsID,
), WATCHDOG_WARNING, $url);
}
} }
else { else { //Try to redirect directly to Fedora.
header('HTTP/1.1 307 Moved Temporarily'); header('HTTP/1.1 307 Moved Temporarily');
header('Location: ' . $url); header('Location: ' . $url);
} }
} }
else { else {
watchdog('fedora_repository', 'Curl error while trying to get datastream %dsid from Fedora object %dsid. Curl info: !info', array( watchdog('fedora_repository', 'Curl error while trying to get datastream %dsid from Fedora object %pid. Curl info: !info', array(
'%pid' => $pid, '%pid' => $pid,
'%dsid' => $dsID, '%dsid' => $dsID,
'!info' => print_r(curl_getinfo($ch), TRUE), '!info' => print_r(curl_getinfo($ch), TRUE),

36
fedora_repository.module

@ -660,6 +660,42 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $
return $form; return $form;
} }
function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) {
$form = array(
'#action' => url("fedora/repository/object_download/$pid/$dsid/$label"),
'submit' => array(
'#type' => 'submit',
'#value' => t('Download'),
),
);
if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$item = new Fedora_Item($pid);
$versions = $item->get_datastream_history($dsid);
$version_array = array();
if (is_array($versions)) {
foreach ($versions as $version) {
$version_array[] = $version->createDate;
}
}
else {
$version_array[] = $versions->createDate;
}
if (count($version_array) > 1) {
$form['#attributes'] = array(
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;'
);
$form['version'] = array(
'#type' => 'select',
'#options' => array_combine($version_array, $version_array),
);
}
}
return $form;
}
/** /**
* fedora repository replace stream * fedora repository replace stream
* @param type $pid * @param type $pid

Loading…
Cancel
Save