$value) { switch (substr($key, 0, 1)) { case '-': $rcArgs[$key] = $value; break; case '_': if ($key == DOWNLOAD_SIP_ENCODE_PARAMETER) { $rcSipEncode = true; } break; default: $urlParamNew[$key] = $value; break; } } return $urlParamNew; } /** * Removes new lines (\n) from expressions like {{var:SC0:alnumx}} and replaces them with spaces. * Handles nested expressions like {{SELECT {{var::alnumx}}}} * This function is useful to allow multiline expressions in form definitions such as: * sqlInsert = {{INSERT INTO test (grId) * VALUES(123) }} * * @param $str - the string to be parsed * @return string - the resulting string with new lines in expressions replaced * @throws UserFormException - alerts the user if the delimiters are not balanced */ public static function removeNewlinesInNestedExpression($str) { $delimStart = '{{'; $delimEnd = '}}'; $lastDelimPos = -strlen($delimStart); $exprDepth = 0; // keeps count of the level of expression depth $nestingStart = 0; // Process the string one start/end delimiter at a time while (true) { // find the next start/end delimiter $nextDelimStartPos = strpos($str, $delimStart, $lastDelimPos + strlen($delimStart)); $nextDelimEndPos = strpos($str, $delimEnd, $lastDelimPos + strlen($delimEnd)); if ($nextDelimStartPos === false && $nextDelimEndPos === false) break; $nextDelimPos = min($nextDelimStartPos, $nextDelimEndPos); if ($nextDelimStartPos === false) $nextDelimPos = $nextDelimEndPos; if ($nextDelimEndPos === false) $nextDelimPos = $nextDelimStartPos; if ($nextDelimPos == $nextDelimStartPos) { // opening delimiter if ($exprDepth == 0) $nestingStart = $nextDelimPos; $exprDepth++; } else { // closing delimiter $exprDepth--; if ($exprDepth < 0) { throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Too many closing delimiters '$delimEnd'", ERROR_MESSAGE_SUPPORT => "in '$str'"]), ERROR_MISSING_OPEN_DELIMITER); break; } elseif ($exprDepth == 0) { // end of nesting -> replace \n inside nested expression with space $pre = substr($str, 0, $nestingStart); $nest = substr($str, $nestingStart, $nextDelimPos - $nestingStart); $nestNew = str_replace('\n', ' ', $nest); $post = substr($str, $nextDelimPos); $str = substr($str, 0, $nestingStart) . str_replace("\n", " ", substr($str, $nestingStart, $nextDelimPos - $nestingStart)) . substr($str, $nextDelimPos); } } $lastDelimPos = $nextDelimPos; } if ($exprDepth > 0) { throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Missing close delimiter '$delimEnd'", ERROR_MESSAGE_SUPPORT => "in '$str'"]), ERROR_MISSING_CLOSE_DELIMITER); } return $str; } /** * Split a $_SERVER['PATH_INFO'] of the form '/form1/id1/form2/id2/form3/id3/...)' to * r=id1 * form=form1 * restPath=form2/id2/form3/id3/... * * @param $pathInfo * @return string * @throws UserFormException */ public static function extractFormRecordId($pathInfo) { $text = ''; if ($pathInfo == '') { return ''; } if ($pathInfo[0] == '/') { $pathInfo = substr($pathInfo, 1); } $len = strlen($pathInfo); if ($len > 0 && $pathInfo[$len - 1] == '/') { $pathInfo = substr($pathInfo, 0, $len - 1); } if ($pathInfo == '') { return ''; } $param = explode('/', $pathInfo); $cnt = count($param); if ($cnt % 2 == 0) { $id = array_pop($param); if (!ctype_digit($id)) { throw new UserFormException('Expect numerial id', ERROR_BROKEN_PARAMETER); } $text = TYPO3_RECORD_ID . '=' . $id . PHP_EOL; } $form = array_pop($param); if (!ctype_alnum($form)) { throw new UserFormException('Expect alphanumeric string', ERROR_BROKEN_PARAMETER); } $text .= TYPO3_FORM . '=' . $form . PHP_EOL; if (count($param) > 0) { $text .= TYPO3_REST_PATH . '=' . implode('/', $param) . PHP_EOL; } return $text; } }