diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index 1b4578d9292b887b2a4ca80abb3ed31afcc9a14e..6a7137ab7fd33b494b8e6a488567b9bbca19bc82 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -2409,6 +2409,41 @@ function generer_url_action($script, $args = '', $no_entities = false, $public = } +/** + * Créer une URL + * + * @param string $script + * Nom du script à exécuter + * @param string $args + * Arguments à transmettre a l'URL sous la forme `arg1=yy&arg2=zz` + * @param bool $no_entities + * Si false : transforme les & en & + * @param boolean $public + * URL public ou relative a l'espace ou l'on est ? + * @return string + * URL + */ +function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) { + if (is_null($public)) { + $public = (_DIR_RACINE ? false : ''); + } + if (substr($script, -4) !== '.api') { + $script .= '.api'; + } + $url = + (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') + . $script . '/' + . ($path ? trim($path, '/') : '') + . ($args ? "?" . quote_amp('&' . $args) : ''); + + if ($no_entities) { + $url = str_replace('&', '&', $url); + } + + return $url; +} + + /** * Fonction d'initialisation groupée pour compatibilité ascendante *