+
+ /**
+ * Is the given string in our nickname blacklist?
+ *
+ * @param string $str
+ * @return boolean
+ */
+ public static function isBlacklisted($str)
+ {
+ $blacklist = common_config('nickname', 'blacklist');
+ return in_array($str, $blacklist);
+ }
+
+ /**
+ * Is the given string identical to a system path or route?
+ * This could probably be put in some other class, but at
+ * at the moment, only Nickname requires this functionality.
+ *
+ * @param string $str
+ * @return boolean
+ */
+ public static function isSystemPath($str)
+ {
+ $paths = array();
+
+ // All directory and file names in site root should be blacklisted
+ $d = dir(INSTALLDIR);
+ while (false !== ($entry = $d->read())) {
+ $paths[] = $entry;
+ }
+ $d->close();
+
+ // All top level names in the router should be blacklisted
+ $router = Router::get();
+ foreach (array_keys($router->m->getPaths()) as $path) {
+ if (preg_match('/^\/(.*?)[\/\?]/',$path,$matches)) {
+ $paths[] = $matches[1];
+ }
+ }
+ return in_array($str, $paths);
+ }
+
+ /**
+ * Is the nickname already in use locally? Checks the User table.
+ *
+ * @param string $str
+ * @return User|null Returns null if no such user, otherwise a User object
+ */
+ public static function isTaken($str)
+ {
+ $user = User::getKV('nickname', $str);
+ return $user; // null if no such User entry
+ }