Settings: Add configurable shortcode length constraint

This commit is contained in:
Celestora 2021-10-13 23:41:12 +03:00
parent 1a0454c01f
commit b39dd44143
2 changed files with 7 additions and 4 deletions

View file

@ -662,9 +662,11 @@ class User extends RowModel
$this->stateChanges("left_menu", $mask); $this->stateChanges("left_menu", $mask);
} }
function setShortCode(?string $code = NULL): ?bool function setShortCode(?string $code = NULL, bool $force = false): ?bool
{ {
if(!is_null($code)) { if(!is_null($code)) {
if(strlen($code) < OPENVK_ROOT_CONF["openvk"]["preferences"]["shortcodes"]["minLength"] && !$force)
return false;
if(!preg_match("%^[a-z][a-z0-9\\.\\_]{0,30}[a-z0-9]$%", $code)) if(!preg_match("%^[a-z][a-z0-9\\.\\_]{0,30}[a-z0-9]$%", $code))
return false; return false;
if(in_array($code, OPENVK_ROOT_CONF["openvk"]["preferences"]["shortcodes"]["forbiddenNames"])) if(in_array($code, OPENVK_ROOT_CONF["openvk"]["preferences"]["shortcodes"]["forbiddenNames"]))

View file

@ -10,6 +10,7 @@ openvk:
disableLargeUploads: false disableLargeUploads: false
mode: "basic" mode: "basic"
shortcodes: shortcodes:
minLength: 3 # won't affect existing short urls or the ones set via admin panel
forbiddenNames: forbiddenNames:
- "index.php" - "index.php"
security: security: