filename can be passed to addItem()

This commit is contained in:
Uwe Steinmann 2022-03-25 07:21:37 +01:00
parent 48613b5897
commit 11942c825d

View File

@ -46,6 +46,18 @@ class SeedDMS_Download_Mgr {
*/
protected $extracols;
/**
* @var array $rawcontents list of content used instead of document content
* @access protected
*/
protected $rawcontents;
/**
* @var array $filenames filename used in archive
* @access protected
*/
protected $filnames;
function __construct($tmpdir = '') {
$this->tmpdir = $tmpdir;
$this->items = array();
@ -59,10 +71,11 @@ class SeedDMS_Download_Mgr {
$this->extraheader = $extraheader;
} /* }}} */
public function addItem($item, $extracols=array(), $rawcontent='') { /* {{{ */
public function addItem($item, $extracols=array(), $rawcontent='', $filename='') { /* {{{ */
$this->items[$item->getID()] = $item;
$this->extracols[$item->getID()] = $extracols;
$this->rawcontents[$item->getID()] = $rawcontent;
$this->filenames[$item->getID()] = $filename;
} /* }}} */
public function createToc($file) { /* {{{ */
@ -190,14 +203,19 @@ class SeedDMS_Download_Mgr {
foreach($this->items as $item) {
$document = $item->getDocument();
$dms = $document->_dms;
$ext = pathinfo($document->getName(), PATHINFO_EXTENSION);
$oext = pathinfo($item->getOriginalFileName(), PATHINFO_EXTENSION);
if($ext == $oext)
$filename = preg_replace('/[^A-Za-z0-9_.-]/', '_', $document->getName());
else {
$filename = preg_replace('/[^A-Za-z0-9_-]/', '_', $document->getName()).'.'.$oext;
if($this->filenames[$item->getID()]) {
$filename = $this->filenames[$item->getID()];
} else {
$ext = pathinfo($document->getName(), PATHINFO_EXTENSION);
$oext = pathinfo($item->getOriginalFileName(), PATHINFO_EXTENSION);
if($ext == $oext)
$filename = preg_replace('/[^A-Za-z0-9_.-]/', '_', $document->getName());
else {
$filename = preg_replace('/[^A-Za-z0-9_-]/', '_', $document->getName()).'.'.$oext;
}
$filename = $document->getID().'-'.$item->getVersion().'-'.$filename; //$lc->getOriginalFileName();
}
$filename = $prefixdir."/".$document->getID().'-'.$item->getVersion().'-'.$filename; //$lc->getOriginalFileName();
$filename = $prefixdir."/".$filename;
if($this->rawcontents[$item->getID()]) {
$zip->addFromString(utf8_decode($filename), $this->rawcontents[$item->getID()]);
} else