From 56c65922242de16988e81efce553198e5bf6fde8 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Tue, 22 Mar 2011 14:15:13 -0300 Subject: [PATCH 1/2] Change to fedora_utils to add fixdsid function. It cleans a DSID so fedora will accept it. --- api/fedora_utils.inc | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index 97612595..5b144b21 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -88,20 +88,41 @@ function fix_encoding($in_str) { } } - function validPid($pid) { - $valid = FALSE; - if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) { - $valid = TRUE; - } - - return $valid; +function validPid($pid) { + $valid = FALSE; + if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) { + $valid = TRUE; } - function validDsid($dsid) { - $valid = FALSE; - if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) { - $valid = TRUE; - } + return $valid; +} - return $valid; +function validDsid($dsid) { + $valid = FALSE; + if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) { + $valid = TRUE; } + + return $valid; +} + +function fixDsid($dsid) { + $new_dsid = trim($dsid); + + $find = '/[^a-zA-Z0-9\.\_\-]/'; + $replace = ''; + $new_dsid = preg_replace($find, $replace, $new_dsid); + + if( strlen($new_dsid) > 63 ) + $new_dsid = substr($new_dsid, -63); + + if( preg_match('/^[^a-zA-Z]/', $dsid ) ) + $new_dsid = 'x' . $new_dsid; + + if( strlen($new_dsid) == 0 ) + $new_dsid = 'item' . rand(1, 100); + + return $new_dsid; + +} + From 4c51598ebac49fe9108e73117907578227d81e1b Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Tue, 22 Mar 2011 14:24:13 -0300 Subject: [PATCH 2/2] Defined names in contentmodel.inc so that if no content model is defined PHP doesn't complain about using undefined variables --- ContentModel.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ContentModel.inc b/ContentModel.inc index 4650d1ad..c82baf89 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -2038,6 +2038,7 @@ class ContentModel extends XMLDatastream { if (!$this->validate()) { return FALSE; } + $names = FALSE; $result = $this->xpath->query('//cm:forms/cm:form/@name'); // Select the name attribute of all forms. for($i = 0; $i < $result->length; $i++) { $attribute = $result->item($i);