From 53e6d5fde32a917718a0658fb95f366dc7dfc248 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 26 Apr 2020 15:41:48 +0200 Subject: user bookmarks use new object + shortcuts visible in backtopbar --- app/fn/fn.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app/fn') diff --git a/app/fn/fn.php b/app/fn/fn.php index 737590f..4ad0c6b 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -87,7 +87,13 @@ function arrayclean($input) return $output; } -function idclean(string $input): string +/** + * Clean string from characters outside `[0-9a-z-_]` and troncate it + * @param string $input + * @param int $max lenght to trucate id + * @return string output formated id + */ +function idclean(string $input, int $max = Wcms\Model::MAX_ID_LENGTH): string { $input = urldecode($input); $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' ']; @@ -96,7 +102,7 @@ function idclean(string $input): string $input = preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input))); - $input = substr($input, 0, Wcms\Model::MAX_ID_LENGTH); + $input = substr($input, 0, $max); return $input; } @@ -335,18 +341,22 @@ function recurse_copy($src, $dst) * * @param array $options as `value => title` * @param string|int $selected value of actualy selected option + * @param bool $title Use title as value. Default : false * * @return string HTML list of options */ -function options(array $options, $selected = null): string +function options(array $options, $selected = null, $title = false): string { $html = ''; foreach ($options as $value => $title) { - if ($value == $selected) { + if ($value === $selected) { $attribute = 'selected'; } else { $attribute = ''; } + if ($title) { + $value = $title; + } $html .= '' . PHP_EOL; } return $html; -- cgit v1.2.3