diff --git a/Documentation/Report.rst b/Documentation/Report.rst index 179736ea1e4681d3f21d2d3a6beae1b7441c2115..f3aa5a842bfdaebbc8e25cc8f54068b464fd9a0a 100644 --- a/Documentation/Report.rst +++ b/Documentation/Report.rst @@ -1411,21 +1411,21 @@ Run a php function defined in an external script. * All column parameters are passed as an associative array to the function as the first argument. * The second argument (here called $qfq) is an object which acts as an interface to QFQ functionality. * The script has access to the following qfq functions using this interface: - * $qfq::apiCall($method, $url, $data = [], $header = [], $timeout = 5) - * string $method can be PUT/POST/GET/DELETE + * $qfq::apiCall($method, $url, $data = '', $header = [], $timeout = 5) + * string $method: can be PUT/POST/GET/DELETE * string $url - * array $data a json string which will be added as GET parameters or as POST fields respectively. - * array $header is of the form ['Content-type: text/plain', 'Content-length: 100'] - * int $timeout is the number of seconds to wait until call is aborted. + * string $data: a json string which will be added as GET parameters or as POST fields respectively. + * array $header: is of the form ['Content-type: text/plain', 'Content-length: 100'] + * int $timeout: is the number of seconds to wait until call is aborted. * $qfq::getVar($key, $useStores = 'FSRVD', $sanitizeClass = '', &$foundInStore = '', $typeMessageViolate = 'c') - * string $key is the name of qfq variable - * string $useStores are the stores in which variable is searched (in order from left to right). see :ref:`store`. - * string $sanitizeClass (see :ref:`sanitize-class`) - * string $foundInStore is filled with the name of the store in which the variable was found. - * string $typeMessageViolate defines what to return if the sanitize class was violated: - * 'c': return '!!<sanitize class>!!' - * '0': return '0' - * 'e': return '' + * string $key: is the name of qfq variable + * string $useStores: are the stores in which variable is searched (in order from left to right). see :ref:`store`. + * string $sanitizeClass: (see :ref:`sanitize-class`) + * string $foundInStore: is filled with the name of the store in which the variable was found. + * string $typeMessageViolate: defines what to return if the sanitize class was violated: + * 'c' : returns '!!<sanitize class>!!' + * '0' : returns '0' + * 'e' : returns '' * The current working directory is the current web instance (e.g. ``/var/www/html``) . * All output (e.g. using echo) will be returned by the special column as is. * If the function returns an associative array, then the key-value pairs will be accessible via the Client store. @@ -1436,11 +1436,11 @@ Run a php function defined in an external script. +-------------------+----------------------------------------------------+------------------------------------------------------------------+ | Token | Example | Comment | +===================+====================================================+==================================================================+ -| scr | scr:fileadmin/scripts/my_script.php | Path to the custom script relative to the current web instance | +| F | F:fileadmin/scripts/my_script.php | Path to the custom script relative to the current web instance | +-------------------+----------------------------------------------------+------------------------------------------------------------------+ -| f | f:my_function | Function name | +| c | c:my_function | PHP function to call | +-------------------+----------------------------------------------------+------------------------------------------------------------------+ -| <whatever> | myParameter:something | All parameters are passed on in an associative array | +| <whatever> | myParameter:something | all parameters are passed on as an array to the function | +-------------------+----------------------------------------------------+------------------------------------------------------------------+ **Example** @@ -1467,13 +1467,13 @@ Run a php function defined in an external script. * QFQ report :: 5.sql = SELECT "IAmInRecordStore" AS _savedInRecordStore - 10.sql = SELECT "scr:fileadmin/scripts/my_script.php|f:my_function|a1:Hello|a2:World" AS _script + 10.sql = SELECT "F:fileadmin/scripts/my_script.php|c:my_function|a1:Hello|a2:World" AS _script 20.sql = SELECT "<br><br>Returened value: {{IAmInClientStore:C:alnumx}}" * Output :: The first argument contains all attributes including "src" and "f": - Array ( [scr] => fileadmin/scripts/my_script.php [f] => my_function [a1] => Hello [a2] => World ) + Array ( [F] => fileadmin/scripts/my_script.php [c] => my_function [a1] => Hello [a2] => World ) get variable from record store: IAmInRecordStore diff --git a/extension/Classes/Core/Constants.php b/extension/Classes/Core/Constants.php index c0729ad2f70cc8f2b1884bea8bddfa96de0d6084..691ccbdc908d64d7381b090c8e6c1a8dd5a84891 100644 --- a/extension/Classes/Core/Constants.php +++ b/extension/Classes/Core/Constants.php @@ -1774,7 +1774,7 @@ const TOKEN_COPY_TO_CLIPBOARD = 'y'; const TOKEN_DROPDOWN = 'z'; const TOKEN_WEBSOCKET = 'w'; const TOKEN_REST_CLIENT = 'n'; -const TOKEN_SCRIPT = 'scr'; +const TOKEN_SCRIPT = 'F'; const TOKEN_TEXT = 't'; const TOKEN_ALT_TEXT = 'a'; @@ -1802,7 +1802,7 @@ const TOKEN_FILE = 'F'; const TOKEN_FILE_DEPRECATED = 'f'; // since 5.12.17 const TOKEN_DOWNLOAD_MODE = 'M'; const TOKEN_ATTRIBUTE = 'A'; -const TOKEN_FUNCTION = 'f'; +const TOKEN_FUNCTION_CALL = 'c'; const TOKEN_THUMBNAIL = 'T'; const TOKEN_THUMBNAIL_DIMENSION = 'W'; diff --git a/extension/Classes/Core/Report/ColumnScript.php b/extension/Classes/Core/Report/ColumnScript.php index a74e72210b80165abccc0033d63cd452885c3395..2ae4cb8240660d0d9113070a21fe1580d1a08636 100644 --- a/extension/Classes/Core/Report/ColumnScript.php +++ b/extension/Classes/Core/Report/ColumnScript.php @@ -25,7 +25,7 @@ class ColumnScript { if (empty($param[TOKEN_SCRIPT])) { throw new \UserReportException("Missing script path.", ERROR_MISSING_VALUE); } - if (empty($param[TOKEN_FUNCTION])) { + if (empty($param[TOKEN_FUNCTION_CALL])) { throw new \UserReportException("Missing function name.", ERROR_MISSING_VALUE); } @@ -46,18 +46,18 @@ class ColumnScript { } // execute function, write output to buffer - if (!function_exists($param[TOKEN_FUNCTION])) { + if (!function_exists($param[TOKEN_FUNCTION_CALL])) { throw new \UserReportException("Function doesn't exist.", ERROR_IO_READ_FILE); } ob_start(); try { - $return = call_user_func_array($param[TOKEN_FUNCTION], [$param, new ScriptFunctions()]); + $return = call_user_func_array($param[TOKEN_FUNCTION_CALL], [$param, new ScriptFunctions()]); $output = ob_get_clean(); } catch (\Exception | \Error $e) { ob_end_clean(); throw new \UserReportException(json_encode([ ERROR_MESSAGE_TO_USER => 'Function execution failed.', - ERROR_MESSAGE_TO_DEVELOPER => "Error message:\n" . $e->getMessage() . "\n\nFunction: " . $param[TOKEN_FUNCTION] . "\n\nParameters:\n" . print_r($param,true)])); + ERROR_MESSAGE_TO_DEVELOPER => "Error message:\n" . $e->getMessage() . "\n\nFunction: " . $param[TOKEN_FUNCTION_CALL] . "\n\nParameters:\n" . print_r($param,true)])); } // return buffer output and fill store diff --git a/extension/Classes/Core/Report/RestClient.php b/extension/Classes/Core/Report/RestClient.php index 22ef971378ba3ecee06007917c587483a677542a..ff56ce8cb26b2160532c0e870b0eeac2e351c3c7 100644 --- a/extension/Classes/Core/Report/RestClient.php +++ b/extension/Classes/Core/Report/RestClient.php @@ -106,15 +106,6 @@ class RestClient { $header = []; } - if (strpos($param[TOKEN_L_HEADER], 'content-type:') === false) { - $mime = (($param[TOKEN_L_CONTENT][0] ?? '') == '{') ? 'application/json' : 'text/plain'; - $header[] = 'content-type: ' . $mime . '; charset=utf-8'; - } - - if (strpos($param[TOKEN_L_HEADER], 'connection:') === false) { - $header[] = 'connection: close'; - } - // If 'Host' is missing in header: define - useful for Firewall/ Proxy // CR: if a header 'host' is given, REST calls fails always. // if (strpos($param[TOKEN_L_HEADER], 'host:') === false) { @@ -128,6 +119,17 @@ class RestClient { public static function callApiCurl(string $method, string $url, string $data = '', array $header = [], int $timeout = 5) { + // Header: Set content-type if not set + if (strpos(join('', $header), 'content-type:') === false) { + $mime = (($data[0] ?? '') == '{') ? 'application/json' : 'text/plain'; + $header[] = 'content-type: ' . $mime . '; charset=utf-8'; + } + + // Header: Set connection if not set + if (strpos(join('', $header), 'connection:') === false) { + $header[] = 'connection: close'; + } + $ch = curl_init(); $curlConfig = array( CURLOPT_RETURNTRANSFER => true,