]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.8.x' into 0.9.x
authorEvan Prodromou <evan@status.net>
Sun, 4 Oct 2009 07:07:37 +0000 (03:07 -0400)
committerEvan Prodromou <evan@status.net>
Sun, 4 Oct 2009 07:07:37 +0000 (03:07 -0400)
Conflicts:
classes/Profile.php

1  2 
classes/Profile.php
classes/User.php
lib/htmloutputter.php

index 7f0d1275833daa51feee64172b8a35e8ec2ff346,8385ebf8890bb5e6f7a229b0d059dfedfbed2168..4a069ee84eb6141465d27f2a9ac205432d41cfd5
@@@ -461,19 -462,78 +461,94 @@@ class Profile extends Memcached_DataObj
          }
      }
  
 +    static function maxBio()
 +    {
 +        $biolimit = common_config('profile', 'biolimit');
 +        // null => use global limit (distinct from 0!)
 +        if (is_null($biolimit)) {
 +            $biolimit = common_config('site', 'textlimit');
 +        }
 +        return $biolimit;
 +    }
 +
 +    static function bioTooLong($bio)
 +    {
 +        $biolimit = self::maxBio();
 +        return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
 +    }
++
+     function delete()
+     {
+         $this->_deleteNotices();
+         $this->_deleteSubscriptions();
+         $this->_deleteMessages();
+         $this->_deleteTags();
+         $this->_deleteBlocks();
+         $related = array('Avatar',
+                          'Reply',
+                          'Group_member',
+                          );
+         foreach ($related as $cls) {
+             $inst = new $cls();
+             $inst->profile_id = $this->id;
+             $inst->delete();
+         }
+         parent::delete();
+     }
+     function _deleteNotices()
+     {
+         $notice = new Notice();
+         $notice->profile_id = $this->id;
+         if ($notice->find()) {
+             while ($notice->fetch()) {
+                 $other = clone($notice);
+                 $other->delete();
+             }
+         }
+     }
+     function _deleteSubscriptions()
+     {
+         $sub = new Subscription();
+         $sub->subscriber = $this->id;
+         $sub->delete();
+         $subd = new Subscription();
+         $subd->subscribed = $this->id;
+         $subd->delete();
+     }
+     function _deleteMessages()
+     {
+         $msg = new Message();
+         $msg->from_profile = $this->id;
+         $msg->delete();
+         $msg = new Message();
+         $msg->to_profile = $this->id;
+         $msg->delete();
+     }
+     function _deleteTags()
+     {
+         $tag = new Profile_tag();
+         $tag->tagged = $this->id;
+         $tag->delete();
+     }
+     function _deleteBlocks()
+     {
+         $block = new Profile_block();
+         $block->blocked = $this->id;
+         $block->delete();
+         $block = new Group_block();
+         $block->blocked = $this->id;
+         $block->delete();
+     }
  }
index 3f7ed09bb7ae508c324ebec07f436060d6f40ca1,007662131c70a0a44702f1caa114e38f680d1ba5..48df0cdd773f46b9b4b98379ab5ce7589105d073
@@@ -663,81 -674,63 +663,125 @@@ class User extends Memcached_DataObjec
          return $profile;
      }
  
 -    function hasOpenID()
 +    function getDesign()
 +    {
 +        return Design::staticGet('id', $this->design_id);
 +    }
 +
 +    function hasRole($name)
 +    {
 +        $role = User_role::pkeyGet(array('user_id' => $this->id,
 +                                         'role' => $name));
 +        return (!empty($role));
 +    }
 +
 +    function grantRole($name)
 +    {
 +        $role = new User_role();
 +
 +        $role->user_id = $this->id;
 +        $role->role    = $name;
 +        $role->created = common_sql_now();
 +
 +        $result = $role->insert();
 +
 +        if (!$result) {
 +            common_log_db_error($role, 'INSERT', __FILE__);
 +            return false;
 +        }
 +
 +        return true;
 +    }
 +
 +    function revokeRole($name)
      {
 -        $oid = new User_openid();
 +        $role = User_role::pkeyGet(array('user_id' => $this->id,
 +                                         'role' => $name));
 +
 +        if (empty($role)) {
 +            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; does not exist.');
 +        }
  
 -        $oid->user_id = $this->id;
 +        $result = $role->delete();
  
 -        $cnt = $oid->find();
 +        if (!$result) {
 +            common_log_db_error($role, 'DELETE', __FILE__);
 +            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; database error.');
 +        }
  
 -        return ($cnt > 0);
 +        return true;
      }
  
 -    function getDesign()
 +    /**
 +     * Does this user have the right to do X?
 +     *
 +     * With our role-based authorization, this is merely a lookup for whether the user
 +     * has a particular role. The implementation currently uses a switch statement
 +     * to determine if the user has the pre-defined role to exercise the right. Future
 +     * implementations may allow per-site roles, and different mappings of roles to rights.
 +     *
 +     * @param $right string Name of the right, usually a constant in class Right
 +     * @return boolean whether the user has the right in question
 +     */
 +
 +    function hasRight($right)
      {
 -        return Design::staticGet('id', $this->design_id);
 +        $result = false;
 +        if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
 +            switch ($right)
 +            {
 +             case Right::deleteOthersNotice:
 +                $result = $this->hasRole('moderator');
 +                break;
 +             default:
 +                $result = false;
 +                break;
 +            }
 +        }
 +        return $result;
      }
+     function delete()
+     {
+         $profile = $this->getProfile();
+         $profile->delete();
+         $related = array('Fave',
+                          'User_openid',
+                          'Confirm_address',
+                          'Remember_me',
+                          'Foreign_link',
+                          'Invitation',
+                          );
+         if (common_config('inboxes', 'enabled')) {
+             $related[] = 'Notice_inbox';
+         }
+         foreach ($related as $cls) {
+             $inst = new $cls();
+             $inst->user_id = $this->id;
+             $inst->delete();
+         }
+         $this->_deleteTags();
+         $this->_deleteBlocks();
+         parent::delete();
+     }
+     function _deleteTags()
+     {
+         $tag = new Profile_tag();
+         $tag->tagger = $this->id;
+         $tag->delete();
+     }
+     function _deleteBlocks()
+     {
+         $block = new Profile_block();
+         $block->blocker = $this->id;
+         $block->delete();
+         // XXX delete group block? Reset blocker?
+     }
  }
Simple merge