Commit dfdf717a authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6358 / Copy to clipboard: Implemented F:... - copy file to clipboard.

parent 9fb20689
Pipeline #654 passed with stage
in 1 minute and 48 seconds
...@@ -5100,7 +5100,7 @@ Special column names ...@@ -5100,7 +5100,7 @@ Special column names
| _pdf, _file, _zip |Shortcut version of the link interface for fast creation of `download`_ links. Used to offer single file download or to concatenate several PDFs and printout of websites to one PDF file. | | _pdf, _file, _zip |Shortcut version of the link interface for fast creation of `download`_ links. Used to offer single file download or to concatenate several PDFs and printout of websites to one PDF file. |
| _Pdf, _File, _Zip | | | _Pdf, _File, _Zip | |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _yank | Copy to clipboard. Shortcut version of the link interface | | _yank | `copyToClipboard`_. Shortcut version of the link interface |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _sendmail |Send emails. | | _sendmail |Send emails. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
...@@ -5289,12 +5289,12 @@ Link Examples ...@@ -5289,12 +5289,12 @@ Link Examples
| SELECT "s:1|d:full.pdf|M:pdf|p:id=det1&r=12|p:id=det2|F:cv.pdf| | <a href="typo3conf/ext/qfq/qfq/api/download.php?s=badcaffee1234">Download</a> | | SELECT "s:1|d:full.pdf|M:pdf|p:id=det1&r=12|p:id=det2|F:cv.pdf| | <a href="typo3conf/ext/qfq/qfq/api/download.php?s=badcaffee1234">Download</a> |
| t:Download|a:Create complete PDF - please wait" as _link | | | t:Download|a:Create complete PDF - please wait" as _link | |
+-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| SELECT "y:iatae3Ieem0jeet|t:Password|o:Copy to clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({text: 'iatae3Ieem0jeet'});" title='Copy to clipboard'>Password</button> | | SELECT "y:iatae3Ieem0jeet|t:Password|o:Clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({text: 'iatae3Ieem0jeet'});" title='Copy to clipboard'>Password</button> |
+-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| SELECT "y|F:dir/data.R|t:Data|o:Copy to clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({uri: 'typo3conf/.../download.php?s=badcaffee1234'});" | | SELECT "y|s:1|F:dir/data.R|t:Data|o:Clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({uri: 'typo3conf/.../download.php?s=badcaffee1234'});" |
| | title='Copy to clipboard'>Data</button> | | | title='Copy to clipboard'>Data</button> |
+-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| SELECT "y|p:emails&grId=45|t:Mails|o:Copy to clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({uri: 'indexp.php?id=45&s=badcaffee1234'});" | | SELECT "y|s:1|p:emails&grId=45|t:Mails|o:Clipboard|b" AS _link | <button class="btn btn-info" onClick="new QfqNS.Clipboard({uri: 'indexp.php?id=45&s=badcaffee1234'});" |
| | title='Copy to clipboard'>Mails</button> | | | title='Copy to clipboard'>Mails</button> |
+-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
......
...@@ -22,28 +22,24 @@ require_once(__DIR__ . '/../qfq/exceptions/ErrorHandler.php'); ...@@ -22,28 +22,24 @@ require_once(__DIR__ . '/../qfq/exceptions/ErrorHandler.php');
set_error_handler("\\qfq\\ErrorHandler::exception_error_handler"); set_error_handler("\\qfq\\ErrorHandler::exception_error_handler");
$data = ''; $error = '';
try { try {
try { try {
$download = new \qfq\Download(); $download = new \qfq\Download();
// If all is fine - 'process()' never returns! The output file is delivered and PHP is stopped after that. // If all is fine: process() will output file via print() !!
$data = $download->process(STORE_SIP, OUTPUT_MODE_DIRECT); $error = $download->process(STORE_SIP, OUTPUT_MODE_DIRECT);
if ($download->getOutputFormat() === DOWNLOAD_OUTPUT_FORMAT_JSON) {
$data = json_encode([JSON_TEXT => $data]);
}
} catch (qfq\CodeException $e) { } catch (qfq\CodeException $e) {
$data = $e->formatMessage(); $error = $e->formatMessage();
} catch (qfq\DbException $e) { } catch (qfq\DbException $e) {
$data = $e->formatMessage(); $error = $e->formatMessage();
} catch (qfq\DownloadException $e) { } catch (qfq\DownloadException $e) {
$data = $e->formatMessage(); $error = $e->formatMessage();
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$data = "Exception: " . $e->getMessage(); $error = "Exception: " . $e->getMessage();
} }
echo $data; echo $error;
...@@ -194,7 +194,11 @@ class Download { ...@@ -194,7 +194,11 @@ class Download {
header("Pragma: no-cache"); header("Pragma: no-cache");
header("Expires: 0"); header("Expires: 0");
print file_get_contents($file); if ($this->getOutputFormat() === DOWNLOAD_OUTPUT_FORMAT_JSON) {
print json_encode([JSON_TEXT => file_get_contents($file)]);
} else {
print file_get_contents($file);
}
} }
/** /**
...@@ -373,6 +377,7 @@ class Download { ...@@ -373,6 +377,7 @@ class Download {
case OUTPUT_MODE_DIRECT: case OUTPUT_MODE_DIRECT:
$this->outputFile($filename, $vars[DOWNLOAD_EXPORT_FILENAME]); $this->outputFile($filename, $vars[DOWNLOAD_EXPORT_FILENAME]);
HelperFile::cleanTempFiles([$filename]); HelperFile::cleanTempFiles([$filename]);
$filename='';
break; break;
default: default:
......
...@@ -832,16 +832,13 @@ class Link { ...@@ -832,16 +832,13 @@ class Link {
// CopyToClipboard // CopyToClipboard
if (isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) && $vars[NAME_COPY_TO_CLIPBOARD] === '') { if (isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) && $vars[NAME_COPY_TO_CLIPBOARD] === '') {
// Message in download popup.
// $altText = ($vars[NAME_ALT_TEXT] == '') ? 'Please wait' : addslashes($vars[NAME_ALT_TEXT]);
// $vars[NAME_EXTRA_CONTENT_WRAP] = str_replace(DOWNLOAD_POPUP_REPLACE_TEXT, $altText, $vars[NAME_EXTRA_CONTENT_WRAP]);
// $vars[NAME_EXTRA_CONTENT_WRAP] = str_replace(DOWNLOAD_POPUP_REPLACE_TITLE, 'Download: ' . addslashes($vars[NAME_DOWNLOAD]), $vars[NAME_EXTRA_CONTENT_WRAP]);
$tmpUrlParam = array(); // $tmpUrlParam = array();
$tmpUrlParam[DOWNLOAD_MODE] = DOWNLOAD_MODE_FILE; // $tmpUrlParam[DOWNLOAD_MODE] = DOWNLOAD_MODE_FILE;
$tmpUrlParam[DOWNLOAD_OUTPUT_FORMAT] = DOWNLOAD_OUTPUT_FORMAT_JSON; // $tmpUrlParam[DOWNLOAD_OUTPUT_FORMAT] = DOWNLOAD_OUTPUT_FORMAT_JSON;
$tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS])); // $tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]));
$vars[NAME_URL_PARAM] = KeyValueStringParser::unparse($tmpUrlParam, '=', '&'); // $vars[NAME_URL_PARAM] = KeyValueStringParser::unparse($tmpUrlParam, '=', '&');
return '';
} }
// Delete // Delete
...@@ -1421,26 +1418,37 @@ EOF; ...@@ -1421,26 +1418,37 @@ EOF;
} }
$attributes = Support::doAttribute('class', $bootstrapButton, true); $attributes = Support::doAttribute('class', $bootstrapButton, true);
// Clipboard Source
if ($vars[NAME_COPY_TO_CLIPBOARD] !== '') { if ($vars[NAME_COPY_TO_CLIPBOARD] !== '') {
$source = "{text: '" . $vars[NAME_COPY_TO_CLIPBOARD] ." '}"; $jsAction = 'onClick';
} elseif ($vars[NAME_FILE] !== ''){ $source = "{text: '" . $vars[NAME_COPY_TO_CLIPBOARD] . " '}";
} elseif ($vars[NAME_FILE] !== '') {
$jsAction = 'onmousedown';
$tmpUrlParam = array();
$tmpUrlParam[DOWNLOAD_MODE] = DOWNLOAD_MODE_FILE;
$tmpUrlParam[DOWNLOAD_OUTPUT_FORMAT] = DOWNLOAD_OUTPUT_FORMAT_JSON;
// $tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]));
// $vars[NAME_URL_PARAM] = KeyValueStringParser::unparse($tmpUrlParam, '=', '&');
$tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS])); $tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]));
$urlNParam = KeyValueStringParser::unparse($tmpUrlParam, '=', '&'); $urlNParam = KeyValueStringParser::unparse($tmpUrlParam, '=', '&');
$vars[NAME_URL] = API_DIR . '/' . API_DOWNLOAD_PHP; // $vars[NAME_URL] = API_DIR . '/' . API_DOWNLOAD_PHP;
$paramArray = $this->sip->queryStringToSip($urlNParam, RETURN_ARRAY); $paramArray = $this->sip->queryStringToSip($urlNParam, RETURN_ARRAY);
$urlNParam = $paramArray[SIP_SIP_URL];
if (Support::findInSet(SYSTEM_SHOW_DEBUG_INFO_YES, $this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM))) { if (Support::findInSet(SYSTEM_SHOW_DEBUG_INFO_YES, $this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM))) {
$vars[NAME_TOOL_TIP] .= PHP_EOL . PHP_EOL . $this->sip->debugSip($paramArray); $vars[NAME_TOOL_TIP] .= PHP_EOL . PHP_EOL . $this->sip->debugSip($paramArray);
} }
$source = "{uri: '" .API_DIR . '/' . API_DOWNLOAD_PHP . '&s=' . $paramArray[SIP_SIP_URL] . " '}"; $source = "{uri: '" . API_DIR . '/' . API_DOWNLOAD_PHP . '?s=' . $paramArray[SIP_SIP] . "'}";
} }
$onClick = "onClick=\"new QfqNS.Clipboard($source);\""; // Depending on 'text' or 'file' different JS class are necessary.
// onClick="new QfqNS.Clipboard({text: 'test clipboard'});">
// onmousedown="new QfqNS.Clipboard({uri: 'mockData/downloadResponse.json'});">
$onClick = "$jsAction=\"new QfqNS.Clipboard($source);\"";
// <button class="btn btn-info" // <button class="btn btn-info"
...@@ -1456,7 +1464,7 @@ EOF; ...@@ -1456,7 +1464,7 @@ EOF;
// $vars[NAME_EXTRA_CONTENT_WRAP] = '<button type="button" ' . $attributes . $onClick . '>'; // $vars[NAME_EXTRA_CONTENT_WRAP] = '<button type="button" ' . $attributes . $onClick . '>';
// } else { // } else {
$vars[NAME_EXTRA_CONTENT_WRAP] = '<button ' . $attributes . $onClick . '>'; $vars[NAME_EXTRA_CONTENT_WRAP] = '<button ' . $attributes . $onClick . '>';
$vars[NAME_BOOTSTRAP_BUTTON] = '0'; $vars[NAME_BOOTSTRAP_BUTTON] = '';
// } // }
......
...@@ -282,6 +282,7 @@ class SendMail { ...@@ -282,6 +282,7 @@ class SendMail {
* [ 0 -> 'd:all.pdf', 1 -> 'U:?id=detailPerson&form=Person&r=1&_sip=1', 2 -> 'F:/etc/hostname' ] ] * [ 0 -> 'd:all.pdf', 1 -> 'U:?id=detailPerson&form=Person&r=1&_sip=1', 2 -> 'F:/etc/hostname' ] ]
* @return array Array of filenames. Those files has to be deleted later, if they are temporary files. * @return array Array of filenames. Those files has to be deleted later, if they are temporary files.
* @throws CodeException * @throws CodeException
* @throws DbException
* @throws DownloadException * @throws DownloadException
* @throws UserFormException * @throws UserFormException
* @throws UserReportException * @throws UserReportException
......
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