2012-07-16 03:06:35 +02:00
|
|
|
<?php
|
2012-07-16 08:21:48 +02:00
|
|
|
class DMSDocument extends DataObject implements DMSDocumentInterface {
|
|
|
|
static $db = array(
|
2012-07-26 02:46:03 +02:00
|
|
|
"Filename" => "Varchar(255)", // eg. 3469~2011-energysaving-report.pdf
|
|
|
|
"Folder" => "Varchar(255)", // eg. 0
|
|
|
|
"Title" => 'Varchar(1024)', // eg. "Energy Saving Report for Year 2011, New Zealand LandCorp"
|
2012-07-25 08:08:49 +02:00
|
|
|
"Description" => 'Text',
|
2012-07-27 04:02:46 +02:00
|
|
|
"LastChanged" => 'SS_DateTime' //when this document's file was created or last replaced (small changes like updating title don't count)
|
2012-07-16 08:21:48 +02:00
|
|
|
);
|
2012-07-16 03:06:35 +02:00
|
|
|
|
2012-07-17 07:58:33 +02:00
|
|
|
static $many_many = array(
|
2012-07-25 05:11:06 +02:00
|
|
|
'Pages' => 'SiteTree',
|
|
|
|
'Tags' => 'DMSTag'
|
2012-07-17 07:58:33 +02:00
|
|
|
);
|
2012-07-27 05:38:42 +02:00
|
|
|
|
|
|
|
static $display_fields = array(
|
|
|
|
'ID'=>'ID',
|
|
|
|
'Title'=>'Title',
|
|
|
|
'Filename'=>'Filename',
|
|
|
|
'LastChanged'=>'LastChanged'
|
|
|
|
);
|
2012-07-17 07:58:33 +02:00
|
|
|
|
2012-07-16 03:06:35 +02:00
|
|
|
/**
|
2012-07-16 05:32:28 +02:00
|
|
|
* Associates this document with a Page. This method does nothing if the association already exists.
|
2012-07-27 02:22:27 +02:00
|
|
|
* This could be a simple wrapper around $myDoc->Pages()->add($myPage) to add a many_many relation
|
2012-07-16 05:32:28 +02:00
|
|
|
* @param $pageObject Page object to associate this Document with
|
|
|
|
* @return null
|
2012-07-16 03:06:35 +02:00
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function addPage($pageObject) {
|
2012-07-17 07:58:33 +02:00
|
|
|
$this->Pages()->add($pageObject);
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-27 02:22:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Associates this DMSDocument with a set of Pages. This method loops through a set of page ids, and then associates this
|
|
|
|
* DMSDocument with the individual Page with the each page id in the set
|
|
|
|
* @abstract
|
|
|
|
* @param $pageIDs array of page ids used for the page objects associate this DMSDocument with
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
function addPages($pageIDs){
|
|
|
|
foreach($pageIDs as $id){
|
|
|
|
$pageObject = DataObject::get_by_id("SiteTree", $id);
|
|
|
|
if($pageObject && $pageObject->exists()) {
|
|
|
|
$this->addPage($pageObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the association between this Document and a Page. This method does nothing if the association does not exist.
|
|
|
|
* @param $pageObject Page object to remove the association to
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function removePage($pageObject) {
|
2012-07-17 07:58:33 +02:00
|
|
|
$this->Pages()->remove($pageObject);
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of the Page objects associated with this Document
|
|
|
|
* @return DataList
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function getPages() {
|
2012-07-17 07:58:33 +02:00
|
|
|
$this->Pages();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all associated Pages from the DMSDocument
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
function removeAllPages() {
|
|
|
|
$this->Pages()->removeAll();
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 03:06:35 +02:00
|
|
|
|
2012-07-25 08:08:49 +02:00
|
|
|
|
2012-07-16 03:06:35 +02:00
|
|
|
/**
|
2012-07-16 05:32:28 +02:00
|
|
|
* Adds a metadata tag to the Document. The tag has a category and a value.
|
|
|
|
* Each category can have multiple values by default. So: addTag("fruit","banana") addTag("fruit", "apple") will add two items.
|
|
|
|
* However, if the third parameter $multiValue is set to 'false', then all updates to a category only ever update a single value. So:
|
|
|
|
* addTag("fruit","banana") addTag("fruit", "apple") would result in a single metadata tag: fruit->apple.
|
|
|
|
* Can could be implemented as a key/value store table (although it is more like category/value, because the
|
|
|
|
* same category can occur multiple times)
|
|
|
|
* @param $category String of a metadata category to add (required)
|
|
|
|
* @param $value String of a metadata value to add (required)
|
|
|
|
* @param bool $multiValue Boolean that determines if the category is multi-value or single-value (optional)
|
|
|
|
* @return null
|
2012-07-16 03:06:35 +02:00
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function addTag($category, $value, $multiValue = true) {
|
2012-07-17 07:58:33 +02:00
|
|
|
if ($multiValue) {
|
|
|
|
//check for a duplicate tag, don't add the duplicate
|
2012-07-25 08:56:43 +02:00
|
|
|
$currentTag = $this->Tags()->filter(array('Category' => $category, 'Value' => $value));
|
|
|
|
if ($currentTag->Count() == 0) {
|
2012-07-17 07:58:33 +02:00
|
|
|
//multi value tag
|
|
|
|
$tag = new DMSTag();
|
|
|
|
$tag->Category = $category;
|
|
|
|
$tag->Value = $value;
|
2012-07-27 01:26:30 +02:00
|
|
|
$tag->MultiValue = true;
|
2012-07-17 07:58:33 +02:00
|
|
|
$tag->write();
|
2012-07-25 08:56:43 +02:00
|
|
|
$tag->Documents()->add($this);
|
2012-07-27 01:26:30 +02:00
|
|
|
} else {
|
|
|
|
//add the relation between the tag and document
|
|
|
|
foreach($currentTag as $tagObj) {
|
|
|
|
$tagObj->Documents()->add($this);
|
|
|
|
}
|
2012-07-17 07:58:33 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//single value tag
|
2012-07-25 08:56:43 +02:00
|
|
|
$currentTag = $this->Tags()->filter(array('Category' => $category));
|
2012-07-27 01:26:30 +02:00
|
|
|
$tag = null;
|
|
|
|
if ($currentTag->Count() == 0) {
|
2012-07-17 07:58:33 +02:00
|
|
|
//create the single-value tag
|
|
|
|
$tag = new DMSTag();
|
|
|
|
$tag->Category = $category;
|
|
|
|
$tag->Value = $value;
|
2012-07-27 01:26:30 +02:00
|
|
|
$tag->MultiValue = false;
|
2012-07-17 07:58:33 +02:00
|
|
|
$tag->write();
|
|
|
|
} else {
|
|
|
|
//update the single value tag
|
|
|
|
$tag = $currentTag->first();
|
|
|
|
$tag->Value = $value;
|
2012-07-27 01:26:30 +02:00
|
|
|
$tag->MultiValue = false;
|
2012-07-17 07:58:33 +02:00
|
|
|
$tag->write();
|
|
|
|
}
|
2012-07-27 01:26:30 +02:00
|
|
|
|
|
|
|
//regardless of whether we created a new tag or are just updating an existing one, add the relation
|
|
|
|
$tag->Documents()->add($this);
|
2012-07-17 07:58:33 +02:00
|
|
|
}
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 03:06:35 +02:00
|
|
|
|
2012-07-27 01:26:30 +02:00
|
|
|
protected function getTagsObjects($category, $value = null) {
|
|
|
|
$valueFilter = array("Category" => $category);
|
|
|
|
if (!empty($value)) $valueFilter['Value'] = $value;
|
|
|
|
|
|
|
|
$tags = $this->Tags()->filter($valueFilter);
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2012-07-25 08:56:43 +02:00
|
|
|
/**
|
|
|
|
* Fetches all tags associated with this DMSDocument within a given category. If a value is specified this method
|
|
|
|
* tries to fetch that specific tag.
|
|
|
|
* @abstract
|
|
|
|
* @param $category String of the metadata category to get
|
|
|
|
* @param null $value String of the value of the tag to get
|
|
|
|
* @return array of Strings of all the tags or null if there is no match found
|
|
|
|
*/
|
2012-07-30 02:33:01 +02:00
|
|
|
function getTagsList($category, $value = null) {
|
2012-07-27 01:26:30 +02:00
|
|
|
$tags = $this->getTagsObjects($category, $value);
|
2012-07-25 08:56:43 +02:00
|
|
|
|
|
|
|
//convert DataList into array of Values
|
|
|
|
$returnArray = null;
|
2012-07-27 01:26:30 +02:00
|
|
|
if ($tags->Count() > 0) {
|
2012-07-25 08:56:43 +02:00
|
|
|
$returnArray = array();
|
2012-07-27 01:26:30 +02:00
|
|
|
foreach($tags as $t) {
|
2012-07-25 08:56:43 +02:00
|
|
|
$returnArray[] = $t->Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $returnArray;
|
|
|
|
}
|
|
|
|
|
2012-07-16 05:32:28 +02:00
|
|
|
/**
|
|
|
|
* Quick way to add multiple tags to a Document. This takes a multidimensional array of category/value pairs.
|
|
|
|
* The array should look like this:
|
|
|
|
* $twoDimensionalArray = new array(
|
|
|
|
* array('fruit','banana'),
|
|
|
|
* array('fruit','apple')
|
|
|
|
* );
|
|
|
|
* @param $twoDimensionalArray array containing a list of arrays
|
|
|
|
* @param bool $multiValue Boolean that determines if the category is multi-value or single-value (optional)
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function addTags($twoDimensionalArray, $multiValue = true) {
|
|
|
|
// TODO: Implement addTags() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a tag from the Document. If you only set a category, then all values in that category are deleted.
|
|
|
|
* If you specify both a category and a value, then only that single category/value pair is deleted.
|
|
|
|
* Nothing happens if the category or the value do not exist.
|
|
|
|
* @param $category Category to remove (required)
|
|
|
|
* @param null $value Value to remove (optional)
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function removeTag($category, $value = null) {
|
2012-07-27 01:26:30 +02:00
|
|
|
$tags = $this->getTagsObjects($category, $value);
|
|
|
|
|
|
|
|
if ($tags->Count() > 0) {
|
|
|
|
foreach($tags as $t) {
|
|
|
|
$documentList = $t->Documents();
|
|
|
|
|
|
|
|
//remove the relation between the tag and the document
|
|
|
|
$documentList->remove($this);
|
|
|
|
|
|
|
|
//delete the entire tag if it has no relations left
|
2012-07-27 02:36:45 +02:00
|
|
|
if ($documentList->Count() == 0) $t->delete();
|
2012-07-27 01:26:30 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all tags associated with this Document.
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function removeAllTags() {
|
2012-07-27 01:26:30 +02:00
|
|
|
$allTags = $this->Tags();
|
|
|
|
foreach($allTags as $tag) {
|
2012-07-27 02:36:45 +02:00
|
|
|
$documentlist = $tag->Documents();
|
|
|
|
$documentlist->remove($this);
|
2012-07-27 01:26:30 +02:00
|
|
|
if ($tag->Documents()->Count() == 0) $tag->delete();
|
|
|
|
}
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a multi-dimensional array containing all Tags associated with this Document. The array has the
|
|
|
|
* following structure:
|
|
|
|
* $twoDimensionalArray = new array(
|
2012-07-16 08:21:48 +02:00
|
|
|
* array('fruit','banana'),
|
|
|
|
* array('fruit','apple')
|
|
|
|
* );
|
2012-07-16 05:32:28 +02:00
|
|
|
* @return array Multi-dimensional array of tags
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function getAllTags() {
|
|
|
|
// TODO: Implement getAllTags() method.
|
|
|
|
}
|
2012-07-16 03:06:35 +02:00
|
|
|
|
2012-07-16 05:32:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a link to download this document from the DMS store
|
|
|
|
* @return String
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function downloadLink() {
|
2012-07-27 07:38:20 +02:00
|
|
|
return Controller::join_links(Director::baseURL(),'dmsdocument/'.$this->ID);
|
2012-07-16 08:21:48 +02:00
|
|
|
}
|
2012-07-16 03:06:35 +02:00
|
|
|
|
2012-07-16 05:32:28 +02:00
|
|
|
/**
|
|
|
|
* Hides the document, so it does not show up when getByPage($myPage) is called
|
|
|
|
* (without specifying the $showEmbargoed = true parameter). This is similar to expire, except that this method
|
|
|
|
* should be used to hide documents that have not yet gone live.
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function embargo() {
|
|
|
|
// TODO: Implement embargo() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if this is Document is embargoed.
|
|
|
|
* @return bool True or False depending on whether this document is embargoed
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function isEmbargoed() {
|
|
|
|
// TODO: Implement isEmbargoed() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the document, so it does not show up when getByPage($myPage) is called. Automatically un-hides the
|
|
|
|
* Document at a specific date.
|
|
|
|
* @param $datetime String date time value when this Document should expire
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function embargoUntilDate($datetime) {
|
|
|
|
// TODO: Implement embargoUntilDate() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears any previously set embargos, so the Document always shows up in all queries.
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function clearEmbargo() {
|
|
|
|
// TODO: Implement clearEmbargo() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the document, so it does not show up when getByPage($myPage) is called.
|
|
|
|
* (without specifying the $showEmbargoed = true parameter). This is similar to embargo, except that it should be
|
|
|
|
* used to hide documents that are no longer useful.
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function expire() {
|
|
|
|
// TODO: Implement expire() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if this is Document is expired.
|
|
|
|
* @return bool True or False depending on whether this document is expired
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function isExpired() {
|
|
|
|
// TODO: Implement isExpired() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the document at a specific date, so it does not show up when getByPage($myPage) is called.
|
|
|
|
* @param $datetime String date time value when this Document should expire
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function expireAtDate($datetime) {
|
|
|
|
// TODO: Implement expireAtDate() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears any previously set expiry.
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function clearExpiry() {
|
|
|
|
// TODO: Implement clearExpiry() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a DataList of all previous Versions of this document (check the LastEdited date of each
|
|
|
|
* object to find the correct one)
|
|
|
|
* @return DataList List of Document objects
|
|
|
|
*/
|
2012-07-16 08:21:48 +02:00
|
|
|
function getVersions() {
|
|
|
|
// TODO: Implement getVersions() method.
|
|
|
|
}
|
2012-07-16 05:32:28 +02:00
|
|
|
|
2012-07-17 03:52:46 +02:00
|
|
|
/**
|
|
|
|
* Returns the full filename of the document stored in this object
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getFullPath() {
|
2012-07-27 07:38:20 +02:00
|
|
|
return DMS::get_DMS_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $this->Filename;
|
2012-07-17 03:52:46 +02:00
|
|
|
}
|
|
|
|
|
2012-07-17 07:58:33 +02:00
|
|
|
/**
|
|
|
|
* Deletes the DMSDocument, its underlying file, as well as any tags related to this DMSDocument. Also calls the
|
|
|
|
* parent DataObject's delete method.
|
|
|
|
*/
|
|
|
|
function delete() {
|
|
|
|
//remove tags
|
|
|
|
$this->removeAllTags();
|
|
|
|
|
|
|
|
//delete the file
|
2012-07-27 07:38:20 +02:00
|
|
|
if (is_file($this->getFullPath())) unlink($this->getFullPath());
|
2012-07-17 07:58:33 +02:00
|
|
|
|
|
|
|
$this->removeAllPages();
|
|
|
|
|
|
|
|
//delete the dataobject
|
|
|
|
parent::delete();
|
|
|
|
}
|
|
|
|
|
2012-07-27 04:02:46 +02:00
|
|
|
function storeDocument($filePath) {
|
|
|
|
if (empty($this->ID)) user_error("Document must be written to database before it can store documents",E_USER_ERROR);
|
|
|
|
|
|
|
|
//calculate all the path to copy the file to
|
|
|
|
$fromFilename = basename($filePath);
|
|
|
|
$toFilename = $this->ID. '~' . $fromFilename; //add the docID to the start of the Filename
|
2012-07-27 04:21:24 +02:00
|
|
|
$toFolder = DMS::getStorageFolder($this->ID);
|
2012-07-27 07:38:20 +02:00
|
|
|
$toPath = DMS::get_DMS_path() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename;
|
|
|
|
DMS::createStorageFolder(DMS::get_DMS_path() . DIRECTORY_SEPARATOR . $toFolder);
|
2012-07-27 04:02:46 +02:00
|
|
|
|
|
|
|
//copy the file into place
|
|
|
|
$fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath;
|
|
|
|
copy($fromPath, $toPath); //this will overwrite the existing file (if present)
|
|
|
|
|
|
|
|
//write the filename of the stored document
|
|
|
|
$this->Filename = $toFilename;
|
|
|
|
$this->Folder = $toFolder;
|
|
|
|
if (empty($this->Title)) $this->Title = $fromFilename; //don't overwrite existing document titles
|
|
|
|
$this->LastChanged = SS_Datetime::now()->Rfc2822();
|
|
|
|
|
|
|
|
$this->write();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-07-27 01:26:30 +02:00
|
|
|
/**
|
|
|
|
* Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file
|
|
|
|
* but keeping the rest of the document unchanged.
|
|
|
|
* @param $file File object, or String that is path to a file to store
|
|
|
|
* @return DMSDocumentInstance Document object that we replaced the file in
|
|
|
|
*/
|
|
|
|
function replaceDocument($file) {
|
2012-07-27 04:21:24 +02:00
|
|
|
$filePath = DMS::transformFileToFilePath($file);
|
2012-07-27 04:02:46 +02:00
|
|
|
$doc = $this->storeDocument($filePath); //replace the document
|
|
|
|
return $doc;
|
2012-07-27 01:26:30 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 07:38:20 +02:00
|
|
|
function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class DMSDocument_Controller extends Controller {
|
|
|
|
static $allowed_actions = array(
|
|
|
|
'index'
|
|
|
|
);
|
|
|
|
|
|
|
|
protected static function get_file_extension($filename) {
|
|
|
|
return pathinfo($filename, PATHINFO_EXTENSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access the file download without redirecting user, so we can block direct access to documents.
|
|
|
|
*/
|
|
|
|
function index(SS_HTTPRequest $request) {
|
|
|
|
$id = Convert::raw2sql($this->getRequest()->param('ID'));
|
|
|
|
Debug::show($id);
|
|
|
|
if (!empty($id)) $doc = DataObject::get_by_id('DMSDocument', $id);
|
|
|
|
if (!empty($doc)) {
|
|
|
|
Debug::Show($doc);
|
|
|
|
$canView = false;
|
|
|
|
|
|
|
|
//Runs through all pages that this page links to and sets canView to true if the user can view ONE of these pages
|
|
|
|
$pages = $doc->Pages();
|
|
|
|
if ($pages->Count() > 0) {
|
|
|
|
foreach($pages as $page) {
|
|
|
|
if ($page->CanView()) {
|
|
|
|
$canView = true; //just one canView is enough to know that we can view the file
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//if the document isn't on any page, then allow viewing of the document (because there is no canView() to consult)
|
|
|
|
$canView = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add a check for embargo
|
|
|
|
|
|
|
|
if ($canView) {
|
|
|
|
$path = $doc->getFullPath();
|
|
|
|
Debug::Show($path);
|
|
|
|
if ( is_file($path) ) {
|
|
|
|
$fileBin = trim(`whereis file`);
|
|
|
|
Debug::Show($fileBin);
|
|
|
|
if ( function_exists('finfo_file') ) {
|
|
|
|
// discover the mime type properly
|
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$mime = finfo_file($finfo, $path);
|
|
|
|
}
|
|
|
|
else if ( is_executable($fileBin) ) {
|
|
|
|
// try to use the system tool
|
|
|
|
$mime = `$fileBin -i -b $path`;
|
|
|
|
$mime = explode(';', $mime);
|
|
|
|
$mime = trim($mime[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// make do with what we have
|
|
|
|
$ext = self::get_file_extension($path);
|
|
|
|
if ( $ext =='pdf') {
|
|
|
|
$mime = 'application/pdf';
|
|
|
|
}elseif ($ext == 'html' || $ext =='htm') {
|
|
|
|
$mime = 'text/html';
|
|
|
|
}else {
|
|
|
|
$mime = 'application/octet-stream';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
header('Content-Type: ' . $mime);
|
|
|
|
header('Content-Length: ' . filesize($path), null);
|
|
|
|
if (!empty($mime) && $mime != "text/html") header('Content-Disposition: attachment; filename="'.basename($path).'"');
|
|
|
|
header('Content-transfer-encoding: 8bit');
|
|
|
|
header('Expires: 0');
|
|
|
|
header('Pragma: cache');
|
|
|
|
header('Cache-Control: private');
|
|
|
|
flush();
|
|
|
|
readfile($path);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->httpError(404, 'This asset does not exist.');
|
|
|
|
}
|
2012-07-30 02:33:01 +02:00
|
|
|
|
|
|
|
function getCMSFields() {
|
|
|
|
return parent::getCMSFields();
|
|
|
|
}
|
2012-07-27 07:38:20 +02:00
|
|
|
}
|
|
|
|
|