Browse Source

fixed conflict

pull/164/head
William Panting 12 years ago
parent
commit
af6a9f4b25
  1. 80
      MimeClass.inc
  2. 95
      api/fedora_utils.inc
  3. 112
      fedora_repository.module

80
MimeClass.inc

@ -21,10 +21,11 @@
* http://api.drupal.org/api/function/file_default_mimetype_mapping/7 * http://api.drupal.org/api/function/file_default_mimetype_mapping/7
* *
*/ */
class MimeClass { class MimeClass {
private $private_mime_types = array( private $private_mime_types = array(
/** /*
* This is a shortlist of mimetypes which should catch most * This is a shortlist of mimetypes which should catch most
* mimetype<-->extension lookups in the context of Islandora collections. * mimetype<-->extension lookups in the context of Islandora collections.
* *
@ -37,16 +38,16 @@ class MimeClass {
* project, as lookups against this list will be quicker and less * project, as lookups against this list will be quicker and less
* resource intensive than other methods. * resource intensive than other methods.
* *
* Lookups are first checked against this short list. If no results are found, * Lookups are first checked against this short list.
* then the lookup function may move on to check other sources, namely the * If no results are found, then the lookup function may move
* system's mime.types file. * on to check other sources, namely the system's mime.types file.
* *
* In most cases though, this short list should suffice. * In most cases though, this short list should suffice.
* *
* If modifying this list, please note that for promiscuous mimetypes * If modifying this list, please note that for promiscuous mimetypes
* (those which map to multiple extensions, such as text/plain) * (those which map to multiple extensions, such as text/plain)
* The function get_extension will always return the *LAST* extension in this list, * The function get_extension will always return the *LAST* extension
* so you should put your preferred extension *LAST*. * in this list, so you should put your preferred extension *LAST*.
* *
* e.g... * e.g...
* "jpeg" => "image/jpeg", * "jpeg" => "image/jpeg",
@ -89,7 +90,7 @@ class MimeClass {
'ksp' => 'application/x-kspread', 'ksp' => 'application/x-kspread',
'kwt' => 'application/x-kword', 'kwt' => 'application/x-kword',
'kwd' => 'application/x-kword', 'kwd' => 'application/x-kword',
// ms office 97: // MS office 97:
'doc' => 'application/msword', 'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint', 'ppt' => 'application/vnd.ms-powerpoint',
@ -113,9 +114,9 @@ class MimeClass {
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// wordperfect (who cares?): // Wordperfect (who cares?):
'wpd' => 'application/wordperfect', 'wpd' => 'application/wordperfect',
// common and generic containers: // Common and generic containers:
'pdf' => 'application/pdf', 'pdf' => 'application/pdf',
'eps' => 'application/postscript', 'eps' => 'application/postscript',
'ps' => 'application/postscript', 'ps' => 'application/postscript',
@ -185,7 +186,8 @@ class MimeClass {
"ogg" => "audio/ogg", "ogg" => "audio/ogg",
"flac" => "audio/x-flac", "flac" => "audio/x-flac",
"wav" => "audio/vnd.wave", "wav" => "audio/vnd.wave",
// compressed formats: (note: http://svn.cleancode.org/svn/email/trunk/mime.types) /* Compressed formats:
(note: http://svn.cleancode.org/svn/email/trunk/mime.types).*/
"tgz" => "application/x-gzip", "tgz" => "application/x-gzip",
"gz" => "application/x-gzip", "gz" => "application/x-gzip",
"tar" => "application/x-tar", "tar" => "application/x-tar",
@ -193,7 +195,9 @@ class MimeClass {
"zip" => "application/x-zip", "zip" => "application/x-zip",
// others: // others:
'bin' => 'application/octet-stream', 'bin' => 'application/octet-stream',
'json' => 'application/json',
); );
private $private_file_extensions; private $private_file_extensions;
private $system_types; private $system_types;
private $system_exts; private $system_exts;
@ -204,10 +208,10 @@ class MimeClass {
*/ */
public function __construct() { public function __construct() {
// populate the reverse shortlist: // Populate the reverse shortlist:
$this->private_file_extensions = array_flip($this->private_mime_types); $this->private_file_extensions = array_flip($this->private_mime_types);
// pick up a local mime.types file if it is available // Pick up a local mime.types file if it is available.
if (is_readable('mime.types')) { if (is_readable('mime.types')) {
$this->etc_mime_types = 'mime.types'; $this->etc_mime_types = 'mime.types';
} }
@ -227,40 +231,47 @@ class MimeClass {
/** /**
* function: get_mimetype * function: get_mimetype
* description: returns a mimetype associated with the file extension of $filename * description: returns a mimetype associated with the
* file extension of $filename
* *
* @param type $filename * @param type $filename
* @param type $debug * @param type $debug
* @return type * @return string
* mimetype associated with the file extension of $filename
*/ */
public function get_mimetype($filename, $debug = FALSE) { public function get_mimetype($filename, $debug = FALSE) {
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); $ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
if (!empty($this->private_mime_types[$ext])) { if (!empty($this->private_mime_types[$ext])) {
if (TRUE === $debug) if (TRUE === $debug) {
return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array'); return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array');
}
return $this->private_mime_types[$ext]; return $this->private_mime_types[$ext];
} }
if (function_exists('file_get_mimetype')) { if (function_exists('file_get_mimetype')) {
$drupal_mimetype = file_get_mimetype($filename); $drupal_mimetype = file_get_mimetype($filename);
if ('application/octet-stream' != $drupal_mimetype) { if ('application/octet-stream' != $drupal_mimetype) {
if (TRUE == $debug) if (TRUE == $debug) {
return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype'); return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype');
}
return $drupal_mimetype; return $drupal_mimetype;
} }
} }
if (!isset($this->system_types)) if (!isset($this->system_types)) {
$this->system_types = $this->system_extension_mime_types(); $this->system_types = $this->system_extension_mime_types();
}
if (isset($this->system_types[$ext])) { if (isset($this->system_types[$ext])) {
if (TRUE == $debug) if (TRUE == $debug) {
return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types'); return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types');
}
return $this->system_types[$ext]; return $this->system_types[$ext];
} }
if (TRUE === $debug) if (TRUE === $debug) {
return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort'); return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort');
}
return 'application/octet-stream'; return 'application/octet-stream';
} }
@ -275,21 +286,25 @@ class MimeClass {
public function get_extension($mime_type, $debug = FALSE) { public function get_extension($mime_type, $debug = FALSE) {
if (!empty($this->private_file_extensions[$mime_type])) { if (!empty($this->private_file_extensions[$mime_type])) {
if (TRUE == $debug) if (TRUE == $debug) {
return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array'); return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array');
}
return $this->private_file_extensions[$mime_type]; return $this->private_file_extensions[$mime_type];
} }
if (!isset($this->system_exts)) if (!isset($this->system_exts)) {
$this->system_exts = $this->system_mime_type_extensions(); $this->system_exts = $this->system_mime_type_extensions();
}
if (isset($this->system_exts[$mime_type])) { if (isset($this->system_exts[$mime_type])) {
if (TRUE == $debug) if (TRUE == $debug) {
return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types'); return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types');
}
return $this->system_exts[$mime_type]; return $this->system_exts[$mime_type];
} }
if (TRUE == $debug) if (TRUE == $debug) {
return array('extension' => 'bin', 'method' => 'last_resort'); return array('extension' => 'bin', 'method' => 'last_resort');
}
return 'bin'; return 'bin';
} }
@ -306,15 +321,18 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r'); $file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) { while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line)); $line = trim(preg_replace('/#.*/', '', $line));
if (!$line) if (!$line) {
continue; continue;
}
$parts = preg_split('/\s+/', $line); $parts = preg_split('/\s+/', $line);
if (count($parts) == 1) if (count($parts) == 1) {
continue; continue;
}
// A single part means a mimetype without extensions, which we ignore. // A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts); $type = array_shift($parts);
if (!isset($out[$type])) if (!isset($out[$type])) {
$out[$type] = array_shift($parts); $out[$type] = array_shift($parts);
}
// We take the first ext from the line if many are present. // We take the first ext from the line if many are present.
} }
fclose($file); fclose($file);
@ -335,20 +353,22 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r'); $file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) { while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line)); $line = trim(preg_replace('/#.*/', '', $line));
if (!$line) if (!$line) {
continue; continue;
}
$parts = preg_split('/\s+/', $line); $parts = preg_split('/\s+/', $line);
if (count($parts) == 1) if (count($parts) == 1) {
continue; continue;
}
// A single part means a mimetype without extensions, which we ignore. // A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts); $type = array_shift($parts);
foreach ($parts as $part) foreach ($parts as $part) {
$out[$part] = $type; $out[$part] = $type;
} }
}
fclose($file); fclose($file);
} }
return $out; return $out;
} }
} }

