aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-02-07 18:53:51 -0800
committerfriendica <info@friendica.com>2013-02-07 18:53:51 -0800
commit82ed07baa14690611835b2e9becfb3330396c581 (patch)
tree89b83faf64d8122386afd06db644976364bb9a04
parentbf4b964aeb93eaefa7e11cd69918dc8ac7393f0d (diff)
downloadvolse-hubzilla-82ed07baa14690611835b2e9becfb3330396c581.tar.gz
volse-hubzilla-82ed07baa14690611835b2e9becfb3330396c581.tar.bz2
volse-hubzilla-82ed07baa14690611835b2e9becfb3330396c581.zip
provide a global way of enforcing name policy restrictions, but only enforce empty names or length > storage size. Allow plugins to set other policies. In particular, you can't have an empty channel name now, but one char is legal ;-)
-rw-r--r--include/identity.php25
-rw-r--r--mod/settings.php10
2 files changed, 31 insertions, 4 deletions
diff --git a/include/identity.php b/include/identity.php
index a66929b63..bfe908a40 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -24,6 +24,25 @@ function identity_check_service_class($account_id) {
return $ret;
}
+// Return an error message if the name is not valid. We're currently only checking
+// for an empty name or one that exceeds our storage limit (255 chars).
+// 255 chars is probably going to create a mess on some pages.
+// Plugins can set additional policies such as full name requirements, character sets, multi-byte
+// length, etc.
+
+function validate_channelname($name) {
+
+ if(! $name)
+ return t('Empty name');
+ if(strlen($name) > 255)
+ return t('Name too long');
+ $arr = array('name' => $name);
+ call_hooks('validate_channelname',$arr);
+ if(x($arr,'message'))
+ return $arr['message'];
+ return;
+}
+
// Required: name, nickname, account_id
@@ -43,6 +62,12 @@ function create_identity($arr) {
$name = escape_tags($arr['name']);
$pageflags = ((x($arr,'pageflags')) ? intval($arr['pageflags']) : PAGE_NORMAL);
+ $name_error = validate_channelname($arr['name']);
+ if($name_error) {
+ $ret['message'] = $name_error;
+ return $ret;
+ }
+
if(check_webbie(array($nick)) !== $nick) {
$ret['message'] = t('Nickname has unsupported characters or is already being used on this site.');
return $ret;
diff --git a/mod/settings.php b/mod/settings.php
index ea914cbac..d2dd57b18 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -429,10 +429,12 @@ function settings_post(&$a) {
if($username != $channel['channel_name']) {
$name_change = true;
- if(mb_strlen($username) > 40)
- $err .= t(' Please use a shorter name.');
- if(mb_strlen($username) < 3)
- $err .= t(' Name too short.');
+ require_once('include/identity.php');
+ $err = validate_channelname($username);
+ if($err) {
+ notice($err);
+ return;
+ }
}