Commit 720eb76b authored by Carsten  Rose's avatar Carsten Rose
Browse files

Implements #6793. Source files for ZIP archives might now specified with a...

Implements #6793. Source files for ZIP archives might now specified with a path/filename how they are called inside the ZIP.
parent 1e03320f
Pipeline #4866 passed with stages
in 4 minutes and 39 seconds
......@@ -1506,24 +1506,42 @@ Most of the other Link-Class attributes can be used to customize the link. ::
10.sql = SELECT "[options]" AS _pdf, "[options]" AS _file, "[options]" AS _zip
with: [options] = [d:<exportFilename][|p:<params>][|U:<params>][|u:<url>][|F:file][|t:<text>][|a:<message>][|o:<tooltip>][|c:<class>][|r:<render mode>]
with: [options] = [d:<exportFilename][|p:<params>][|U:<params>][|u:<url>][|F:file[:path/file in zip]][|t:<text>][|a:<message>][|o:<tooltip>][|c:<class>][|r:<render mode>]
* Parameter are position independent.
* *<params>*: see :ref:`download-parameter-files`
* For column `_pdf` and `_zip`, the element sources `p:...`, `U:...`, `u:...`, `F:...` might repeated multiple times.
* For column `_zip`, an optional parameter might define the path and filename inside the ZIP: `F:<orig filename>:<inside ZIP path and filename>`
* To only render the page content without menus add the parameter `type=2`. For example: `U:id=pageToPrint&type=2&_sip=1&r=', r.id`
* Example::
10.sql = SELECT "F:fileadmin/test.pdf" as _pdf, "F:fileadmin/test.pdf" as _file, "F:fileadmin/test.pdf" as _zip
10.sql = SELECT "p:id=export&r=1" as _pdf, "p:id=export&r=1" as _file, "p:id=export&r=1" as _zip
# ... AS _file
10.sql = SELECT "F:fileadmin/test.pdf" as _pdf
20.sql = SELECT "p:id=export&r=1" as _pdf
30.sql = SELECT "t:Download PDF|F:fileadmin/test.pdf" as _pdf
40.sql = SELECT "t:Download PDF|p:id=export&r=1" as _pdf
50.sql = SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _pdf
60.sql = SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test.pdf|p:id=export&r=1|u:www.example.com" AS _pdf
# ... AS _file
100.sql = SELECT "F:fileadmin/test.pdf" as _file
110.sql = SELECT "p:id=export&r=1" as _file
120.sql = SELECT "t:Download PDF|F:fileadmin/test.pdf" as _file
130.sql = SELECT "t:Download PDF|p:id=export&r=1" as _file
140.sql = SELECT
150.sql = SELECT
# ... AS _zip
200.sql = SELECT "F:fileadmin/test.pdf" as _zip
210.sql = SELECT "p:id=export&r=1" as _zip
220.sql = SELECT "t:Download ZIP|F:fileadmin/test.pdf" as _zip
230.sql = SELECT "t:Download ZIP|p:id=export&r=1" as _zip
# Several files
240.sql = SELECT "d:complete.zip|t:Download ZIP|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _zip
# Several files with new path/filename
250.sql = SELECT "d:complete.zip|t:Download ZIP|F:fileadmin/test1.pdf:data/file-1.pdf|F:fileadmin/test2.pdf:data/file-2.pdf" as _zip
10.sql = SELECT "t:Download PDF|F:fileadmin/test.pdf" as _pdf, "t:Download PDF|F:fileadmin/test.pdf" as _file, "t:Download ZIP|F:fileadmin/test.pdf" as _zip
10.sql = SELECT "t:Download PDF|p:id=export&r=1" as _pdf, "t:Download PDF|p:id=export&r=1" as _file, "t:Download ZIP|p:id=export&r=1" as _zip
10.sql = SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _pdf, "d:complete.zip|t:Download ZIP|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _zip
10.sql = SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test.pdf|p:id=export&r=1|u:www.example.com" AS _pdf
.. _column-save-pdf:
......
......@@ -355,7 +355,7 @@ class Download {
/**
* Interprets $element and fetches corresponding content, either as a file or the content in a variable.
*
* @param string $element - U:id=myExport&r=12, u:http://www.nzz.ch/issue?nr=21, f:fileadmin/sample.pdf
* @param string $element - U:id=myExport&r=12, u:http://www.nzz.ch/issue?nr=21, F:fileadmin/sample.pdf
*
* @param string $downloadMode - DOWNLOAD_MODE_EXCEL | ....
* @param string $rcData - With $downloadMode=DOWNLOAD_MODE_EXCEL, this contains the rendered code from the given T3 page.
......@@ -497,15 +497,17 @@ class Download {
$len = strlen(TMP_FILE_PREFIX);
$ii = 1;
foreach ($files as $filename) {
$localName = substr($filename, strrpos($filename, '/') + 1);
foreach ($files as $item) {
$arr = explode(PARAM_TOKEN_DELIMITER, $item);
$filename = $arr[0] ?? '';
$localName = ($arr[1] == '') ? substr($filename, strrpos($filename, '/') + 1) : $arr[1];
if (substr($localName, 0, $len) == TMP_FILE_PREFIX) {
$localName = 'file-' . $ii;
$ii++;
}
$zip->addFile($filename, $localName);
$zip->addFile($filename, Sanitize::safeFilename($localName, false, true));
}
$zip->close();
......
......@@ -18,6 +18,33 @@ use PHPUnit\Framework\TestCase;
*/
class TokenTest extends TestCase {
public function testExplodeTokenString() {
// Edge cases: flagAssoc=true
$this->assertEquals(array(), Token::explodeTokenString(''));
$this->assertEquals([' ' => ''], Token::explodeTokenString(' '));
$this->assertEquals(['' => ''], Token::explodeTokenString(':'));
$this->assertEquals(['' => '::'], Token::explodeTokenString(':::'));
$this->assertEquals(array(), Token::explodeTokenString('|'));
$this->assertEquals(array(), Token::explodeTokenString('|||'));
$this->assertEquals(['1' => ''], Token::explodeTokenString('1'));
$this->assertEquals(['T' => ''], Token::explodeTokenString('T:'));
$this->assertEquals(['T' => '', 'W' => ''], Token::explodeTokenString('T|W'));
$this->assertEquals(['T' => '', 'W' => ''], Token::explodeTokenString('||T|W||'));
// Regular
$this->assertEquals(['T' => 'arg1'], Token::explodeTokenString('T:arg1'));
$this->assertEquals(['T' => 'arg1', 'W' => 'arg2'], Token::explodeTokenString('T:arg1|W:arg2'));
$this->assertEquals(['T' => 'arg1:arg1.1', 'W' => 'arg2'], Token::explodeTokenString('T:arg1:arg1.1|W:arg2'));
$this->assertEquals(['T' => ':arg1:arg1.1::', 'W' => 'arg2'], Token::explodeTokenString('T::arg1:arg1.1::|W:arg2'));
}
public function testExplodeDimension() {
$this->assertEquals('', Token::explodeDimension(''));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment