diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-26 15:41:48 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-26 15:41:48 +0200 |
commit | 53e6d5fde32a917718a0658fb95f366dc7dfc248 (patch) | |
tree | 6510be3ee713a444a477aef8faf60a62fb47b165 /app/fn/fn.php | |
parent | 0efeef6b6693d62675ec8a45e73c71f69e0a0362 (diff) | |
download | wcms-53e6d5fde32a917718a0658fb95f366dc7dfc248.tar.gz wcms-53e6d5fde32a917718a0658fb95f366dc7dfc248.zip |
user bookmarks use new object
+ shortcuts visible in backtopbar
Diffstat (limited to 'app/fn/fn.php')
-rw-r--r-- | app/fn/fn.php | 18 |
1 files changed, 14 insertions, 4 deletions
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 .= '<option value="' . $value . '" ' . $attribute . '>' . $title . '</option>' . PHP_EOL; } return $html; |