]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Events on user registrations now strictly typed
[quix0rs-gnu-social.git] / classes / User.php
index 8d21d2bc19f305b3e5a5d9946f99cd8df368e986..cc6e55d1bde3ab936829102e19560b08024c6ed8 100644 (file)
@@ -65,9 +65,6 @@ class User extends Managed_DataObject
     public $created;                         // datetime()   not_null
     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /* Static get */
-    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User',$k,$v); }
-
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
@@ -131,7 +128,7 @@ class User extends Managed_DataObject
     function getProfile()
     {
         if (is_int($this->_profile) && $this->_profile == -1) { // invalid but distinct from null
-            $this->_profile = Profile::staticGet('id', $this->id);
+            $this->_profile = Profile::getKV('id', $this->id);
             if (empty($this->_profile)) {
                 throw new UserNoProfileException($this);
             }
@@ -225,15 +222,7 @@ class User extends Managed_DataObject
 
     function getCarrier()
     {
-        return Sms_carrier::staticGet('id', $this->carrier);
-    }
-
-    /**
-     * @deprecated use Subscription::start($sub, $other);
-     */
-    function subscribeTo($other)
-    {
-        return Subscription::start($this->getProfile(), $other);
+        return Sms_carrier::getKV('id', $this->carrier);
     }
 
     function hasBlocked($other)
@@ -263,7 +252,7 @@ class User extends Managed_DataObject
      *              ?string 'uri' permalink to notice; defaults to local notice URL
      * @return mixed User object or false on failure
      */
-    static function register($fields) {
+    static function register(array $fields) {
 
         // MAGICALLY put fields into current scope
 
@@ -318,7 +307,7 @@ class User extends Managed_DataObject
         // Users who respond to invite email have proven their ownership of that address
 
         if (!empty($code)) {
-            $invite = Invitation::staticGet($code);
+            $invite = Invitation::getKV($code);
             if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
                 $user->email = $invite->address;
             }
@@ -346,7 +335,7 @@ class User extends Managed_DataObject
 
         $user->created = common_sql_now();
 
-        if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
+        if (Event::handle('StartUserRegister', array($profile))) {
 
             $profile->query('BEGIN');
 
@@ -435,12 +424,12 @@ class User extends Managed_DataObject
             $defnick = common_config('newuser', 'default');
 
             if (!empty($defnick)) {
-                $defuser = User::staticGet('nickname', $defnick);
+                $defuser = User::getKV('nickname', $defnick);
                 if (empty($defuser)) {
                     common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
                                __FILE__);
                 } else {
-                    Subscription::start($user, $defuser);
+                    Subscription::start($profile, $defuser->getProfile());
                 }
             }
 
@@ -455,7 +444,7 @@ class User extends Managed_DataObject
             $welcome = common_config('newuser', 'welcome');
 
             if (!empty($welcome)) {
-                $welcomeuser = User::staticGet('nickname', $welcome);
+                $welcomeuser = User::getKV('nickname', $welcome);
                 if (empty($welcomeuser)) {
                     common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
                                __FILE__);
@@ -470,7 +459,7 @@ class User extends Managed_DataObject
                 }
             }
 
-            Event::handle('EndUserRegister', array(&$profile, &$user));
+            Event::handle('EndUserRegister', array($profile));
         }
 
         return $user;
@@ -486,7 +475,7 @@ class User extends Managed_DataObject
 
         if ($invites->find()) {
             while ($invites->fetch()) {
-                $other = User::staticGet($invites->user_id);
+                $other = User::getKV($invites->user_id);
                 subs_subscribe_to($other, $this);
             }
         }
@@ -597,7 +586,7 @@ class User extends Managed_DataObject
         return Profile_tag::setTags($this->id, $this->id, $newtags, $privacy);
     }
 
-    function block($other)
+    function block(Profile $other)
     {
         // Add a new block record
 
@@ -643,11 +632,11 @@ class User extends Managed_DataObject
         return true;
     }
 
-    function unblock($other)
+    function unblock(Profile $other)
     {
         // Get the block record
 
-        $block = Profile_block::get($this->id, $other->id);
+        $block = Profile_block::exists($this->getProfile(), $other);
 
         if (!$block) {
             return false;
@@ -736,7 +725,7 @@ class User extends Managed_DataObject
 
         $profile = new Profile();
 
-        $cnt = $profile->query(sprintf($qry, $this->id, $tag));
+        $cnt = $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
 
         return $profile;
     }
@@ -758,7 +747,7 @@ class User extends Managed_DataObject
 
         $profile = new Profile();
 
-        $profile->query(sprintf($qry, $this->id, $tag));
+        $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
 
         return $profile;
     }
@@ -874,13 +863,12 @@ class User extends Managed_DataObject
         } else if ($cfg == 'never') {
             return false;
         } else { // user
-            $share = true;
+            $share = common_config('location', 'sharedefault');
 
-            $prefs = User_location_prefs::staticGet('user_id', $this->id);
+            // Check if user has a personal setting for this
+            $prefs = User_location_prefs::getKV('user_id', $this->id);
 
-            if (empty($prefs)) {
-                $share = common_config('location', 'sharedefault');
-            } else {
+            if (!empty($prefs)) {
                 $share = $prefs->share_location;
                 $prefs->free();
             }
@@ -904,7 +892,7 @@ class User extends Managed_DataObject
             $pr->limit(1);
 
             if ($pr->find(true)) {
-                $owner = User::staticGet('id', $pr->profile_id);
+                $owner = User::getKV('id', $pr->profile_id);
             } else {
                 $owner = null;
             }
@@ -934,7 +922,7 @@ class User extends Managed_DataObject
             $nickname = common_config('singleuser', 'nickname');
 
             if (!empty($nickname)) {
-                $user = User::staticGet('nickname', $nickname);
+                $user = User::getKV('nickname', $nickname);
             }
 
             // if there was no nickname or no user by that nickname,
@@ -1055,11 +1043,11 @@ class User extends Managed_DataObject
 
     static function recoverPassword($nore)
     {
-        $user = User::staticGet('email', common_canonical_email($nore));
+        $user = User::getKV('email', common_canonical_email($nore));
 
         if (!$user) {
             try {
-                $user = User::staticGet('nickname', common_canonical_nickname($nore));
+                $user = User::getKV('nickname', common_canonical_nickname($nore));
             } catch (NicknameException $e) {
                 // invalid
             }
@@ -1076,7 +1064,7 @@ class User extends Managed_DataObject
             $confirm_email->address_type = 'email';
             $confirm_email->find();
             if ($confirm_email->fetch()) {
-                $user = User::staticGet($confirm_email->user_id);
+                $user = User::getKV($confirm_email->user_id);
             } else {
                 $confirm_email = null;
             }
@@ -1149,7 +1137,7 @@ class User extends Managed_DataObject
     function streamModeOnly()
     {
         if (common_config('oldschool', 'enabled')) {
-            $osp = Old_school_prefs::staticGet('user_id', $this->id);
+            $osp = Old_school_prefs::getKV('user_id', $this->id);
             if (!empty($osp)) {
                 return $osp->stream_mode_only;
             }
@@ -1161,7 +1149,7 @@ class User extends Managed_DataObject
     function conversationTree()
     {
         if (common_config('oldschool', 'enabled')) {
-            $osp = Old_school_prefs::staticGet('user_id', $this->id);
+            $osp = Old_school_prefs::getKV('user_id', $this->id);
             if (!empty($osp)) {
                 return $osp->conversation_tree;
             }
@@ -1173,7 +1161,7 @@ class User extends Managed_DataObject
     function streamNicknames()
     {
         if (common_config('oldschool', 'enabled')) {
-            $osp = Old_school_prefs::staticGet('user_id', $this->id);
+            $osp = Old_school_prefs::getKV('user_id', $this->id);
             if (!empty($osp)) {
                 return $osp->stream_nicknames;
             }