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

F6358: Copy to clipboard - static text implemented.

parent 5d49f985
Pipeline #641 passed with stage
in 1 minute and 50 seconds
......@@ -5100,6 +5100,8 @@ 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 | |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _yank | Copy to clipboard. Shortcut version of the link interface |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _sendmail |Send emails. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _exec |Run batch files or executables on the webserver. |
......@@ -5151,6 +5153,9 @@ Column: _link
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
|x | |Download |d:[<exportFilename>] |d:complete.pdf |Link points to `api/download.php`. Additional parameter are encoded into a SIP. 'Download' needs an enabled SIP. See `download`_. |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
|x | |Copy to |y:[some content] |y:this will be copied |Click on it copies the value of 'y:' to the clipboard. Optional a file ('F:...') or Typo3 page ('p:...') might be specified as source. |
| | |clipboard | | |See `copyToClipboard`_. |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Text |t:<text> |t:Firstname Lastname |- |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Render |r:<mode> |r:3 |See: `render-mode`_, Default: 0 |
......@@ -5292,6 +5297,14 @@ 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> |
| 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|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'});" |
| | 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'});" |
| | title='Copy to clipboard'>Mails</button> |
+-----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
.. _question:
......@@ -6028,6 +6041,25 @@ Detailed explanation: monitor_
|<htmlId> |Reference to HTML element to whose content replaced by the retrieve one. |monitor-1 |
+-------------+-------------------------------------------------------------------------------------------+---------------------------+
.. _copyToClipboard:
Copy to clipboard
^^^^^^^^^^^^^^^^^
+-------------------+--------------------------------+----------------------------------------------------------------------------+
| Token | Example | Comment |
+===================+================================+============================================================================+
| y[:<content>] | y, y:some content | Initiates 'copy to clipboard' mode. Source might given text or page or url |
+-------------------+--------------------------------+----------------------------------------------------------------------------+
| F:<pathFilename> | F:fileadmin/protected/data.R | pathFilename in DocumentRoot |
+-------------------+--------------------------------+----------------------------------------------------------------------------+
| p:<pageId&params> | p:emails&grId=45 | Typo3 page which will be fetched on request. |
+-------------------+--------------------------------+----------------------------------------------------------------------------+
| u:<url> | u:http://example.com | Get any URL. E.g. some code from a github site. |
+-------------------+--------------------------------+----------------------------------------------------------------------------+
* Three different sources can be copied to the clipboard.
* 'File' and 'page' are SIP encoded by default.
.. _download:
......
......@@ -429,8 +429,8 @@ const SYSTEM_SHOW_DEBUG_INFO_NO = 'no';
const SYSTEM_SHOW_DEBUG_INFO_AUTO = 'auto'; // Remains on value 'auto' as long as there is no BE User logged in. In other words: 'auto'='no'. #5031
const SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD = 'download';
const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL';
const SYSTEM_CSS_LINK_CLASS_EXTERNAL = 'CSS_LINK_CLASS_EXTERNAL';
//const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL';
//const SYSTEM_CSS_LINK_CLASS_EXTERNAL = 'CSS_LINK_CLASS_EXTERNAL';
const SYSTEM_CSS_CLASS_QFQ_CONTAINER = 'cssClassQfqContainer';
const SYSTEM_CSS_CLASS_QFQ_FORM = 'cssClassQfqForm';
const SYSTEM_CSS_CLASS_QFQ_FORM_PILL = 'cssClassQfqFormPill';
......@@ -785,6 +785,7 @@ const GLYPH_ICON_TASKS = 'glyphicon-tasks';
const GLYPH_ICON_DUPLICATE = 'glyphicon-duplicate';
const GLYPH_ICON_VIEW = 'glyphicon-eye-open';
const GLYPH_ICON_FILE = 'glyphicon-file';
const GLYPH_ICON_COPY = 'glyphicon-copy';
// FORM columns: real
const F_ID = 'id';
......
......@@ -35,15 +35,13 @@ require_once(__DIR__ . '/Thumbnail.php');
/*
* a:AltText
* b:bootstrap button
* b:bootstrap [0|1|<button>]
* B:bullet
* c:class [n|i|e|<class>]
* C:checkbox [name]
* d:download
* D:delete
* e:encryption 0|1
* b:bootstrap [0|1|<button>]
*
* E:edit
* F:File
* g:target
......@@ -54,6 +52,7 @@ require_once(__DIR__ . '/Thumbnail.php');
* M:Mode
* N:new
* o:ToolTip
* O:Monitor
* p:page
* P:picture [file]
* q:question <text>
......@@ -65,9 +64,9 @@ require_once(__DIR__ . '/Thumbnail.php');
* T:Thumbnail
* u:url
* U:URL Param
* v:Copy to clipboard
* W:Dimension
* x:Delete
* y:Copy to clipboard
*
*/
......@@ -77,7 +76,7 @@ const NAME_MAIL = 'mail';
const NAME_PAGE = 'page';
const NAME_TEXT = 'text';
const NAME_DOWNLOAD = DOWNLOAD_EXPORT_FILENAME;
const NAME_DOWNLOAD_ELEMENTS = 'downloadElements'; // array with element sources
const NAME_COLLECT_ELEMENTS = 'downloadElements'; // array with element sources
const NAME_DOWNLOAD_MODE = 'mode';
const NAME_BOOTSTRAP_BUTTON = 'bootstrapButton';
const NAME_ALT_TEXT = 'altText';
......@@ -159,14 +158,15 @@ class Link {
private $phpUnit;
private $renderControl = array();
// private $linkClassSelector = array(TOKEN_CLASS_INTERNAL => "internal ", TOKEN_CLASS_EXTERNAL => "external ");
private $cssLinkClassInternal = '';
private $cssLinkClassExternal = '';
// private $cssLinkClassInternal = '';
// private $cssLinkClassExternal = '';
private $ttContentUid = '';
private $callTable = [
TOKEN_URL => 'buildUrl',
TOKEN_MAIL => 'buildMail',
TOKEN_PAGE => 'buildPage',
TOKEN_COPY_TO_CLIPBOARD => 'buildCopyToClipboard',
TOKEN_DOWNLOAD => 'buildDownload',
TOKEN_TOOL_TIP => 'buildToolTip',
TOKEN_PICTURE => 'buildPicture',
......@@ -270,8 +270,8 @@ class Link {
$this->sip = $sip;
$this->store = Store::getInstance('', $phpUnit);
$this->cssLinkClassInternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_INTERNAL, STORE_SYSTEM);
$this->cssLinkClassExternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_EXTERNAL, STORE_SYSTEM);
// $this->cssLinkClassInternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_INTERNAL, STORE_SYSTEM);
// $this->cssLinkClassExternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_EXTERNAL, STORE_SYSTEM);
$this->ttContentUid = $this->store->getVar(TYPO3_TT_CONTENT_UID, STORE_TYPO3);
$this->dbIndexData = $dbIndexData;
/*
......@@ -367,7 +367,7 @@ class Link {
/**
* Build the whole link.
*
* @param string $str Qualifier with params. 'report'-syntax. F.e.: A:u:www.example.com|G:P:home.gif|t:Home"
* @param string $str Qualifier with params. 'report'-syntax. F.e.: u:www.example.com|P:home.gif|t:Home"
*
* @return string The complete HTML encoded Link like
* <a href='http://example.com' class='external'><img src='iconf.gif' title='help text'>Description</a>
......@@ -386,7 +386,7 @@ class Link {
$vars = $this->fillParameter($str, $tokenGiven);
$vars = $this->processParameter($vars, $tokenGiven);
$mode = $this->getModeRender($vars);
$mode = $this->getModeRender($vars, $tokenGiven);
if (isset($tokenGiven[TOKEN_DOWNLOAD]) && $tokenGiven[TOKEN_DOWNLOAD] === true) {
$this->store->setVar(SYSTEM_DOWNLOAD_POPUP, DOWNLOAD_POPUP_REQUEST, STORE_SYSTEM);
......@@ -492,7 +492,7 @@ class Link {
}
/**
* Iterate over all given token.
* Iterate over all given token. Check for double definition.
*
* @param string $str
* @param array $tokenGiven
......@@ -546,9 +546,10 @@ class Link {
$value = $this->checkValue($key, $value);
// Store value
if (isset($tokenGiven[TOKEN_DOWNLOAD]) && ($key == TOKEN_PAGE || $key == TOKEN_URL || $key == TOKEN_URL_PARAM || $key == TOKEN_FILE || $key == TOKEN_FILE_DEPRECATED)) {
if ((isset($tokenGiven[TOKEN_DOWNLOAD]) || isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD])) &&
($key == TOKEN_PAGE || $key == TOKEN_URL || $key == TOKEN_URL_PARAM || $key == TOKEN_FILE || $key == TOKEN_FILE_DEPRECATED)) {
$vars[NAME_DOWNLOAD_ELEMENTS][] = $key . ':' . $value;
$vars[NAME_COLLECT_ELEMENTS][] = $key . ':' . $value;
unset($tokenGiven[$key]); // Skip Bookkeeping for TOKEN_URL_PARAM | TOKEN_FILE | TOKEN_URL.
continue;
......@@ -559,7 +560,7 @@ class Link {
}
}
// Check for double anchor or picture definition
// Check for double anchor or picture definition.
if (isset($this->tokenMapping[$key])) {
$type = $this->tokenMapping[$key];
......@@ -585,6 +586,11 @@ class Link {
$vars = $this->buildDownloadLate($vars);
}
// CopyToClipboard (Download) Link needs some extra work
if ($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
$vars = $this->buildCopyToClipboardLate($vars);
}
// Final Checks
$this->checkParam($tokenGiven, $vars);
......@@ -617,7 +623,7 @@ class Link {
NAME_URL_PARAM => '',
NAME_EXTRA_CONTENT_WRAP => '',
NAME_DOWNLOAD_MODE => '',
NAME_DOWNLOAD_ELEMENTS => array(),
NAME_COLLECT_ELEMENTS => array(),
NAME_COPY_TO_CLIPBOARD => '',
NAME_RENDER => '0',
......@@ -627,6 +633,7 @@ class Link {
NAME_DELETE => '',
NAME_MONITOR => '0',
NAME_COPY_TO_CLIPBOARD => '',
NAME_LINK_CLASS => '', // class name
NAME_LINK_CLASS_DEFAULT => '', // Depending of 'as page' or 'as url'. Only used if class is not explicit set.
......@@ -722,7 +729,7 @@ class Link {
throw new UserReportException ("Token Mail and Target at the same time not possible'" . TOKEN_PAGE . "'", ERROR_MULTIPLE_DEFINITION);
}
if (isset($tokenGiven[TOKEN_DOWNLOAD]) && count($vars[NAME_DOWNLOAD_ELEMENTS]) == 0) {
if (isset($tokenGiven[TOKEN_DOWNLOAD]) && count($vars[NAME_COLLECT_ELEMENTS]) == 0) {
throw new UserReportException ("Missing element sources for download", ERROR_MISSING_REQUIRED_PARAMETER);
}
}
......@@ -753,20 +760,23 @@ class Link {
}
/**
* Determine DownloadMode: explicit given or detected by given download sources.
* Do some basic checks if parameter are correct.
*
* @param array $vars
*
* @return string
* @return string - DOWNLOAD_MODE_PDF | DOWNLOAD_MODE_ZIP | DOWNLOAD_MODE_FILE | DOWNLOAD_MODE_EXCEL
* @throws UserFormException
*/
private function getDownloadModeNCheck(array $vars) {
$cnt = count($vars[NAME_DOWNLOAD_ELEMENTS]);
$cnt = count($vars[NAME_COLLECT_ELEMENTS]);
$mode = $vars[NAME_DOWNLOAD_MODE];
// Determine default.
if ($mode == '') {
if ($cnt == 1) {
$mode = (substr($vars[NAME_DOWNLOAD_ELEMENTS][0], 0, 1) == TOKEN_FILE_DEPRECATED) ? DOWNLOAD_MODE_FILE : DOWNLOAD_MODE_PDF;
$mode = (substr($vars[NAME_COLLECT_ELEMENTS][0], 0, 1) == TOKEN_FILE_DEPRECATED) ? DOWNLOAD_MODE_FILE : DOWNLOAD_MODE_PDF;
} else {
$mode = DOWNLOAD_MODE_PDF;
}
......@@ -793,7 +803,7 @@ class Link {
}
/**
* Concat final HREF string
* Concat final HREF string. Might be used directly (load new page) or as an AJAX call (e.g. Download).
*
* @param array $vars
* @param array $tokenGiven
......@@ -813,9 +823,24 @@ class Link {
$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[DOWNLOAD_MODE] = $this->getDownloadModeNCheck($vars);
$tmpUrlParam[DOWNLOAD_EXPORT_FILENAME] = $vars[NAME_DOWNLOAD];
$tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_DOWNLOAD_ELEMENTS]));
$tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]));
$vars[NAME_URL_PARAM] = KeyValueStringParser::unparse($tmpUrlParam, '=', '&');
}
// CopyToClipboard
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[DOWNLOAD_MODE] = DOWNLOAD_MODE_FILE;
// $tmpUrlParam[DOWNLOAD_EXPORT_FILENAME] = $vars[NAME_DOWNLOAD];
$tmpUrlParam[SIP_DOWNLOAD_PARAMETER] = base64_encode(implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]));
$vars[NAME_URL_PARAM] = KeyValueStringParser::unparse($tmpUrlParam, '=', '&');
}
......@@ -836,7 +861,7 @@ class Link {
$vars[NAME_URL_PARAM] .= PARAM_DB_INDEX_DATA . '=' . $this->dbIndexData;
}
// Normalize '?pagealias' to 'index.php?pagealias'
// Normalize '?pageAlias' to 'index.php?pageAlias'
if (substr($vars[NAME_URL], 0, 1) === '?') {
$vars[NAME_URL] = INDEX_PHP . $vars[NAME_URL];
}
......@@ -1000,8 +1025,8 @@ class Link {
private function doContent(array $vars) {
$arr = array();
if($vars[NAME_MONITOR]=='1'){
$monitor =new Monitor();
if ($vars[NAME_MONITOR] == '1') {
$monitor = new Monitor();
return $monitor->process($vars);
}
......@@ -1129,13 +1154,17 @@ EOF;
* Get mode from table $this->renderControl, depending on $modeRender, $modeUrl, $modeText
*
* @param array $vars
* @param string $prefix
*
* @param array $tokenGiven
* @return string
* @throws UserReportException
*/
private function getModeRender(array $vars, $prefix = '') {
private function getModeRender(array $vars, array $tokenGiven ) {
if($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]){
if($vars[NAME_RENDER]=='0'){
$vars[NAME_RENDER]= RENDER_MODE_1;
}
}
$modeRender = $vars[NAME_RENDER];
$modeUrl = ($vars[FINAL_HREF] === '') ? 0 : 1;
$modeText = ($vars[FINAL_CONTENT] === '') ? 0 : 1;
......@@ -1259,7 +1288,8 @@ EOF;
* @return array
*/
private function buildUrl($vars, $value) {
$vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
// $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
$vars[NAME_LINK_CLASS_DEFAULT] = '';
return $vars;
}
......@@ -1273,7 +1303,8 @@ EOF;
* @return array
*/
private function buildMail($vars, $value) {
$vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
// $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
$vars[NAME_LINK_CLASS_DEFAULT] = '';
return $vars;
}
......@@ -1293,7 +1324,8 @@ EOF;
}
$vars[NAME_PAGE] = Support::concatUrlParam('', $value);
$vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassInternal;
$vars[NAME_LINK_CLASS_DEFAULT] = '';
// $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassInternal;
return $vars;
}
......@@ -1311,6 +1343,19 @@ EOF;
return $vars;
}
/**
* Called by $this->callTable
*
* @param $vars
* @param $value
*
* @return array
*/
private function buildCopyToClipboard($vars, $value) {
return $vars;
}
/**
* @param $vars
* @return array
......@@ -1346,10 +1391,56 @@ EOF;
$vars[NAME_URL] = API_DIR . '/' . API_DOWNLOAD_PHP;
$vars[NAME_LINK_CLASS_DEFAULT] = NO_CLASS;
$vars[NAME_EXTRA_CONTENT_WRAP] = '<span ' . $attributes . $onClick . '>';
$vars[NAME_BOOTSTRAP_BUTTON] = '0';
return $vars;
}
/**
* @param $vars
* @return array
* @throws CodeException
*/
private function buildCopyToClipboardLate($vars) {
if ($vars[NAME_BOOTSTRAP_BUTTON] == '') {
$vars = $this->buildBootstrapButton($vars, '');
}
$bootstrapButton = $vars[NAME_BOOTSTRAP_BUTTON];
if ($vars[NAME_BOOTSTRAP_BUTTON] == '0') {
$bootstrapButton = '';
$vars[NAME_GLYPH] = '';
$vars[NAME_EXTRA_CONTENT_WRAP] = '';
} else {
$vars[NAME_GLYPH] = GLYPH_ICON_COPY;
$vars[NAME_GLYPH_TITLE] = "Copy to clipboard";
}
$attributes = Support::doAttribute('class', $bootstrapButton, true);
if ($vars[NAME_COPY_TO_CLIPBOARD] !== '') {
$value = $vars[NAME_COPY_TO_CLIPBOARD];
$onClick = <<<EOF
onClick="new QfqNS.Clipboard({text: '$value'});"
EOF;
}
// <button class="btn btn-info"
// onClick="new QfqNS.Clipboard({text: 'test clipboard'});">
// Test Clipboard
// </button>
// $vars[NAME_URL] = API_DIR . '/' . API_DOWNLOAD_PHP;
// $vars[NAME_LINK_CLASS_DEFAULT] = NO_CLASS;
// if ($vars[NAME_BOOTSTRAP_BUTTON] == '0') {
// $vars[NAME_EXTRA_CONTENT_WRAP] = '<button type="button" ' . $attributes . $onClick . '>';
// } else {
$vars[NAME_EXTRA_CONTENT_WRAP] = '<span ' . $attributes . $onClick . '>';
$vars[NAME_EXTRA_CONTENT_WRAP] = '<button ' . $attributes . $onClick . '>';
$vars[NAME_BOOTSTRAP_BUTTON] = '0';
// }
......@@ -1602,6 +1693,11 @@ EOF;
/**
* Called by $this->callTable
* Parameter: b:?
*
* 0 : no button, do nothing, return $vars unchanged
* '': default
* 'success', 'btn-success': 'btn btn-success'
*
* @param $vars
* @param $value
......
Markdown is supported
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