From 5b82041dfd625ff6476646f372106b12cdd7f642 Mon Sep 17 00:00:00 2001 From: Carsten Rose Date: Sun, 19 May 2019 12:26:01 +0200 Subject: [PATCH 1/3] Refs #8348 - first implementation for Bootstrap dropdown menu's - fully SIP supported. --- extension/Source/core/Constants.php | 1 + extension/Source/core/report/Link.php | 130 +++++++++++++++++- extension/Tests/unit/core/report/LinkTest.php | 28 ++++ 3 files changed, 154 insertions(+), 5 deletions(-) diff --git a/extension/Source/core/Constants.php b/extension/Source/core/Constants.php index 1f4dda2e..c1de8636 100644 --- a/extension/Source/core/Constants.php +++ b/extension/Source/core/Constants.php @@ -1595,6 +1595,7 @@ const TOKEN_PAGE = 'p'; const TOKEN_UID = 'uid'; const TOKEN_DOWNLOAD = 'd'; const TOKEN_COPY_TO_CLIPBOARD = 'y'; +const TOKEN_DROPDOWN = 'z'; const TOKEN_TEXT = 't'; const TOKEN_ALT_TEXT = 'a'; diff --git a/extension/Source/core/report/Link.php b/extension/Source/core/report/Link.php index b24a3986..affc99c2 100644 --- a/extension/Source/core/report/Link.php +++ b/extension/Source/core/report/Link.php @@ -43,19 +43,30 @@ require_once(__DIR__ . '/Thumbnail.php'); * D:delete * e:encryption 0|1 * E:edit + * f: * F:File * g:target * G:Glyph + * h: * H:Help + * i: * I:information + * j: + * J: + * k: + * K: + * l: + * L: * m:mailto * M:Mode + * n: * N:new * o:ToolTip * O:Monitor * p:page * P:picture [file] * q:question + * Q: * r:render * R:right * s:sip @@ -64,18 +75,25 @@ require_once(__DIR__ . '/Thumbnail.php'); * T:Thumbnail * u:url * U:URL Param + * v: + * V: + * w: * W:Dimension * x:Delete + * X: * y:Copy to clipboard + * Y: + * z:DropDown Menu + * Z: * */ - const NAME_URL = 'url'; const NAME_MAIL = 'mail'; const NAME_PAGE = 'page'; const NAME_UID = 'uid'; const NAME_TEXT = 'text'; +const NAME_DROPDOWN = 'dropdown'; const NAME_DOWNLOAD = DOWNLOAD_EXPORT_FILENAME; const NAME_COLLECT_ELEMENTS = 'downloadElements'; // array with element sources const NAME_DOWNLOAD_MODE = 'mode'; @@ -171,6 +189,7 @@ class Link { TOKEN_PAGE => 'buildPage', TOKEN_COPY_TO_CLIPBOARD => 'buildCopyToClipboard', TOKEN_DOWNLOAD => 'buildDownload', + TOKEN_DROPDOWN => 'buildDropdown', TOKEN_TOOL_TIP => 'buildToolTip', TOKEN_PICTURE => 'buildPicture', TOKEN_BULLET => 'buildBullet', @@ -193,6 +212,7 @@ class Link { TOKEN_MAIL => NAME_MAIL, TOKEN_PAGE => NAME_PAGE, TOKEN_UID => NAME_UID, + TOKEN_DROPDOWN => NAME_DROPDOWN, TOKEN_DOWNLOAD => NAME_DOWNLOAD, TOKEN_DOWNLOAD_MODE => NAME_DOWNLOAD_MODE, TOKEN_TEXT => NAME_TEXT, @@ -371,6 +391,101 @@ class Link { } + /** + * @param string $str + * + * @return string + * @throws CodeException + * @throws UserFormException + * @throws UserReportException + */ + private function processDropdown($str) { + $menuHtml = ''; + $menuEntryStrArr = array(); + $menuEntryLinkArr = array(); + $tokenCollect = array(); + $dropdownStr = null; + + $paramArr = KeyValueStringParser::explodeEscape(PARAM_DELIMITER, $str); + + // Iterate over token. Find delimiter to separate dropdown definition and all menu entries. + foreach ($paramArr as $tokenStr) { + $tokenArr = explode(PARAM_TOKEN_DELIMITER, $tokenStr, 2); + switch ($tokenArr[0] ?? '') { + // No further need: skip + case TOKEN_DROPDOWN: + break; + + // Indicator to start menu entry: force a flush of existing token and start a new round. + case TOKEN_URL: + case TOKEN_MAIL: + case TOKEN_PAGE: + case TOKEN_DOWNLOAD: + case TOKEN_COPY_TO_CLIPBOARD: + case '': + // New menu entry + $menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect); + $tokenCollect = array(); + $tokenCollect[] = $tokenStr; + break; + + default: + $tokenCollect[] = $tokenStr; + } + } + + // Flush remaining element + $menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect); + $dropdownStr = array_shift($menuEntryStrArr); + + // For each menu entry get the link + foreach ($menuEntryStrArr as $str) { + $menuEntryLinkArr[] = $this->renderLink($str); + } + + return $this->renderDropdown($dropdownStr, $menuEntryLinkArr); + + } + + /** + * Start + * + * + * + * + * + * End + * + * @param $dropdownStr + * @param $menuEntryLinkArr + * @return string + */ + private function renderDropdown($dropdownStr, $menuEntryLinkArr) { + static $count = 0; + $time = microtime(false); + + if (defined('PHPUNIT_QFQ')) { + $time = '0.123 1234'; + } + $htmlId = $time . $count++; + + $tmp = ''; + foreach ($menuEntryLinkArr as $link) { + $tmp .= '
  • ' . $link . '
  • '; + } + + $ul = Support::wrapTag('