Commit 97e88238 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Support.php: add concatUrlParam().

Link.php: simplyfied Tooltip creation - might be broken now for non URL - there are no unit  tests for these situation. New: if no tooltip is given, and a link of type [Pp]age? - take the glyph name as tooltip. Render all links, which use a hash and with showDebugInfo='yes' , with the decoded sip as tooltip.
Sip.php: queryStringToSip() extend to return complete paramter array.
parent ae782037
......@@ -37,6 +37,7 @@ const SESSION_FE_USER_UID = 'fe_user_uid';
const RETURN_URL = 'return_url';
const RETURN_SIP = 'return_sip';
const RETURN_ARRAY = 'return_array';
const SQL_FORM_ELEMENT_SPECIFIC_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
const SQL_FORM_ELEMENT_ALL_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
......
......@@ -237,5 +237,16 @@ class Support {
return ($string);
}
/**
* @param $url
* @param $param
* @return string
*/
public static function concatUrlParam($url, $param) {
if ($param == '')
return $url;
$token = (strpos($url, '?') === false) ? '?' : '&';
return $url . $token . $param;
}
}
\ No newline at end of file
......@@ -182,7 +182,7 @@ class Link {
$this->utils = new Utils();
$this->varsDefault[NAME_QUESTION] = 'Please confirm';
$this->varsDefault[NAME_PAGE] = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
// $this->varsDefault[NAME_PAGE] = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
$this->varsDefault[NAME_ENCRYPTION] = '0';
$this->varsDefault[NAME_RIGHT_PICTURE_POSITION] = 'l';
$this->varsDefault[NAME_RENDER] = 0;
......@@ -274,6 +274,11 @@ class Link {
$this->doCssClass($vars);
// Set default tooltip
if ($vars[NAME_TOOL_TIP] == '' && $vars[NAME_GLYPH_TITLE] !== '') {
$vars[NAME_TOOL_TIP] = $vars[NAME_GLYPH_TITLE];
}
$htmlUrl = $this->doAnchor($vars);
$htmlImage = $this->doHtmlImageGlyph($vars);
......@@ -517,7 +522,6 @@ class Link {
private function doAnchor(array &$vars) {
$attributes = '';
// build URL
$htmlUrl = "";
$anchorTitle = '';
// Link: URL
......@@ -525,18 +529,18 @@ class Link {
if ($vars[NAME_HASH] === "1") {
$vars[NAME_URL] = $this->sip->queryStringToSip($vars[NAME_PAGE] . '&' . $vars[NAME_URL_PARAM]);
$paramArray = $this->sip->queryStringToSip(Support::concatUrlParam($vars[NAME_URL], $vars[NAME_URL_PARAM]), RETURN_ARRAY);
$vars[NAME_URL] = $paramArray['_url'];
if ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') {
$vars[NAME_TOOL_TIP] .= PHP_EOL . PHP_EOL . OnArray::toString($paramArray, ' = ', PHP_EOL, "'");
$this->buildToolTip($vars, 'o', $vars[NAME_TOOL_TIP]);
}
} else {
if ($vars[NAME_URL_PARAM] != '') {
// Append '&' or '?' depending if there is already a '?'
$vars[NAME_URL] .= (strpos($vars[NAME_URL], '?') >= 0) ? '&' : '?';
// Append all additional params.
$vars[NAME_URL] .= $vars[NAME_URL_PARAM];
$vars[NAME_URL] = Support::concatUrlParam($vars[NAME_URL], $vars[NAME_URL_PARAM]);
}
}
}
......@@ -556,23 +560,25 @@ class Link {
if ($vars[NAME_GLYPH] !== '') {
$vars[NAME_LINK_CLASS] .= ' btn btn-default ';
if ($vars[NAME_GLYPH_TITLE] !== '') {
$anchorTitle = $vars[NAME_GLYPH_TITLE];
}
// if ($vars[NAME_GLYPH_TITLE] !== '') {
// $anchorTitle = $vars[NAME_GLYPH_TITLE];
// }
}
$attributes .= Support::doAttribute('href', $vars[NAME_URL]);
$attributes .= Support::doAttribute('class', $vars[NAME_LINK_CLASS]);
$attributes .= Support::doAttribute('target', $vars[NAME_TARGET]);
$attributes .= Support::doAttribute('title', $anchorTitle);
// $attributes .= Support::doAttribute('title', $anchorTitle);
$attributes .= Support::doAttribute('title', $vars[NAME_TOOL_TIP]);
if ($vars[NAME_QUESTION]) {
$attributes .= Support::doAttribute('onclick', 'confirm(\'' . $vars[NAME_QUESTION] . '\')');
}
$htmlUrl = '<a ' . $attributes . $vars[NAME_TOOL_TIP_JS][0] . '>';
// $anchor = '<a ' . $attributes . $vars[NAME_TOOL_TIP_JS][0] . '>';
$anchor = '<a ' . $attributes . '>';
return ($htmlUrl);
return ($anchor);
}
//
......@@ -584,6 +590,34 @@ class Link {
// <img src="typo3conf/ext/qfq/Resources/Public/icons/edit.gif" title="Edit" >
//</a>
/**
* Create a ToolTip: $toolTip[0] and $toolTip[1] have to inserted in HTML code accordingly.
* $vars[NAME_TOOL_TIP_JS][0]: JS to show '$toolTip[1]'.
* $vars[NAME_TOOL_TIP_JS][1]: '<span>...</span>' with the tooltip text.
*
* @param $vars
* @param $key
* @param $value
*/
private function buildToolTip(&$vars, $key, $value) {
static $count = 0;
$toolTipIndex = 'tooltip.' . $GLOBALS["TSFE"]->currentRecord . '.' . ++$count;
$vars[NAME_TOOL_TIP_JS] = array();
// Expample: <img src="fileadmin/icons/bullet-gray.gif" onmouseover="document.getElementById('gm167979').style.
// display='block';" onmouseout="document.getElementById('gm167979').style.display='none';" />
$vars[NAME_TOOL_TIP_JS][0] = " onmouseover=\"document.getElementById('" . $toolTipIndex .
"').style.display='block';\" onmouseout=\"document.getElementById('" . $toolTipIndex . "').style.display='none';\"";
// Example: <span id="gm167979" style="display:none; position:absolute; border:solid 1px black; background-color:#F9F3D0;
// padding:3px;">My pesonal tooltip</span>
$vars[NAME_TOOL_TIP_JS][1] = '<span id="' . $toolTipIndex .
'" style="display:none; position:absolute; border:solid 1px black; background-color:#F9F3D0; padding:3px;">' .
$value . '</span>';
return;
}
/**
* Create Image HTML Tag
......@@ -813,7 +847,6 @@ class Link {
$vars[NAME_LINK_CLASS_DEFAULT] = NO_CLASS;
}
/**
* Called by $this->callTable
*
......@@ -881,33 +914,4 @@ class Link {
}
/**
* Create a ToolTip: $toolTip[0] and $toolTip[1] have to inserted in HTML code accordingly.
* $vars[NAME_TOOL_TIP_JS][0]: JS to show '$toolTip[1]'.
* $vars[NAME_TOOL_TIP_JS][1]: '<span>...</span>' with the tooltip text.
*
* @param $vars
* @param $key
* @param $value
*/
private function buildToolTip(&$vars, $key, $value) {
static $count = 0;
$toolTipIndex = 'tooltip.' . $GLOBALS["TSFE"]->currentRecord . '.' . ++$count;
$vars[NAME_TOOL_TIP_JS] = array();
// Expample: <img src="fileadmin/icons/bullet-gray.gif" onmouseover="document.getElementById('gm167979').style.
// display='block';" onmouseout="document.getElementById('gm167979').style.display='none';" />
$vars[NAME_TOOL_TIP_JS][0] = " onmouseover=\"document.getElementById('" . $toolTipIndex .
"').style.display='block';\" onmouseout=\"document.getElementById('" . $toolTipIndex . "').style.display='none';\"";
// Example: <span id="gm167979" style="display:none; position:absolute; border:solid 1px black; background-color:#F9F3D0;
// padding:3px;">My pesonal tooltip</span>
$vars[NAME_TOOL_TIP_JS][1] = '<span id="' . $toolTipIndex .
'" style="display:none; position:absolute; border:solid 1px black; background-color:#F9F3D0; padding:3px;">' .
$value . '</span>';
return;
}
}
\ No newline at end of file
......@@ -64,9 +64,10 @@ class Sip {
* * a=1&s=4b3403665fea6&r=45&type=99&id=person
*
* @param string $mode Possible values: RETURN_URL|RETURN_SIP
* @return string
* @return string/array
* * mode=RETURN_URL: return complete URL
* * mode=RETURN_SIP: returns only the sip
* * mode=RETURN_ARRAY: returns array with url ('_url') and all decoded and created parameters.
* @throws CodeException
* @throws UserFormException
*/
......@@ -103,17 +104,29 @@ class Sip {
$_SESSION[$s] = $sipParamString;
}
if ($mode == RETURN_URL) {
// Append SIP to final parameter
$clientArray[CLIENT_SIP] = $s;
if ($script[0] === '?')
$script = $scriptName . $script;
return $script . OnArray::toString($clientArray);
} else {
return $s;
// Append SIP to final parameter
$clientArray[CLIENT_SIP] = $s;
if ($script[0] === '?')
$script = $scriptName . $script;
$clientArray['_url'] = $script . OnArray::toString($clientArray);
switch ($mode) {
case RETURN_URL:
$rc = $clientArray['_url'];
break;
case RETURN_SIP:
$rc = $s;
break;
case RETURN_ARRAY:
$rc = array_merge($clientArray, $sipArray);
break;
default:
throw new CodeException('Unknown Mode: "' . $mode . '"', ERROR_UNKNOWN_MODE);
}
return $rc;
}
/**
......
......@@ -143,6 +143,29 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
}
}
public function testConcatUrlParam() {
$url = Support::concatUrlParam('', '');
$this->assertEquals('', $url);
$url = Support::concatUrlParam('http://example.com', '');
$this->assertEquals('http://example.com', $url);
$url = Support::concatUrlParam('', 'a=1');
$this->assertEquals('?a=1', $url);
$url = Support::concatUrlParam('http://example.com', 'a=100');
$this->assertEquals('http://example.com?a=100', $url);
$url = Support::concatUrlParam('http://example.com?id=2', 'a=100');
$this->assertEquals('http://example.com?id=2&a=100', $url);
$url = Support::concatUrlParam('http://example.com', 'a=100&b=201');
$this->assertEquals('http://example.com?a=100&b=201', $url);
$url = Support::concatUrlParam('http://example.com?id=34', 'a=100&b=201');
$this->assertEquals('http://example.com?id=34&a=100&b=201', $url);
}
protected function setUp() {
parent::setUp();
......
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