/** * Get the regular expression used to validate usernames. * * @return string Returns a regular expression without enclosing delimiters. */ function validateUsernameRegex() { static $ValidateUsernameRegex; if (is_null($ValidateUsernameRegex)) { // Set our default ValidationRegex based on Unicode support. // Unicode includes Numbers, Letters, Marks, & Connector punctuation. $DefaultPattern = unicodeRegexSupport() ? '\\p{N}\\p{L}\\p{M}\\p{Pc}' : '\\w'; $ValidateUsernameRegex = sprintf("[%s]%s", c("Garden.User.ValidationRegex", $DefaultPattern), c("Garden.User.ValidationLength", "{3,20}")); } return $ValidateUsernameRegex; }
/** * Creates URL codes containing only lowercase Roman letters, digits, and hyphens. * * @param mixed $Mixed An object, array, or string to be formatted. * @return string */ public static function url($Mixed) { if (!is_string($Mixed)) { return self::to($Mixed, 'Url'); } // Preliminary decoding $Mixed = strip_tags(html_entity_decode($Mixed, ENT_COMPAT, 'UTF-8')); $Mixed = strtr($Mixed, self::$_UrlTranslations); $Mixed = preg_replace('`[\']`', '', $Mixed); // Convert punctuation, symbols, and spaces to hyphens if (unicodeRegexSupport()) { $Mixed = preg_replace('`[\\pP\\pS\\s]`u', '-', $Mixed); } else { $Mixed = preg_replace('`[\\W_]`', '-', $Mixed); } // Lowercase, no trailing or repeat hyphens $Mixed = preg_replace('`-+`', '-', strtolower($Mixed)); $Mixed = trim($Mixed, '-'); return rawurlencode($Mixed); }
/** * Import from CustomProfileFields or upgrade from ProfileExtender 2.0. */ public function setup() { if ($Fields = c('Plugins.ProfileExtender.ProfileFields', c('Plugins.CustomProfileFields.SuggestedFields'))) { // Get defaults $Hidden = c('Plugins.ProfileExtender.HideFields', c('Plugins.CustomProfileFields.HideFields')); $OnRegister = c('Plugins.ProfileExtender.RegistrationFields'); $Length = c('Plugins.ProfileExtender.TextMaxLength', c('Plugins.CustomProfileFields.ValueLength')); // Convert to arrays $Fields = array_filter((array) explode(',', $Fields)); $Hidden = array_filter((array) explode(',', $Hidden)); $OnRegister = array_filter((array) explode(',', $OnRegister)); // Assign new data structure $NewData = array(); foreach ($Fields as $Field) { if (unicodeRegexSupport()) { $regex = '/[^\\pL\\pN]/u'; } else { $regex = '/[^a-z\\d]/i'; } // Make unique slug $Name = $TestSlug = preg_replace($regex, '', $Field); $i = 1; // Fallback in case the name is empty if (empty($Name)) { $Name = $TestSlug = md5($Field); } while (array_key_exists($Name, $NewData) || in_array($Name, $this->ReservedNames)) { $Name = $TestSlug . $i++; } // Convert $NewData[$Name] = array('Label' => $Field, 'Length' => $Length, 'FormType' => 'TextBox', 'OnProfile' => in_array($Field, $Hidden) ? 0 : 1, 'OnRegister' => in_array($Field, $OnRegister) ? 1 : 0, 'OnDiscussion' => 0, 'Required' => 0, 'Locked' => 0, 'Sort' => 0); } saveToConfig('ProfileExtender.Fields', $NewData); } }