]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
function delete in dataobjects now don't break strict syntax
[quix0rs-gnu-social.git] / classes / Profile.php
index e1bba076e9e31d0d9020b8d757537395e2afd5c1..50cbeb3ac4fdc16b422aa1b8df93fff9910577c0 100644 (file)
@@ -135,7 +135,7 @@ class Profile extends Managed_DataObject
         $avatar->filename = $filename;
         $avatar->original = true;
         $avatar->url = Avatar::url($filename);
-        $avatar->created = DB_DataObject_Cast::dateTime(); # current time
+        $avatar->created = common_sql_now();
 
         // XXX: start a transaction here
         if (!Avatar::deleteFromProfile($this, true) || !$avatar->insert()) {
@@ -549,40 +549,69 @@ class Profile extends Managed_DataObject
     function getSubscribed($offset=0, $limit=null)
     {
         $subs = Subscription::getSubscribedIDs($this->id, $offset, $limit);
-        $profiles = Profile::listFind('id', $subs);
+        try {
+            $profiles = Profile::listFind('id', $subs);
+        } catch (NoResultException $e) {
+            return $e->obj;
+        }
         return $profiles;
     }
 
     function getSubscribers($offset=0, $limit=null)
     {
         $subs = Subscription::getSubscriberIDs($this->id, $offset, $limit);
-        $profiles = Profile::listFind('id', $subs);
+        try {
+            $profiles = Profile::listFind('id', $subs);
+        } catch (NoResultException $e) {
+            return $e->obj;
+        }
         return $profiles;
     }
 
-    function getTaggedSubscribers($tag)
+    function getTaggedSubscribers($tag, $offset=0, $limit=null)
     {
         $qry =
           'SELECT profile.* ' .
-          'FROM profile JOIN (subscription, profile_tag, profile_list) ' .
+          'FROM profile JOIN subscription ' .
           'ON profile.id = subscription.subscriber ' .
-          'AND profile.id = profile_tag.tagged ' .
-          'AND profile_tag.tagger = profile_list.tagger AND profile_tag.tag = profile_list.tag ' .
+          'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' .
+          'AND profile_tag.tagger = subscription.subscribed) ' .
           'WHERE subscription.subscribed = %d ' .
+          "AND profile_tag.tag = '%s' " .
           'AND subscription.subscribed != subscription.subscriber ' .
-          'AND profile_tag.tagger = %d AND profile_tag.tag = "%s" ' .
-          'AND profile_list.private = false ' .
-          'ORDER BY subscription.created DESC';
+          'ORDER BY subscription.created DESC ';
+
+        if ($offset) {
+            $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+        }
 
         $profile = new Profile();
-        $tagged = array();
 
-        $cnt = $profile->query(sprintf($qry, $this->id, $this->id, $profile->escape($tag)));
+        $cnt = $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
 
-        while ($profile->fetch()) {
-            $tagged[] = clone($profile);
-        }
-        return $tagged;
+        return $profile;
+    }
+
+    function getTaggedSubscriptions($tag, $offset=0, $limit=null)
+    {
+        $qry =
+          'SELECT profile.* ' .
+          'FROM profile JOIN subscription ' .
+          'ON profile.id = subscription.subscribed ' .
+          'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' .
+          'AND profile_tag.tagger = subscription.subscriber) ' .
+          'WHERE subscription.subscriber = %d ' .
+          "AND profile_tag.tag = '%s' " .
+          'AND subscription.subscribed != subscription.subscriber ' .
+          'ORDER BY subscription.created DESC ';
+
+        $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+
+        $profile = new Profile();
+
+        $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
+
+        return $profile;
     }
 
     /**
@@ -724,6 +753,11 @@ class Profile extends Managed_DataObject
         return $cnt;
     }
 
+    function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
+    {
+        return Fave::stream($this->id, $offset, $limit, $own, $since_id, $max_id);
+    }
+
     function noticeCount()
     {
         $c = Cache::instance();
@@ -808,7 +842,34 @@ class Profile extends Managed_DataObject
         return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
     }
 
-    function delete()
+    function update($dataObject=false)
+    {
+        if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
+            try {
+                $local = $this->getUser();
+                common_debug("Updating User ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
+                $origuser = clone($local);
+                $local->nickname = $this->nickname;
+                $result = $local->updateKeys($origuser);
+                if ($result === false) {
+                    common_log_db_error($local, 'UPDATE', __FILE__);
+                    // TRANS: Server error thrown when user profile settings could not be updated.
+                    throw new ServerException(_('Could not update user nickname.'));
+                }
+
+                // Clear the site owner, in case nickname changed
+                if ($local->hasRole(Profile_role::OWNER)) {
+                    User::blow('user:site_owner');
+                }
+            } catch (NoSuchUserException $e) {
+                // Nevermind...
+            }
+        }
+
+        return parent::update($dataObject);
+    }
+
+    function delete($useWhere=false)
     {
         $this->_deleteNotices();
         $this->_deleteSubscriptions();
@@ -830,7 +891,7 @@ class Profile extends Managed_DataObject
             $inst->delete();
         }
 
-        parent::delete();
+        return parent::delete($useWhere);
     }
 
     function _deleteNotices()
@@ -1091,7 +1152,7 @@ class Profile extends Managed_DataObject
      * @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)
+    public function hasRight($right)
     {
         $result = false;
 
@@ -1290,6 +1351,26 @@ class Profile extends Managed_DataObject
         return $uri;
     }
 
+    /**
+     * Returns an assumed acct: URI for a profile. Plugins are required.
+     *
+     * @return string $uri
+     */
+    public function getAcctUri()
+    {
+        $acct = null;
+
+        if (Event::handle('StartGetProfileAcctUri', array($this, &$acct))) {
+            Event::handle('EndGetProfileAcctUri', array($this, &$acct));
+        }
+
+        if ($acct === null) {
+            throw new ProfileNoAcctUriException($this);
+        }
+
+        return $acct;
+    }
+
     function hasBlocked($other)
     {
         $block = Profile_block::exists($this, $other);
@@ -1317,7 +1398,7 @@ class Profile extends Managed_DataObject
         $profile = null;
 
         if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
-            // Get a local user or remote (OMB 0.1) profile
+            // Get a local user
             $user = User::getKV('uri', $uri);
             if (!empty($user)) {
                 $profile = $user->getProfile();