]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Merge branch '0.9.x' into adminpanel
[quix0rs-gnu-social.git] / classes / User.php
index 48df0cdd773f46b9b4b98379ab5ce7589105d073..447a34141b1c28b90f38f95c2abc85acfd27c733 100644 (file)
@@ -117,8 +117,7 @@ class User extends Memcached_DataObject
     function allowed_nickname($nickname)
     {
         // XXX: should already be validated for size, content, etc.
-
-        $blacklist = array();
+        $blacklist = common_config('nickname', 'blacklist');
 
         //all directory and file names should be blacklisted
         $d = dir(INSTALLDIR);
@@ -126,8 +125,15 @@ class User extends Memcached_DataObject
             $blacklist[]=$entry;
         }
         $d->close();
-        $merged = array_merge($blacklist, common_config('nickname', 'blacklist'));
-        return !in_array($nickname, $merged);
+
+        //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)){
+                $blacklist[]=$matches[1];
+            }
+        }
+        return !in_array($nickname, $blacklist);
     }
 
     function getCurrentNotice($dt=null)
@@ -198,6 +204,15 @@ class User extends Memcached_DataObject
         }
         if (!empty($location)) {
             $profile->location = $location;
+
+            $loc = Location::fromName($location);
+
+            if (!empty($loc)) {
+                $profile->lat         = $loc->lat;
+                $profile->lon         = $loc->lon;
+                $profile->location_id = $loc->location_id;
+                $profile->location_ns = $loc->location_ns;
+            }
         }
 
         $profile->created = common_sql_now();
@@ -227,11 +242,9 @@ class User extends Memcached_DataObject
             }
         }
 
-        $inboxes = common_config('inboxes', 'enabled');
+        // This flag is ignored but still set to 1
 
-        if ($inboxes === true || $inboxes == 'transitional') {
-            $user->inboxed = 1;
-        }
+        $user->inboxed = 1;
 
         $user->created = common_sql_now();
         $user->uri = common_user_uri($user);
@@ -321,6 +334,7 @@ class User extends Memcached_DataObject
                                                   common_config('site', 'name'),
                                                   $user->nickname),
                                           'system');
+                common_broadcast_notice($notice);
             }
         }
 
@@ -433,55 +447,16 @@ class User extends Memcached_DataObject
 
     function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
     {
-        $enabled = common_config('inboxes', 'enabled');
-
-        // Complicated code, depending on whether we support inboxes yet
-        // XXX: make this go away when inboxes become mandatory
-
-        if ($enabled === false ||
-            ($enabled == 'transitional' && $this->inboxed == 0)) {
-            $qry =
-              'SELECT notice.* ' .
-              'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
-              'WHERE subscription.subscriber = %d ' .
-              'AND notice.is_local != ' . Notice::GATEWAY;
-            return Notice::getStream(sprintf($qry, $this->id),
-                                     'user:notices_with_friends:' . $this->id,
-                                     $offset, $limit, $since_id, $before_id,
-                                     $order, $since);
-        } else if ($enabled === true ||
-                   ($enabled == 'transitional' && $this->inboxed == 1)) {
-
-            $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
+        $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
 
-            return Notice::getStreamByIds($ids);
-        }
+        return Notice::getStreamByIds($ids);
     }
 
     function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
     {
-        $enabled = common_config('inboxes', 'enabled');
-
-        // Complicated code, depending on whether we support inboxes yet
-        // XXX: make this go away when inboxes become mandatory
+        $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
 
-        if ($enabled === false ||
-            ($enabled == 'transitional' && $this->inboxed == 0)) {
-            $qry =
-              'SELECT notice.* ' .
-              'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
-              'WHERE subscription.subscriber = %d ';
-            return Notice::getStream(sprintf($qry, $this->id),
-                                     'user:notices_with_friends:' . $this->id,
-                                     $offset, $limit, $since_id, $before_id,
-                                     $order, $since);
-        } else if ($enabled === true ||
-                   ($enabled == 'transitional' && $this->inboxed == 1)) {
-
-            $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-
-            return Notice::getStreamByIds($ids);
-        }
+        return Notice::getStreamByIds($ids);
     }
 
     function blowFavesCache()
@@ -730,10 +705,13 @@ class User extends Memcached_DataObject
         if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
             switch ($right)
             {
-             case Right::deleteOthersNotice:
-                $result = $this->hasRole('moderator');
+            case Right::DELETEOTHERSNOTICE:
+                $result = $this->hasRole(User_role::MODERATOR);
+                break;
+            case Right::CONFIGURESITE:
+                $result = $this->hasRole(User_role::ADMINISTRATOR);
                 break;
-             default:
+            default:
                 $result = false;
                 break;
             }
@@ -744,19 +722,18 @@ class User extends Memcached_DataObject
     function delete()
     {
         $profile = $this->getProfile();
-        $profile->delete();
+        if ($profile) {
+            $profile->delete();
+        }
 
         $related = array('Fave',
-                         'User_openid',
                          'Confirm_address',
                          'Remember_me',
                          'Foreign_link',
                          'Invitation',
+                         'Notice_inbox',
                          );
-
-        if (common_config('inboxes', 'enabled')) {
-            $related[] = 'Notice_inbox';
-        }
+        Event::handle('UserDeleteRelated', array($this, &$related));
 
         foreach ($related as $cls) {
             $inst = new $cls();