diff --git a/ktwebdav/lib/KTWebDAVServer.inc.php b/ktwebdav/lib/KTWebDAVServer.inc.php
index ce47e17..fbbd3ec 100644
--- a/ktwebdav/lib/KTWebDAVServer.inc.php
+++ b/ktwebdav/lib/KTWebDAVServer.inc.php
@@ -6,32 +6,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -150,7 +150,6 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
* @return void
*/
function KTWebDAVServer() {
-
// CGI compatible auth setup
$altinfo = KTUtil::arrayGet( $_SERVER, 'kt_auth', KTUtil::arrayGet( $_SERVER, 'REDIRECT_kt_auth'));
if ( !empty( $altinfo) && !isset( $_SERVER['PHP_AUTH_USER'])) {
@@ -443,17 +442,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
$path = $options["path"];
- // Fix for Mac Clients
+ // Fix for the Mac Goliath Client
// Mac adds DS_Store files when folders are added and ._filename files when files are added
// The PUT function doesn't add these files to the dms but PROPFIND still looks for the .DS_Store file,
// and returns an error if not found. We emulate its existence by returning a positive result.
- if($this->dav_client == 'MC' || $this->dav_client == 'MG'){
+ if($this->dav_client == 'MG'){
// Remove filename from path
$aPath = explode('/', $path);
$fileName = $aPath[count($aPath)-1];
-
+
if(strtolower($fileName) == '.ds_store'){
- $this->ktwebdavLog("Using a Mac client. Filename is .DS_Store so we emulate a positive result.", 'info', true);
+ $this->ktwebdavLog("Using a Mac client. Filename is .DS_Store so we emulate a positive result.", 'info', true);
+ // ignore
+ return true;
+ }
+ if($fileName[0] == '.' && $fileName[1] == '_'){
+ $this->ktwebdavLog("Using a Mac client. Filename is ._Filename so we emulate a positive result.", 'info', true);
// ignore
return true;
}
@@ -571,6 +575,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
$this->ktwebdavLog("fspath is " . $fspath, 'info', true);
// create result array
+ // Modified - 25/10/07 - spaces prevent files displaying in finder
+ if($this->dav_client == 'MC'){
+ $path = str_replace('%2F', '/', urlencode($path));
+ }
$info = array();
$info["path"] = $path;
$info["props"] = array();
@@ -647,13 +655,18 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
$this->ktwebdavLog("Entering _fileinfoForFolder. Folder is " . print_r($oFolder, true), 'info', true);
+ // Fix for Mac
+ // Modified - 25/10/07 - spaces prevent files displaying in finder
+ if($this->dav_client == 'MC'){
+ $path = str_replace('%2F', '/', urlencode(utf8_encode($path)));
+ }
// create result array
$info = array();
- $info["path"] = $path;
+ $info["path"] = $path;
$fspath = $default->documentRoot . "/" . $this->rootFolder . $path;
//$fspath = $default->documentRoot . '/' . $oFolder->generateFolderPath($oFolder->getID());
- $info["props"] = array();
+ $info["props"] = array();
// no special beautified displayname here ...
$info["props"][] = $this->mkprop("displayname", $oFolder->getName());
@@ -686,7 +699,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
} else {
$options["depth"] = "infinity";
}
-
+
// analyze request payload
$propinfo = new _parse_propfind("php://input");
if (!$propinfo->success) {
@@ -821,7 +834,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
echo " \n";
$tempHref = $this->_mergePathes($_SERVER['SCRIPT_NAME'], $path);
-
+
// Ensure collections end in a slash
if(isset($file['props'])){
foreach($file['props'] as $v){
@@ -833,9 +846,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
}
}
}
-
+
$href = htmlspecialchars($tempHref);
-
+
echo " $href\n";
$this->ktwebdavLog("\nfile is: " . print_r($file, true), 'info', true);
@@ -991,6 +1004,27 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
// get path to requested resource
$path = $options["path"];
+ // Fix for Mac Clients
+ // Mac adds DS_Store files when folders are added and ._filename files when files are added
+ // The PUT function doesn't add these files to the dms but PROPFIND still looks for the .DS_Store file,
+ // and returns an error if not found. We emulate its existence by returning a positive result.
+ if($this->dav_client == 'MC' || $this->dav_client == 'MG'){
+ // Remove filename from path
+ $aPath = explode('/', $path);
+ $fileName = $aPath[count($aPath)-1];
+
+ if(strtolower($fileName) == '.ds_store'){
+ $this->ktwebdavLog("Using a Mac client. Filename is .DS_Store so we emulate a positive result.", 'info', true);
+ // ignore
+ return true;
+ }
+ if($fileName[0] == '.' && $fileName[1] == '_'){
+ $this->ktwebdavLog("Using a Mac client. Filename is ._Filename so we emulate a positive result.", 'info', true);
+ // ignore
+ return true;
+ }
+ }
+
list($iFolderID, $iDocumentID) = $this->_folderOrDocument($path);
if ($iDocumentID === false) {
@@ -1223,21 +1257,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
$this->ktwebdavLog("dav_client is: " . $this->dav_client, 'info', true);
$path = $options["path"];
-
+
// Fix for Mac
+ // Modified - 22/10/07
// Mac adds DS_Store files when folders are added and ._filename files when files are added
// we want to ignore them.
if($this->dav_client == 'MC' || $this->dav_client == 'MG'){
// Remove filename from path
$aPath = explode('/', $path);
$fileName = $aPath[count($aPath)-1];
-
+
if(strtolower($fileName) == '.ds_store'){
$this->ktwebdavLog("Using a mac client. Ignore the .DS_Store files created with every folder.", 'info', true);
// ignore
return "204 No Content";
}
-
+
if($fileName[0] == '.' && $fileName[1] == '_'){
$fileName = substr($fileName, 2);
$this->ktwebdavLog("Using a mac client. Ignore the ._filename files created with every file.", 'info', true);
@@ -1245,7 +1280,6 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
return "204 No Content";
}
}
-
$res = $this->_folderOrDocument($path);
list($iFolderID, $iDocumentID) = $res;
@@ -1329,7 +1363,13 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
'metadata' => array(),
'novalidate' => true,
);
- $oDocument =& KTDocumentUtil::add($oParentFolder, $name, $oUser, $aOptions);
+ $this->ktwebdavLog("DEBUG: overwriting file. Options: ".print_r($aOptions, true));
+ $this->ktwebdavLog("DEBUG: overwriting file. Temp name: ".$sTempFilename.' '.print_r($sTempFilename, true));
+ $this->ktwebdavLog("DEBUG: overwriting file. Name: ".$name.' '.print_r($name, true));
+
+ // Modified - 25/10/07 - changed add to overwrite
+ //$oDocument =& KTDocumentUtil::add($oParentFolder, $name, $oUser, $aOptions);
+ $oDocument =& KTDocumentUtil::overwrite($oDocument, $name, $sTempFilename, $oUser, $aOptions);
if(PEAR::isError($oDocument)) {
$this->ktwebdavLog("oDocument ERROR: " . $oDocument->getMessage(), 'info', true);
@@ -1340,7 +1380,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
$this->ktwebdavLog("oDocument is " . print_r($oDocument, true), 'info', true);
unlink($sTempFilename);
- return "204 No Content";
+ return "201 Created";
}
$options["new"] = true;
@@ -1682,8 +1722,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
function _MOVEDocument($options, $iFolderID, $iDocumentID) {
if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
-
- // Fix for Mac
+
+ // Fix for Mac Goliath
+ // Modified - 25/10/07 - remove ktwebdav from document path
if($this->dav_client == 'MG'){
$this->ktwebdavLog("Remove ktwebdav from destination path: ".$options['dest'], 'info', true);
if(!(strpos($options['dest'], 'ktwebdav/ktwebdav.php/') === FALSE)){
@@ -1691,9 +1732,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
}
if($options['dest'][0] != '/'){
$options['dest'] = '/'.$options['dest'];
- }
+ }
}
-
+
$this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true);
global $default;
$new = true;
@@ -1840,6 +1881,18 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
return "400 Bad request - depth must be 'inifinity'.";
}
+ // Fix for Mac Goliath
+ // Modified - 30/10/07 - remove ktwebdav from folder path
+ if($this->dav_client == 'MG'){
+ $this->ktwebdavLog("Remove ktwebdav from destination path: ".$options['dest'], 'info', true);
+ if(!(strpos($options['dest'], 'ktwebdav/ktwebdav.php/') === FALSE)){
+ $options['dest'] = substr($options['dest'], 22);
+ }
+ if($options['dest'][0] != '/'){
+ $options['dest'] = '/'.$options['dest'];
+ }
+ }
+
global $default;
$source_path = $options["path"];
@@ -2298,9 +2351,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
}
// Mac Finder
- if ($this->dav_client == 'MC') {
+ if ($this->dav_client == 'MC' && $this->safeMode == 'off') {
+
+ $this->ktwebdavLog("This is Mac Finder type client with SafeMode off.", 'info', true);
+ return true;
+
+ }
+ if ($this->dav_client == 'MC' && $this->safeMode != 'off') {
- $this->ktwebdavLog("This is Mac Finder type client which only supports SafeMode.", 'info', true);
+ $this->ktwebdavLog("This is Mac Finder type client with SafeMode on.", 'info', true);
return false;
}
diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php
index 1f538f2..55b5925 100644
--- a/lib/documentmanagement/documentutil.inc.php
+++ b/lib/documentmanagement/documentutil.inc.php
@@ -295,6 +295,81 @@ class KTDocumentUtil {
return $oDocument;
}
+ // Overwrite the document
+ function overwrite($oDocument, $sFilename, $sTempFileName, $oUser, $aOptions) {
+ //$oDocument, $sFilename, $sCheckInComment, $oUser, $aOptions = false
+ $oStorage =& KTStorageManagerUtil::getSingleton();
+ $iFileSize = filesize($sTempFileName);
+
+ // Check that document is not checked out
+ if($oDocument->getIsCheckedOut()) {
+ return PEAR::raiseError(_kt('Document is checkout and cannot be overwritten'));
+ }
+
+ if (!$oStorage->upload($oDocument, $sTempFileName)) {
+ return PEAR::raiseError(_kt('An error occurred while storing the new file'));
+ }
+
+ $oDocument->setLastModifiedDate(getCurrentDateTime());
+ $oDocument->setModifiedUserId($oUser->getId());
+
+ $oDocument->setFileSize($iFileSize);
+
+ $sOriginalFilename = $oDocument->getFileName();
+
+ if($sOriginalFilename != $sFilename){
+ if(strlen($sFilename)) {
+ global $default;
+ $oDocument->setFileName($sFilename);
+ $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
+ }
+ $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1);
+ }
+
+ $sType = KTMime::getMimeTypeFromFile($sFilename);
+ $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
+ $oDocument->setMimeTypeId($iMimeTypeId);
+
+ $bSuccess = $oDocument->update();
+ if ($bSuccess !== true) {
+ if (PEAR::isError($bSuccess)) {
+ return $bSuccess;
+ }
+ return PEAR::raiseError(_kt('An error occurred while storing this document in the database'));
+ }
+/*
+ // create the document transaction record
+ $oDocumentTransaction = new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
+ $oDocumentTransaction->create();
+
+ $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
+ $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
+ foreach ($aTriggers as $aTrigger) {
+ $sTrigger = $aTrigger[0];
+ $oTrigger = new $sTrigger;
+ $oTrigger->setDocument($oDocument);
+ $ret = $oTrigger->scan();
+ if (PEAR::isError($ret)) {
+ $oDocument->delete();
+ return $ret;
+ }
+ }
+
+ // NEW SEARCH
+
+ Indexer::index($oDocument);
+
+
+ // fire subscription alerts for the checked in document
+ $oSubscriptionEvent = new SubscriptionEvent();
+ $oFolder = Folder::get($oDocument->getFolderID());
+ $oSubscriptionEvent->CheckinDocument($oDocument, $oFolder);
+
+ KTDocumentUtil::updateSearchableText($oDocument);
+*/
+ return true;
+ }
+
// {{{ validateMetadata
function validateMetadata(&$oDocument, $aMetadata) {
$aFieldsets =& KTFieldset::getGenericFieldsets();
@@ -477,32 +552,32 @@ class KTDocumentUtil {
function &_in_add($oFolder, $sFilename, $oUser, $aOptions) {
$aOrigOptions = $aOptions;
if (KTDocumentUtil::fileExists($oFolder, $sFilename)) {
- $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId());
- if (PEAR::isError($oDoc)) {
- return PEAR::raiseError(_kt('Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
- } else {
- if ($oDoc->getStatusID() != LIVE) {
- $sError = _kt('Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.');
- } else {
- $sError = _kt('Document with that filename already exists in this folder.');
- }
-
- $sError .= _kt(' Document') . ': ' . $oDoc->getName() . ' (ID:' . $oDoc->getId() . ')';
- return PEAR::raiseError($sError);
- }
+ $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId());
+ if (PEAR::isError($oDoc)) {
+ return PEAR::raiseError(_kt('Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
+ } else {
+ if ($oDoc->getStatusID() != LIVE) {
+ $sError = _kt('Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.');
+ } else {
+ $sError = _kt('Document with that filename already exists in this folder.');
+ }
+
+ $sError .= _kt(' Document') . ': ' . $oDoc->getName() . ' (ID:' . $oDoc->getId() . ')';
+ return PEAR::raiseError($sError);
+ }
}
$sName = KTUtil::arrayGet($aOptions, 'description', $sFilename);
if (KTDocumentUtil::nameExists($oFolder, $sName)) {
- $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId());
- if (PEAR::isError($oDoc)) {
- return PEAR::raiseError(_kt('Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
- } else {
- if ($oDoc->getStatusID != LIVE) {
- return PEAR::raiseError(_kt('Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.'));
- } else {
- return PEAR::raiseError(_kt('Document with that title already exists in this folder.'));
- }
- }
+ $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId());
+ if (PEAR::isError($oDoc)) {
+ return PEAR::raiseError(_kt('Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
+ } else {
+ if ($oDoc->getStatusID != LIVE) {
+ return PEAR::raiseError(_kt('Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.'));
+ } else {
+ return PEAR::raiseError(_kt('Document with that title already exists in this folder.'));
+ }
+ }
}
@@ -907,7 +982,6 @@ class KTDocumentUtil {
$oNewDocument->setIsCheckedOut(false);
$oNewDocument->setCheckedOutUserID(-1);
-
// finally, copy the actual file.
$oStorage =& KTStorageManagerUtil::getSingleton();
$res = $oStorage->copy($oDocument, $oNewDocument);