aboutsummaryrefslogtreecommitdiff
path: root/app/fn/fn.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-04-26 15:41:48 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-04-26 15:41:48 +0200
commit53e6d5fde32a917718a0658fb95f366dc7dfc248 (patch)
tree6510be3ee713a444a477aef8faf60a62fb47b165 /app/fn/fn.php
parent0efeef6b6693d62675ec8a45e73c71f69e0a0362 (diff)
downloadwcms-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.php18
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;