]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
getID() will complain loudly if something is wrong
[quix0rs-gnu-social.git] / classes / Profile.php
index 47e144032d2b04d061cf04867b94f5668450f6ec..78ef18484c7e0d9f7c9f2559cb419783f39fd1ad 100644 (file)
@@ -48,12 +48,12 @@ class Profile extends Managed_DataObject
             'description' => 'local and remote users have profiles',
             'fields' => array(
                 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
-                'nickname' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username', 'collate' => 'utf8_general_ci'),
-                'fullname' => array('type' => 'varchar', 'length' => 191, 'description' => 'display name', 'collate' => 'utf8_general_ci'),
+                'nickname' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username', 'collate' => 'utf8mb4_general_ci'),
+                'fullname' => array('type' => 'varchar', 'length' => 191, 'description' => 'display name', 'collate' => 'utf8mb4_general_ci'),
                 'profileurl' => array('type' => 'varchar', 'length' => 191, 'description' => 'URL, cached so we dont regenerate'),
-                'homepage' => array('type' => 'varchar', 'length' => 191, 'description' => 'identifying URL', 'collate' => 'utf8_general_ci'),
-                'bio' => array('type' => 'text', 'description' => 'descriptive biography', 'collate' => 'utf8_general_ci'),
-                'location' => array('type' => 'varchar', 'length' => 191, 'description' => 'physical location', 'collate' => 'utf8_general_ci'),
+                'homepage' => array('type' => 'varchar', 'length' => 191, 'description' => 'identifying URL', 'collate' => 'utf8mb4_general_ci'),
+                'bio' => array('type' => 'text', 'description' => 'descriptive biography', 'collate' => 'utf8mb4_general_ci'),
+                'location' => array('type' => 'varchar', 'length' => 191, 'description' => 'physical location', 'collate' => 'utf8mb4_general_ci'),
                 'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
                 'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
                 'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
@@ -138,6 +138,18 @@ class Profile extends Managed_DataObject
         return true;
     }
 
+    // Returns false if the user has no password (which will always
+    // be the case for remote users). This can be the case for OpenID
+    // logins or other mechanisms which don't store a password hash.
+    public function hasPassword()
+    {
+        try {
+            return $this->getUser()->hasPassword();
+        } catch (NoSuchUserException $e) {
+            return false;
+        }
+    }
+
     public function getObjectType()
     {
         // FIXME: More types... like peopletags and whatever
@@ -242,6 +254,11 @@ class Profile extends Managed_DataObject
         return null;
     }
 
+    function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
+    {
+        return Reply::stream($this->getID(), $offset, $limit, $since_id, $before_id);
+    }
+
     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
     {
         $stream = new TaggedProfileNoticeStream($this, $tag);
@@ -860,6 +877,11 @@ class Profile extends Managed_DataObject
 
     function delete($useWhere=false)
     {
+        // just in case it hadn't been done before... (usually set before adding deluser to queue handling!)
+        if (!$this->hasRole(Profile_role::DELETED)) {
+            $this->grantRole(Profile_role::DELETED);
+        }
+
         $this->_deleteNotices();
         $this->_deleteSubscriptions();
         $this->_deleteTags();
@@ -1220,8 +1242,9 @@ class Profile extends Managed_DataObject
     {
         // XXX: not really a pkey, but should work
 
-        $notice = Notice::pkeyGet(array('profile_id' => $this->id,
-                                        'repeat_of' => $notice->id));
+        $notice = Notice::pkeyGet(array('profile_id' => $this->getID(),
+                                        'repeat_of' => $notice->getID(),
+                                        'verb' => ActivityVerb::SHARE));
 
         return !empty($notice);
     }
@@ -1390,6 +1413,11 @@ class Profile extends Managed_DataObject
         return $this->fullname;
     }
 
+    public function getHomepage()
+    {
+        return $this->homepage;
+    }
+
     public function getDescription()
     {
         return $this->bio;
@@ -1566,6 +1594,23 @@ class Profile extends Managed_DataObject
         return $this;
     }
 
+    /**
+     * Test whether the given profile is the same as the current class,
+     * for testing identities.
+     *
+     * @param Profile $other    The other profile, usually from Action's $this->scoped
+     *
+     * @return boolean
+     */
+    public function sameAs(Profile $other=null)
+    {
+        if (is_null($other)) {
+            // In case $this->scoped is null or something, i.e. not a current/legitimate profile.
+            return false;
+        }
+        return $this->getID() === $other->getID();
+    }
+
     /**
      * This will perform shortenLinks with the connected User object.
      *
@@ -1613,4 +1658,9 @@ class Profile extends Managed_DataObject
     public function setPref($namespace, $topic, $data) {
         return Profile_prefs::setData($this, $namespace, $topic, $data);
     }
+
+    public function getConnectedApps($offset=0, $limit=null)
+    {
+        return $this->getUser()->getConnectedApps($offset, $limit);
+    }
 }