95
api/fedora_utils.inc

@ -1,23 +1,23 @@
<?php <?php
/** /**
* @file * @file
* Base utilities used by the Islandora fedora module. * Base utilities used by the Islandora fedora module.
*/ */
if (!function_exists('str_getcsv')) { if (!function_exists('str_getcsv')) {
/** /**
* Functions that emulate php5.3 functionality for backwards compatiablity * Functions that emulate php5.3 functionality for backwards compatiablity
*
* @param type $input * @param type $input
* @param type $delimiter * @param type $delimiter
* @param type $enclosure * @param type $enclosure
* @param type $escape * @param type $escape
* @param type $eol * @param type $eol
*
* @return type * @return type
*/ */
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=NULL, $eol=NULL) { function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = NULL, $eol = NULL) {
$temp = fopen("php://memory", "rw"); $temp = fopen("php://memory", "rw");
fwrite($temp, $input); fwrite($temp, $input);
fseek($temp, 0); fseek($temp, 0);
@ -50,7 +50,7 @@ if (!function_exists('str_getcsv')) {
* @param $post * @param $post
* Whether the curl_exec is done as a "get" or a "post" * Whether the curl_exec is done as a "get" or a "post"
* *
* @return * @return mixed
* TRUE, FALSE, NULL, or the data returned from accessing the URL * TRUE, FALSE, NULL, or the data returned from accessing the URL
*/ */
function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) { function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
@ -59,7 +59,6 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
} }
/** /**
*
* Utility method to get data from a url location using curl_exec * Utility method to get data from a url location using curl_exec
* *
* This method takes a URL and three associated parameters and initializes the * This method takes a URL and three associated parameters and initializes the
@ -70,7 +69,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* Various defaults are used for the parameters required by curl_exec including * Various defaults are used for the parameters required by curl_exec including
* the user agent and timeout. These are hard-coded. * the user agent and timeout. These are hard-coded.
* *
* @param $url * @param string $url
* URL to be accessed by the function * URL to be accessed by the function
* @param $return_to_variable * @param $return_to_variable
* Indicates whether the resource accessed by the curl call (HTML page, * Indicates whether the resource accessed by the curl call (HTML page,
@ -81,7 +80,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* @param $post * @param $post
* Whether the curl_exec is done as a "get" or a "post" * Whether the curl_exec is done as a "get" or a "post"
* *
* @return * @return mixed
* an array that consists of three value or NULL if curl is not suported: * an array that consists of three value or NULL if curl is not suported:
* - element 0: * - element 0:
* The value returned from the curl_exec function call. * The value returned from the curl_exec function call.
@ -112,11 +111,15 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)"; $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors // Fail on errors.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s // Allow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// Times out after 90s.
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable // Return into a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable);
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass"); curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
@ -141,7 +144,8 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
/** /**
* Fedora available * Fedora available
* @return type *
* @return mixed
*/ */
function fedora_available() { function fedora_available() {
@ -151,7 +155,8 @@ function fedora_available() {
/** /**
* Resource index search available * Resource index search available
* @return type *
* @return mixed
*/ */
function risearch_available() { function risearch_available() {
@ -161,7 +166,9 @@ function risearch_available() {
/** /**
* Returns a UTF-8-encoded transcripiton of the string given in $in_str. * Returns a UTF-8-encoded transcripiton of the string given in $in_str.
*
* @param string $in_str * @param string $in_str
*
* @return string A UTF-8 encoded string. * @return string A UTF-8 encoded string.
*/ */
function fix_encoding($in_str) { function fix_encoding($in_str) {
@ -176,7 +183,9 @@ function fix_encoding($in_str) {
/** /**
* valid pid ?? * valid pid ??
*
* @param type $pid * @param type $pid
*
* @return boolean * @return boolean
*/ */
function valid_pid($pid) { function valid_pid($pid) {
@ -190,7 +199,9 @@ function valid_pid($pid) {
/** /**
* Valid Dsid ?? * Valid Dsid ??
*
* @param type $dsid * @param type $dsid
*
* @return boolean * @return boolean
*/ */
function valid_dsid($dsid) { function valid_dsid($dsid) {
@ -204,7 +215,9 @@ function valid_dsid($dsid) {
/** /**
* fixDsid ?? * fixDsid ??
*
* @param type $dsid * @param type $dsid
*
* @return string * @return string
*/ */
function fix_dsid($dsid) { function fix_dsid($dsid) {
@ -214,14 +227,17 @@ function fix_dsid($dsid) {
$replace = ''; $replace = '';
$new_dsid = preg_replace($find, $replace, $new_dsid); $new_dsid = preg_replace($find, $replace, $new_dsid);
if (strlen($new_dsid) > 63) if (strlen($new_dsid) > 63) {
$new_dsid = substr($new_dsid, -63); $new_dsid = substr($new_dsid, -63);
}
if (preg_match('/^[^a-zA-Z]/', $dsid)) if (preg_match('/^[^a-zA-Z]/', $dsid)) {
$new_dsid = 'x' . $new_dsid; $new_dsid = 'x' . $new_dsid;
}
if (strlen($new_dsid) == 0) if (strlen($new_dsid) == 0) {
$new_dsid = 'item' . rand(1, 100); $new_dsid = 'item' . rand(1, 100);
}
return $new_dsid; return $new_dsid;
} }
@ -229,9 +245,8 @@ function fix_dsid($dsid) {
/** /**
* Function: get_collections_as_option_array * Function: get_collections_as_option_array
* *
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array * @return array
* Returns an associative array of all collection objects in Fedora instance
*/ */
function get_collections_as_option_array() { function get_collections_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -254,7 +269,7 @@ function get_collections_as_option_array() {
'stream' => 'on', 'stream' => 'on',
'query' => $query, 'query' => $query,
); );
//The url function will take care of URL encoding... // The url function will take care of URL encoding.
$content = do_curl(url($url, array('query' => $options))); $content = do_curl(url($url, array('query' => $options)));
$list = explode("\n", $content); $list = explode("\n", $content);
@ -264,7 +279,8 @@ function get_collections_as_option_array() {
$trimmed_names[] = trim($namespace); $trimmed_names[] = trim($namespace);
} }
$options = array(); $options = array();
foreach ($list as $item) { //removes blanks // Removes blanks.
foreach ($list as $item) {
if ($item) { if ($item) {
$parts = explode(',', $item); $parts = explode(',', $item);
$namespace = explode(':', $parts[0]); $namespace = explode(':', $parts[0]);
@ -283,9 +299,8 @@ function get_collections_as_option_array() {
/** /**
* Function: get_content_models_as_option_array * Function: get_content_models_as_option_array
* *
* Description: Returns an associative array of all available content models in Fedora instance
*
* @return array * @return array
* associative array of all available content models in Fedora instance
*/ */
function get_content_models_as_option_array() { function get_content_models_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -311,12 +326,12 @@ function get_content_models_as_option_array() {
$list = explode("\n", $content); $list = explode("\n", $content);
array_shift($list); array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list); $list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks // Removes blanks.
foreach ($list as $item) {
if ($item) { if ($item) {
$parts = explode(',', $item); $parts = explode(',', $item);
$nameparts = explode(':', $parts[0]); $nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed)) { if (!$restricted || in_array($nameparts[0], $allowed)) {
if (!preg_match('/fedora-system/', $nameparts[0])) { if (!preg_match('/fedora-system/', $nameparts[0])) {
$options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0]; $options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0];
} }
@ -326,3 +341,33 @@ function get_content_models_as_option_array() {
return $options; return $options;
} }
/**
* This function will retrieve the collections that the given PID belongs to.
*
* @param string $PID
* The PID to find the parents of.
*
* @return array
* $object_PIDs the list of PIDs of the collections that the
* indicated object is a member of.
*/
function get_parent_collections_from_pid($PID) {
$query_string = 'select $parent from <#ri>
where ($object <fedora-rels-ext:isMemberOf> $parent
or $object <fedora-rels-ext:isMemberOfCollection> $parent)
and $object <dc:identifier> \'' . $PID . '\'
order by $object';
$query_string = htmlentities(urlencode($query_string));
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= '?type=tuples&flush=true&format=csv&limit=13000&lang=itql&stream=on&query=' . $query_string;
$content = do_curl($url, TRUE);
$results = explode("\n", $content);
$object_PIDs = preg_replace('/^info:fedora\/|"parent"| /', '', $results);
$object_PIDs = array_values(array_filter($object_PIDs));
return $object_PIDs;
}

112
fedora_repository.module

@ -40,8 +40,10 @@ function fedora_repository_help($path, $arg) {
/** /**
* fedora repository purge object * fedora repository purge object
*
* @param type $pid * @param type $pid
* @param type $name * @param type $name
*
* @return type * @return type
*/ */
function fedora_repository_purge_object($pid = NULL, $name = NULL) { function fedora_repository_purge_object($pid = NULL, $name = NULL) {
@ -64,9 +66,11 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) {
/** /**
* fedora repository ingest object * fedora repository ingest object
*
* @param type $collection_pid * @param type $collection_pid
* @param type $collection_label * @param type $collection_label
* @param type $content_model * @param type $content_model
*
* @return type * @return type
*/ */
function fedora_repository_ingest_object($collection_pid=NULL, $collection_label = NULL, $content_model = NULL) { function fedora_repository_ingest_object($collection_pid=NULL, $collection_label = NULL, $content_model = NULL) {
@ -266,11 +270,15 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio
/** /**
* fedora repository purge object form * fedora repository purge object form
*
* @global type $base_url * @global type $base_url
*
* @param type $form_state * @param type $form_state
* @param type $pid * @param type $pid
* @param type $referrer * @param type $referrer
* @return type *
* @return mixed
* NULL or the form array.
*/ */
function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) { function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) {
global $base_url; global $base_url;
@ -282,7 +290,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
} }
$form['pid'] = array( $form['pid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => "$pid" '#value' => "$pid",
); );
if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) { if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) {
$form['referrer'] = array( $form['referrer'] = array(
@ -291,27 +299,26 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
); );
} }
if (!isset($form_state['storage']['confirm'])) { if (!isset($form_state['storage']['confirm'])) {
// do your normal $form definition here // Do your normal $form definition here.
$form['submit'] = array( $form['submit'] = array(
'#type' => 'image_button', '#type' => 'image_button',
'#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png', '#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png',
'#value' => t('Purge'), '#value' => t('Purge'),
'#suffix' => 'Purge this object', '#suffix' => 'Purge this object',
); );
if (!empty($collectionPid)) {
$collectionPid = $_SESSION['fedora_collection'];
}
//$form['#rebuild'] = $false;
return $form; return $form;
} }
else { else {
// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form /* ALSO do $form definition here. Your final submit handler
* (after user clicks Yes, I Confirm)
* will only see $form_state info defined here.
* Form you create here passed as param1 to confirm_form*/
return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); //Had better luck leaving off last param 'name' // Had better luck leaving off last param 'name'.
return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel');
} }
return $form; return $form;
} }
@ -487,14 +494,22 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL)
return $output; return $output;
} }
/**
* Validates the purge object form.
*
* @param array $form
* The form to validate.
* @param array $form_state
* The state of the form to validate
*/
function fedora_repository_purge_object_form_validate($form, &$form_state) { function fedora_repository_purge_object_form_validate($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_collection'); module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$objectHelper = new ObjectHelper(); $object_helper = new ObjectHelper();
$contentModels = $objectHelper->get_content_models_list($pid); $content_models = $object_helper->get_content_models_list($pid);
foreach ($contentModels as $contentModel) { foreach ($content_models as $content_model) {
if ($contentModel->pid == 'islandora:collectionCModel') { if ($content_model->pid == 'islandora:collectionCModel') {
$member_pids = get_related_items_as_array($pid, 'isMemberOfCollection'); $member_pids = get_related_items_as_array($pid, 'isMemberOfCollection');
if (is_array($member_pids) && ! empty($member_pids)) { if (is_array($member_pids) && ! empty($member_pids)) {
form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself.")); form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself."));
@ -506,27 +521,37 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) {
/** /**
* fedora repository purge object form submit * fedora repository purge object form submit
*
* @param type $form * @param type $form
* The submited form.
* @param type $form_state * @param type $form_state
* @return type * The state of the submitted form.
*/ */
function fedora_repository_purge_object_form_submit($form, &$form_state) { function fedora_repository_purge_object_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$parents = get_parent_collections_from_pid($pid);
if (!isset($form_state['storage']['confirm'])) { if (!isset($form_state['storage']['confirm'])) {
$form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form /* This will cause the form to be rebuilt,
$form_state['rebuild'] = TRUE; // along with this * entering the confirm part of the form.*/
$form_state['storage']['confirm'] = TRUE;
// Along with this.
$form_state['rebuild'] = TRUE;
} }
else { else {
// this is where you do your processing after they have pressed the confirm button /* This is where you do your processing after
* they have pressed the confirm button.*/
$params = array( $params = array(
"pid" => $pid, "pid" => $pid,
"logMessage" => "Purged", "logMessage" => "Purged",
"force" => "" "force" => "",
); );
try { try {
$soapHelper = new ConnectionHelper(); $soap_helper = new ConnectionHelper();
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); $client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
$object = $client->__soapCall('purgeObject', array($params)); $object = $client->__soapCall('purgeObject', array($params));
unset($form_state['storage']['confirm']); unset($form_state['storage']['confirm']);
} catch (exception $e) { } catch (exception $e) {
@ -538,39 +563,33 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
} }
return; return;
} }
if (!empty($form_state['values']['referrer'])) {
$form_state['redirect'] = $form_state['values']['referrer'];
}
elseif (empty($collectionPid) && !empty($_SESSION['fedora_collection']) && $_SESSION['fedora_collection'] != $pid) {
$collectionPid = $_SESSION['fedora_collection'];
$form_state['redirect'] = "fedora/repository/$collectionPid/"; // Set the form's redirect to its first identifiable parent collection.
} $form_state['redirect'] = "fedora/repository/$parents[0]/";
else {
$form_state['redirect'] = 'fedora/repository/';
}
} }
} }
/** /**
* fedora repository purge stream form * fedora repository purge stream form
*
* @param type $form_state * @param type $form_state
* @param type $pid * @param type $pid
* @param type $dsId * @param type $dsId
*
* @return type * @return type
*/ */
function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) { function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) {
$form['pid'] = array( $form['pid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => "$pid" '#value' => "$pid",
); );
$form['dsid'] = array( $form['dsid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => "$dsId" '#value' => "$dsId",
); );
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Purge') '#value' => t('Purge'),
); );
return $form; return $form;
@ -578,7 +597,9 @@ function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) {
/** /**
* fedora repository purge stream form submit * fedora repository purge stream form submit
*
* @global type $base_url * @global type $base_url
*
* @param type $form * @param type $form
* @param array $form_state * @param array $form_state
*/ */
@ -596,6 +617,13 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) {
$form_state['redirect'] = "fedora/repository/$pid"; $form_state['redirect'] = "fedora/repository/$pid";
} }
/**
*
* @param unknown_type $form_state
* @param unknown_type $pid
* @param unknown_type $dsid
* @param unknown_type $label
*/
function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$form = array( $form = array(
@ -621,7 +649,7 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $
if (count($version_array) > 1) { if (count($version_array) > 1) {
$form['#attributes'] = array( $form['#attributes'] = array(
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;' 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;',
); );
$form['version'] = array( $form['version'] = array(
'#type' => 'select', '#type' => 'select',
@ -635,11 +663,13 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $
/** /**
* fedora repository replace stream * fedora repository replace stream
*
* @param type $pid * @param type $pid
* @param type $dsId * @param type $dsId
* @param type $dsLabel * @param type $dsLabel
* @param type $collectionName * @param type $collectionName
* @return type *
* @return string
*/ */
function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectionName = NULL) { function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectionName = NULL) {
if ($pid == NULL || $dsId == NULL) { if ($pid == NULL || $dsId == NULL) {
@ -653,10 +683,12 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectio
/** /**
* fedora repository replace stream form * fedora repository replace stream form
*
* @param type $form_state * @param type $form_state
* @param type $pid * @param type $pid
* @param type $dsId * @param type $dsId
* @param type $dsLabel * @param type $dsLabel
*
* @return type * @return type
*/ */
function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) { function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) {
@ -675,7 +707,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
// If a file was uploaded, process it. // If a file was uploaded, process it.
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) { if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) {
// attempt to save the uploaded file // Attempt to save the uploaded file.
$file = file_save_upload('file', array(), file_directory_path()); $file = file_save_upload('file', array(), file_directory_path());
// set error is file was not uploaded // set error is file was not uploaded
@ -843,7 +875,8 @@ function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
$soap_helper = new ConnectionHelper(); $soap_helper = new ConnectionHelper();
$client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); $client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
// Check the content model for a custom edit metadata form submit function. /* Check the content model for a custom
* edit metadata form submit function.*/
if (isset($form_state['values']['pid'])) { if (isset($form_state['values']['pid'])) {
module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'ContentModel');
if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) { if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) {
@ -2247,6 +2280,7 @@ function fedora_repository_display_schema($file) {
*/ */
function fedora_repository_batch_reingest_object($object, $module_name, &$context) { function fedora_repository_batch_reingest_object($object, $module_name, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');

Loading…
Cancel
Save