Commit fbb8a6c3c933e2f32e29bb74a6746dddfc2575f2

Authored by Neil Blakey-Milner
1 parent 82bdb119

Remove some items implemented by the abstract storage manager system, as

well as the MIME-related functions.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3605 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/PhysicalDocumentManager.inc
... ... @@ -31,57 +31,9 @@ if (!extension_loaded('fileinfo')) {
31 31 @dl('fileinfo.' . PHP_SHLIB_SUFFIX);
32 32 }
33 33  
  34 +require_once(KT_LIB_DIR . '/mime.inc.php');
  35 +
34 36 class PhysicalDocumentManager {
35   -
36   - /**
37   - * Upload and store a new document
38   - *
39   - * @param The document object being uploaded
40   - * @param Primary key of folder in which document will be stored
41   - * @param Document description (should be passed through as a form variable)
42   - * @param Temporary path of file on server (get from $aFileArray['fFile']['tmp_name'])
43   - *
44   - * @return boolean true on successful upload and storage, false otherwise and set $_SESSION["errorMessage"]
45   - *
46   - * @todo add URL functionality
47   - */
48   - function uploadPhysicalDocument($oDocument, $iFolderID, $sDescription, $sTmpFilePath) {
49   - global $lang_fileexists, $lang_err_upload, $lang_err_database;
50   - //find the path on the system where the document should be stored
51   - $sDocumentFileSystemPath = $oDocument->getPath();
52   - //copy the file accross
53   - if (copy($sTmpFilePath, $sDocumentFileSystemPath)) {
54   - //remove the temporary file
55   - unlink($sTmpFilePath);
56   - if (file_exists($sDocumentFileSystemPath)) {
57   - return true;
58   - } else {
59   - return false;
60   - }
61   - } else {
62   - $_SESSION["errorMessage"] = $lang_err_upload;
63   - return false;
64   - }
65   - }
66   -
67   - /**
68   - * Renames a document on the filesystem
69   - *
70   - * @param object the document to rename
71   - * @param string the new document filename
72   - * @return true on success, false on failure
73   - */
74   - function renamePhysicalDocument($oDocument, $sNewFileName) {
75   - global $default;
76   -
77   - // create new and old paths
78   - $sDocumentFileSystemPath = $oDocument->getPath();
79   - $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $sNewFileName;
80   - $default->log->debug("renaming $sDocumentFileSystemPath to $sNewDocumentFileSystemPath");
81   - // move it
82   - return rename($sDocumentFileSystemPath, $sNewDocumentFileSystemPath);
83   - }
84   -
85 37 /**
86 38 * Stream a document to a client over http
87 39 *
... ... @@ -99,7 +51,7 @@ class PhysicalDocumentManager {
99 51 if (file_exists($sDocumentFileSystemPath)) {
100 52 //set the correct headers
101 53 header("Content-Type: " .
102   - PhysicalDocumentManager::getMimeTypeName($oDocument->getMimeTypeID()));
  54 + KTMime::getMimeTypeName($oDocument->getMimeTypeID()));
103 55 header("Content-Length: ". $oDocument->getFileSize());
104 56 header("Content-Disposition: attachment; filename=\"" . $oDocument->getFileName() . "\"");
105 57 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
... ... @@ -117,7 +69,7 @@ class PhysicalDocumentManager {
117 69 * Stream a particular version of a document to a client over http
118 70 *
119 71 * @param Primary key of document to stream
120   - * @param Primary key of document to stream
  72 + * @param Primary key of document to stream
121 73 * @return int number of bytes read from file on success or false otherwise;
122 74 */
123 75 function downloadVersionedPhysicalDocument($iDocumentID, $sVersion) {
... ... @@ -128,7 +80,7 @@ class PhysicalDocumentManager {
128 80 if (file_exists($sDocumentFileSystemPath)) {
129 81 //set the correct headers
130 82 header("Content-Type: " .
131   - PhysicalDocumentManager::getMimeTypeName($oDocument->getMimeTypeID()));
  83 + KTMime::getMimeTypeName($oDocument->getMimeTypeID()));
132 84 header("Content-Length: ". filesize($sDocumentFileSystemPath));
133 85 // prefix the filename presented to the browser to preserve the document extension
134 86 header('Content-Disposition: attachment; filename="' . "$sVersion-" . $oDocument->getFileName() . '"');
... ... @@ -412,108 +364,9 @@ class PhysicalDocumentManager {
412 364 */
413 365 function & createDocumentFromUploadedFile($aFileArray, $iFolderID) {
414 366 //get the uploaded document information and put it into a document object
415   - $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
  367 + $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], KTMime::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
416 368 return $oDocument;
417 369 }
418   -
419   - /**
420   - * Strip all but the extension from a file. For instance, input of
421   - * 'foo.tif' would return 'tif'.
422   - *
423   - * @param string filename
424   - * @return string extension for given file, without filename itself
425   - */
426   - function stripAllButExtension($sFileName) {
427   - return strtolower(substr($sFileName, strpos($sFileName, ".")+1, strlen($sFileName) - strpos($sFileName, ".")));
428   - }
429   -
430   - /**
431   - * Get the mime type primary key for a specific mime type
432   - *
433   - * @param string detected mime type
434   - * @param string filename
435   - * @return int mime type primary key if found, else default mime type primary key (text/plain)
436   - */
437   - function getMimeTypeID($sMimeType, $sFileName) {
438   - global $default;
439   - $sql = $default->db;
440   - $bOfficeDocument = false;
441   -
442   - // application/msword seems to be set by all Office documents
443   - if ($sMimeType == "application/msword") {
444   - $bOfficeDocument = true;
445   - }
446   -
447   - if ($bOfficeDocument || (!$sMimeType)) {
448   - // check by file extension
449   - $sExtension = PhysicalDocumentManager::stripAllButExtension($sFileName);
450   - $sql->query(array("SELECT id FROM " . $default->mimetypes_table . " WHERE LOWER(filetypes) = ?", $sExtension));/*ok*/
451   - if ($sql->next_record()) {
452   - return $sql->f("id");
453   - }
454   - }
455   -
456   - // get the mime type id
457   - if (isset($sMimeType)) {
458   - $sql->query(array("SELECT id FROM " . $default->mimetypes_table . " WHERE mimetypes = ?", $sMimeType));/*ok*/
459   - if ($sql->next_record()) {
460   - return $sql->f("id");
461   - }
462   - }
463   -
464   - //otherwise return the default mime type
465   - return PhysicalDocumentManager::getDefaultMimeTypeID();
466   - }
467   -
468   - /**
469   - * Get the default mime type, which is text/plain
470   - *
471   - * @return int default mime type
472   - *
473   - */
474   - function getDefaultMimeTypeID() {
475   - global $default;
476   - $sql = $default->db;
477   - $sql->query("SELECT id FROM " . $default->mimetypes_table . " WHERE mimetypes = 'text/plain'");/*ok*/
478   - $sql->next_record();
479   - //get the mime type id
480   - return $sql->f("id");
481   - }
482   -
483   - function getMimeTypeName($iMimeTypeID) {
484   - global $default;
485   - $sql = $default->db;
486   - $sql->query(array("SELECT mimetypes FROM " . $default->mimetypes_table . " WHERE id = ?", $iMimeTypeID));/*ok*/
487   - if ($sql->next_record()) {
488   - return $sql->f("mimetypes");
489   - }
490   - return "application/octet-stream";
491   - }
492   -
493   - /**
494   - * Try well-defined methods for getting the MIME type for a file on disk.
495   - * First try PECL's Fileinfo library, then try mime_content_type() builtin.
496   - * If neither are available, returns NULL.
497   - *
498   - * @param string file on disk
499   - * @return string mime time for given filename, or NULL
500   - */
501   - function getMimeTypeFromFile($sFileName) {
502   - if (extension_loaded('fileinfo')) {
503   - $res = finfo_open(FILEINFO_MIME);
504   - $sType = finfo_file($res, $sFileName);
505   - }
506   -
507   - if (!$sType && function_exists('mime_content_type')) {
508   - $sType = @mime_content_type($sFileName);
509   - }
510   -
511   - if ($sType) {
512   - return preg_replace('/;.*$/', '', $sType);
513   - }
514   -
515   - return NULL;
516   - }
517 370 }
518 371  
519 372 ?>
... ...