本文整理汇总了PHP中Validate::string方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::string方法的具体用法?PHP Validate::string怎么用?PHP Validate::string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate($values)
{
$return = true;
$validate = new Validate();
if (!$validate->string($values['navn'], array('min_length' => 1))) {
$return = false;
}
if (!$validate->string($values['adresse'], array('min_length' => 1))) {
$return = false;
}
if (!$validate->number($values['postnr'], array('min' => 100))) {
$return = false;
}
if (!$validate->string($values['postby'], array('min_length' => 1))) {
$return = false;
}
if (!empty($values['email']) and !$validate->email($values['email'])) {
$return = false;
}
/*
if (isset($values['langekurser']) != "" && $values['langekurser'] != "1") $return = false;
if (isset($values['kortekurser']) != "" && $values['kortekurser'] != "1") $return = false;
if (isset($values['efterskole']) != "" && $values['efterskole'] != "1") $return = false;
if (isset($values['kursuscenter']) != "" && $values['kursuscenter'] != "1") $return = false;
*/
return $return;
}
示例2: validate
/**
* @return bool
* @throws Exception
*/
public function validate()
{
if ($this->id && !Validate::number($this->id)) {
throw new Exception('Invalid Id!');
}
if ($this->name && !Validate::string($this->name)) {
throw new Exception('Invalid Name');
}
if ($this->language && !Validate::string($this->language)) {
throw new Exception('Invalid Language');
}
if ($this->genre && !Validate::string($this->genre)) {
throw new Exception('Invalid Genre');
}
if ($this->author && !Validate::string($this->author)) {
throw new Exception('Invalid Author');
}
if ($this->publish_date && !Validate::number($this->publish_date)) {
if (!Validate::date($this->publish_date)) {
throw new Exception('Invalid Publish Date');
}
$this->publish_date = strtotime($this->publish_date);
}
return true;
}
示例3: validate
protected function validate($var)
{
$return = true;
$validate = new Validate();
if (!$validate->string($var['navn'], array('min_length' => 1))) {
$return = false;
}
return $return;
}
示例4: dni
/**
* Valida un DNI Español (el dni tiene que ser de la forma 11111111X)
*
* @param string $dni El Documento Nacional de Indentidad a chequear
* @return bool
*/
function dni($dni)
{
$letra = substr($dni, -1);
$number = substr($dni, 0, -1);
if (!Validate::string($number, VALIDATE_NUM, 8, 8)) {
return false;
}
if (!Validate::string($letra, VALIDATE_ALPHA)) {
return false;
}
// El resto entero de la division del numero del dni/23 +1
// es la posicion de la letra en la cadena $string
$string = 'TRWAGMYFPDXBNJZSQVHLCKET';
// ver la letra de un numero
if ($letra == $string[$number % 23]) {
return true;
}
return false;
}
示例5: update_profile
function update_profile($req, $consumer, $token)
{
$version = $req->get_parameter('omb_version');
if ($version != OMB_VERSION_01) {
$this->clientError(_('Unsupported OMB version'), 400);
return false;
}
# First, check to see if listenee exists
$listenee = $req->get_parameter('omb_listenee');
$remote = Remote_profile::staticGet('uri', $listenee);
if (!$remote) {
$this->clientError(_('Profile unknown'), 404);
return false;
}
# Second, check to see if they should be able to post updates!
# We see if there are any subscriptions to that remote user with
# the given token.
$sub = new Subscription();
$sub->subscribed = $remote->id;
$sub->token = $token->key;
if (!$sub->find(true)) {
$this->clientError(_('You did not send us that profile'), 403);
return false;
}
$profile = Profile::staticGet('id', $remote->id);
if (!$profile) {
# This one is our fault
$this->serverError(_('Remote profile with no matching profile'), 500);
return false;
}
$nickname = $req->get_parameter('omb_listenee_nickname');
if ($nickname && !Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
$this->clientError(_('Nickname must have only lowercase letters and numbers and no spaces.'));
return false;
}
$license = $req->get_parameter('omb_listenee_license');
if ($license && !common_valid_http_url($license)) {
$this->clientError(sprintf(_("Invalid license URL '%s'"), $license));
return false;
}
$profile_url = $req->get_parameter('omb_listenee_profile');
if ($profile_url && !common_valid_http_url($profile_url)) {
$this->clientError(sprintf(_("Invalid profile URL '%s'."), $profile_url));
return false;
}
# optional stuff
$fullname = $req->get_parameter('omb_listenee_fullname');
if ($fullname && mb_strlen($fullname) > 255) {
$this->clientError(_("Full name is too long (max 255 chars)."));
return false;
}
$homepage = $req->get_parameter('omb_listenee_homepage');
if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
$this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage));
return false;
}
$bio = $req->get_parameter('omb_listenee_bio');
if ($bio && mb_strlen($bio) > 140) {
$this->clientError(_("Bio is too long (max 140 chars)."));
return false;
}
$location = $req->get_parameter('omb_listenee_location');
if ($location && mb_strlen($location) > 255) {
$this->clientError(_("Location is too long (max 255 chars)."));
return false;
}
$avatar = $req->get_parameter('omb_listenee_avatar');
if ($avatar) {
if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
$this->clientError(sprintf(_("Invalid avatar URL '%s'"), $avatar));
return false;
}
$size = @getimagesize($avatar);
if (!$size) {
$this->clientError(sprintf(_("Can't read avatar URL '%s'"), $avatar));
return false;
}
if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
$this->clientError(sprintf(_("Wrong size image at '%s'"), $avatar));
return false;
}
if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
$this->clientError(sprintf(_("Wrong image type for '%s'"), $avatar));
return false;
}
}
$orig_profile = clone $profile;
/* Use values even if they are an empty string. Parsing an empty string in
updateProfile is the specified way of clearing a parameter in OMB. */
if (!is_null($nickname)) {
$profile->nickname = $nickname;
}
if (!is_null($profile_url)) {
$profile->profileurl = $profile_url;
}
if (!is_null($fullname)) {
$profile->fullname = $fullname;
}
if (!is_null($homepage)) {
$profile->homepage = $homepage;
//.........这里部分代码省略.........
示例6: validateAliases
function validateAliases()
{
$aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $this->aliasstring)));
if (count($aliases) > common_config('group', 'maxaliases')) {
// TRANS: API validation exception thrown when aliases do not validate.
// TRANS: %d is the maximum number of aliases and used for plural.
throw new ApiValidationException(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
}
foreach ($aliases as $alias) {
if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
throw new ApiValidationException(sprintf(_('Invalid alias: "%s".'), $alias));
}
if ($this->nicknameExists($alias)) {
throw new ApiValidationException(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
}
// XXX assumes alphanum nicknames
if (strcmp($alias, $this->nickname) == 0) {
throw new ApiValidationException(_('Alias cannot be the same as nickname.'));
}
}
return $aliases;
}
示例7: tryRegister
/**
* Try to register a user
*
* Validates the input and tries to save a new user and profile
* record. On success, shows an instructions page.
*
* @return void
*/
function tryRegister()
{
if (Event::handle('StartRegistrationTry', array($this))) {
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('网页错误,请返回重试
'));
return;
}
$nickname = $this->trimmed('nickname');
$type = $this->trimmed('type');
$email = $this->trimmed('email');
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
// We don't trim these... whitespace is OK in a password!
$password = $this->arg('password');
$confirm = $this->arg('confirm');
// invitation code, if any
$code = $this->trimmed('code');
if ($code) {
$invite = Invitation::staticGet($code);
}
if (common_config('site', 'inviteonly') && !($code && $invite)) {
$this->clientError(_('Sorry, only invited people can register.'));
return;
}
// Input scrubbing
$nickname = common_canonical_nickname($nickname);
$email = common_canonical_email($email);
if (!$this->boolean('license')) {
$this->showForm(_('You can\'t register if you don\'t ' . 'agree to the license.'));
} else {
if ($email && !Validate::email($email, common_config('email', 'check_domain'))) {
$this->showForm(_('Not a valid email address.'));
} else {
if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
$this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
} else {
if ($this->nicknameExists($nickname)) {
$this->showForm(_('Nickname already in use. Try another one.'));
} else {
if (!User::allowed_nickname($nickname)) {
$this->showForm(_('Not a valid nickname.'));
} else {
if ($this->emailExists($email)) {
$this->showForm(_('Email address already exists.'));
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
} else {
if (Profile::bioTooLong($bio)) {
$this->showForm(sprintf(_('Bio is too long (max %d chars).'), Profile::maxBio()));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
} else {
if (strlen($password) < 6) {
$this->showForm(_('Password must be 6 or more characters.'));
return;
} else {
if ($password != $confirm) {
$this->showForm(_('Passwords don\'t match.'));
} else {
if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $code, 'type' => $type))) {
if (!$user) {
$this->showForm(_('Invalid username or password.'));
return;
}
// success!
if (!common_set_user($user)) {
$this->serverError(_('Error setting user.'));
return;
}
// this is a real login
common_real_login(true);
if ($this->boolean('rememberme')) {
common_debug('Adding rememberme cookie for ' . $nickname);
common_rememberme($user);
}
Event::handle('EndRegistrationTry', array($this));
// Re-init language env in case it changed (not yet, but soon)
common_init_language();
$this->showSuccess();
//.........这里部分代码省略.........
示例8: setLocation
public function setLocation($location)
{
if ($location === '') {
$location = null;
} elseif (!Validate::string($location, array('max_length' => 255))) {
throw new OMB_InvalidParameterException($location, 'profile', 'fullname');
}
$this->location = $location;
$this->param_array = false;
}
示例9: dodaj
public function dodaj($arg = false)
{
echo "Dodajam..";
//get user id
Session::init();
$userid = Session::get('userid');
if ($userid == "") {
$redirect = sprintf("location: %sprijava", STATIC_URL);
header($redirect);
exit;
}
//parse POST variables add validation here
$kratek_opis = $_POST['kratek_opis'];
$datum = $_POST['date'];
$podrocje = $_POST['podrocje'];
$opis = $_POST['opis'];
$tel = $_POST['tel'];
//echo $kratek_opis, $datum, $podrocje, $opis, $tel, $userid;
//inicialize model
require 'models/prijava_tezave.php';
$model = new Prijava_Tezave_Model();
//validate
$validation = "succeded";
$validate = new Validate();
if ($validate->string($kratek_opis) != 1) {
$validation = "failed";
$this->view->errors['kratek_opis'] = "Vnesite naslov težave";
}
if (!$validate->date($datum, 'm/d/Y')) {
$validation = "failed";
$this->view->errors['datum'] = "Izberite datum";
}
if ($validate->string($podrocje) != 1) {
$validation = "failed";
$this->view->errors['podrocje'] = "Vnesite področje na katerem imate težavo";
}
if ($validate->string($opis) != 1) {
$validation = "failed";
$this->view->errors['opis'] = "Vnesite opis vaše težave";
}
if ($validate->phone($tel) != 1) {
$validation = "failed";
$this->view->errors['tel'] = "Telefonska številka ni prave oblike";
}
/*samples
var_dump($validate->email('test@arnes.si'));
var_dump($validate->phone('031 772-079'));
var_dump($validate->date('01/30/2014'));
var_dump($validate->date('30/01/2012', 'd/m/Y'));
var_dump($validate->string('test'));*/
//$validation = "failed";
if ($validation == "failed") {
$this->view->values['kratek_opis'] = $kratek_opis;
$this->view->values['datum'] = $datum;
$this->view->values['podrocje'] = $podrocje;
$this->view->values['opis'] = $opis;
$this->view->values['tel'] = $tel;
$this->view->render('user/prijava_tezave');
exit;
}
//insert into database
$this->view->result = $model->dodaj($kratek_opis, $datum, $podrocje, $opis, $tel, $userid);
if ($this->view->result == 1) {
//$this->view->msg="Zahtevek uspešno dodan.";
//$this->view->render('user/zahtevki');
$redirect = sprintf("location: %szahtevki", STATIC_URL);
header($redirect);
exit;
} else {
$this->view->render('user/prijava_tezave');
exit;
}
//$this->view->render('user/zahtevki');
//header($redirect);
//exit();
}
示例10: validate
/**
* validate - override this to set up your validation rules
*
* validate the current objects values either just testing strings/numbers or
* using the user defined validate{Row name}() methods.
* will attempt to call $this->validate{column_name}() - expects true = ok false = ERROR
* you can the use the validate Class from your own methods.
*
* This should really be in a extenal class - eg. DB_DataObject_Validate.
*
* @access public
* @return array of validation results or true
*/
function validate()
{
require_once 'Validate.php';
$table = $this->table();
$ret = array();
$seq = $this->sequenceKey();
foreach ($table as $key => $val) {
// call user defined validation always...
$method = "Validate" . ucfirst($key);
if (method_exists($this, $method)) {
$ret[$key] = $this->{$method}();
continue;
}
// if not null - and it's not set.......
if (!isset($this->{$key}) && $val & DB_DATAOBJECT_NOTNULL) {
// dont check empty sequence key values..
if ($key == $seq[0] && $seq[1] == true) {
continue;
}
$ret[$key] = false;
continue;
}
if (is_string($this->{$key}) && strtolower($this->{$key}) == 'null' && $val & DB_DATAOBJECT_NOTNULL) {
$ret[$key] = false;
continue;
}
// ignore things that are not set. ?
if (!isset($this->{$key})) {
continue;
}
// if the string is empty.. assume it is ok..
if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) {
continue;
}
switch (true) {
// todo: date time.....
case $val & DB_DATAOBJECT_STR:
$ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME);
continue;
case $val & DB_DATAOBJECT_INT:
$ret[$key] = Validate::number($this->{$key}, array('decimal' => '.'));
continue;
}
}
foreach ($ret as $key => $val) {
if ($val === false) {
return $ret;
}
}
return true;
// everything is OK.
}
示例11: validate
/**
* validate the values of the object (usually prior to inserting/updating..)
*
* Note: This was always intended as a simple validation routine.
* It lacks understanding of field length, whether you are inserting or updating (and hence null key values)
*
* This should be moved to another class: DB_DataObject_Validate
* FEEL FREE TO SEND ME YOUR VERSION FOR CONSIDERATION!!!
*
* Usage:
* if (is_array($ret = $obj->validate())) { ... there are problems with the data ... }
*
* Logic:
* - defaults to only testing strings/numbers if numbers or strings are the correct type and null values are correct
* - validate Column methods : "validate{ROWNAME}()" are called if they are defined.
* These methods should return
* true = everything ok
* false|object = something is wrong!
*
* - This method loads and uses the PEAR Validate Class.
*
*
* @access public
* @return array of validation results (where key=>value, value=false|object if it failed) or true (if they all succeeded)
*/
function validate()
{
global $_DB_DATAOBJECT;
require_once 'Validate.php';
$table = $this->table();
$ret = array();
$seq = $this->sequenceKey();
$options = $_DB_DATAOBJECT['CONFIG'];
foreach ($table as $key => $val) {
// call user defined validation always...
$method = "Validate" . ucfirst($key);
if (method_exists($this, $method)) {
$ret[$key] = $this->{$method}();
continue;
}
// if not null - and it's not set.......
if ($val & DB_DATAOBJECT_NOTNULL && DB_DataObject::_is_null($this, $key)) {
// dont check empty sequence key values..
if ($key == $seq[0] && $seq[1] == true) {
continue;
}
$ret[$key] = false;
continue;
}
if (DB_DataObject::_is_null($this, $key)) {
if ($val & DB_DATAOBJECT_NOTNULL) {
$this->debug("'null' field used for '{$key}', but it is defined as NOT NULL", 'VALIDATION', 4);
$ret[$key] = false;
continue;
}
continue;
}
// ignore things that are not set. ?
if (!isset($this->{$key})) {
continue;
}
// if the string is empty.. assume it is ok..
if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) {
continue;
}
// dont try and validate cast objects - assume they are problably ok..
if (is_object($this->{$key}) && is_a($this->{$key}, 'DB_DataObject_Cast')) {
continue;
}
// at this point if you have set something to an object, and it's not expected
// the Validate will probably break!!... - rightly so! (your design is broken,
// so issuing a runtime error like PEAR_Error is probably not appropriate..
switch (true) {
// todo: date time.....
case $val & DB_DATAOBJECT_STR:
$ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME);
continue;
case $val & DB_DATAOBJECT_INT:
$ret[$key] = Validate::number($this->{$key}, array('decimal' => '.'));
continue;
}
}
// if any of the results are false or an object (eg. PEAR_Error).. then return the array..
foreach ($ret as $key => $val) {
if ($val !== true) {
return $ret;
}
}
return true;
// everything is OK.
}
示例12: isNewNickname
function isNewNickname($str)
{
if (!Validate::string($str, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
return false;
}
if (!User::allowed_nickname($str)) {
return false;
}
if (User::staticGet('nickname', $str)) {
return false;
}
return true;
}
示例13: handlePost
/**
* Handle a post
*
* Validate input and save changes. Reload the form with a success
* or error message.
*
* @return void
*/
function handlePost()
{
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
return;
}
if (Event::handle('StartProfileSaveForm', array($this))) {
$nickname = $this->trimmed('nickname');
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
$autosubscribe = $this->boolean('autosubscribe');
$language = $this->trimmed('language');
$timezone = $this->trimmed('timezone');
$tagstring = $this->trimmed('tags');
// Some validation
if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
$this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
return;
} else {
if (!User::allowed_nickname($nickname)) {
$this->showForm(_('Not a valid nickname.'));
return;
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
} else {
if (Profile::bioTooLong($bio)) {
$this->showForm(sprintf(_('Bio is too long (max %d chars).'), Profile::maxBio()));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
} else {
if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
$this->showForm(_('Timezone not selected.'));
return;
} else {
if ($this->nicknameExists($nickname)) {
$this->showForm(_('Nickname already in use. Try another one.'));
return;
} else {
if (!is_null($language) && strlen($language) > 50) {
$this->showForm(_('Language is too long (max 50 chars).'));
return;
}
}
}
}
}
}
}
}
}
if ($tagstring) {
$tags = array_map('common_canonical_tag', preg_split('/[\\s,]+/', $tagstring));
} else {
$tags = array();
}
foreach ($tags as $tag) {
if (!common_valid_profile_tag($tag)) {
$this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
return;
}
}
$user = common_current_user();
$user->query('BEGIN');
if ($user->nickname != $nickname || $user->language != $language || $user->timezone != $timezone) {
common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, __FILE__);
common_debug('Updating user language from ' . $user->language . ' to ' . $language, __FILE__);
common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, __FILE__);
$original = clone $user;
$user->nickname = $nickname;
$user->language = $language;
$user->timezone = $timezone;
$result = $user->updateKeys($original);
if ($result === false) {
common_log_db_error($user, 'UPDATE', __FILE__);
$this->serverError(_('Couldn\'t update user.'));
return;
} else {
// Re-initialize language environment if it changed
common_init_language();
//.........这里部分代码省略.........
示例14: _validateCurrency
/** Validate the order amount currency
*
* The abbrivation for a currency, usually 2-3 chars
*
* @access private
* @return boolean true if valid, false otherwise
*/
function _validateCurrency()
{
return Validate::string($this->currency, array('format' => VALIDATE_ALPHA_UPPER, 'min_length' => 2, 'max_length' => 3));
}
示例15: trySave
function trySave()
{
$nickname = $this->trimmed('nickname');
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$description = $this->trimmed('description');
$location = $this->trimmed('location');
$aliasstring = $this->trimmed('aliases');
if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
$this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
return;
} else {
if ($this->nicknameExists($nickname)) {
$this->showForm(_('Nickname already in use. Try another one.'));
return;
} else {
if (!User_group::allowedNickname($nickname)) {
$this->showForm(_('Not a valid nickname.'));
return;
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
} else {
if (User_group::descriptionTooLong($description)) {
$this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
}
}
}
}
}
}
}
if (!empty($aliasstring)) {
$aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
} else {
$aliases = array();
}
if (count($aliases) > common_config('group', 'maxaliases')) {
$this->showForm(sprintf(_('Too many aliases! Maximum %d.'), common_config('group', 'maxaliases')));
return;
}
foreach ($aliases as $alias) {
if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
$this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
return;
}
if ($this->nicknameExists($alias)) {
$this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
return;
}
// XXX assumes alphanum nicknames
if (strcmp($alias, $nickname) == 0) {
$this->showForm(_('Alias can\'t be the same as nickname.'));
return;
}
}
$mainpage = common_local_url('showgroup', array('nickname' => $nickname));
$cur = common_current_user();
// Checked in prepare() above
assert(!is_null($cur));
$group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $cur->id, 'mainpage' => $mainpage, 'local' => true));
common_redirect($group->homeUrl(), 303);
}