]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / classes / Profile.php
index cd9b15961b9dd89b66f1a0b42a2b1b102d4eff47..9c334fd923be614f04f1e41e419c09639e6b62ce 100644 (file)
@@ -175,7 +175,6 @@ class Profile extends Managed_DataObject
         $avatar->mediatype = image_type_to_mime_type($imagefile->type);
         $avatar->filename = $filename;
         $avatar->original = true;
-        $avatar->url = Avatar::url($filename);
         $avatar->created = common_sql_now();
 
         // XXX: start a transaction here
@@ -233,10 +232,10 @@ class Profile extends Managed_DataObject
      *
      * @return mixed Notice or null
      */
-    function getCurrentNotice()
+    function getCurrentNotice(Profile $scoped=null)
     {
         try {
-            $notice = $this->getNotices(0, 1);
+            $notice = $this->getNotices(0, 1, 0, 0, $scoped);
 
             if ($notice->fetch()) {
                 if ($notice instanceof ArrayWrapper) {
@@ -381,7 +380,7 @@ class Profile extends Managed_DataObject
         return false;
     }
 
-    function getLists($auth_user, $offset=0, $limit=null, $since_id=0, $max_id=0)
+    function getLists(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
     {
         $ids = array();
 
@@ -421,9 +420,7 @@ class Profile extends Managed_DataObject
             self::cacheSet($keypart, implode(',', $ids));
         }
 
-        $showPrivate = (($auth_user instanceof User ||
-                            $auth_user instanceof Profile) &&
-                        $auth_user->id === $this->id);
+        $showPrivate = $this->sameAs($scoped);
 
         $lists = array();
 
@@ -446,7 +443,7 @@ class Profile extends Managed_DataObject
     /**
      * Get tags that other people put on this profile, in reverse-chron order
      *
-     * @param (Profile|User) $auth_user  Authorized user (used for privacy)
+     * @param Profile        $scoped     User we are requesting as
      * @param int            $offset     Offset from latest
      * @param int            $limit      Max number to get
      * @param datetime       $since_id   max date
@@ -455,7 +452,7 @@ class Profile extends Managed_DataObject
      * @return Profile_list resulting lists
      */
 
-    function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
+    function getOtherTags(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
     {
         $list = new Profile_list();
 
@@ -467,11 +464,11 @@ class Profile extends Managed_DataObject
                        $this->id);
 
 
-        if ($auth_user instanceof User || $auth_user instanceof Profile) {
+        if (!is_null($scoped)) {
             $qry .= sprintf('AND ( ( profile_list.private = false ) ' .
                             'OR ( profile_list.tagger = %d AND ' .
                             'profile_list.private = true ) )',
-                            $auth_user->id);
+                            $scoped->getID());
         } else {
             $qry .= 'AND profile_list.private = 0 ';
         }
@@ -824,6 +821,7 @@ class Profile extends Managed_DataObject
 
         $notices = new Notice();
         $notices->profile_id = $this->id;
+        $notices->verb = ActivityVerb::POST;        
         $cnt = (int) $notices->count('distinct id');
 
         if (!empty($c)) {
@@ -1424,11 +1422,25 @@ class Profile extends Managed_DataObject
      */
     public function getUrl()
     {
-        if (empty($this->profileurl) ||
-                !filter_var($this->profileurl, FILTER_VALIDATE_URL)) {
-            throw new InvalidUrlException($this->profileurl);
+        $url = null;
+        if ($this->isGroup()) {
+            // FIXME: Get rid of this event, it fills no real purpose, data should be in Profile->profileurl (replaces User_group->mainpage)
+            if (Event::handle('StartUserGroupHomeUrl', array($this->getGroup(), &$url))) {
+                $url = $this->getGroup()->isLocal()
+                        ? common_local_url('showgroup', array('nickname' => $this->getNickname()))
+                        : $this->profileurl;
+            }
+            Event::handle('EndUserGroupHomeUrl', array($this->getGroup(), $url));
+        } elseif ($this->isLocal()) {
+            $url = common_local_url('showstream', array('nickname' => $this->getNickname()));
+        } else {
+            $url = $this->profileurl;
+        }
+        if (empty($url) ||
+                !filter_var($url, FILTER_VALIDATE_URL)) {
+            throw new InvalidUrlException($url);
         }
-        return $this->profileurl;
+        return $url;
     }
 
     public function getNickname()
@@ -1543,6 +1555,11 @@ class Profile extends Managed_DataObject
             $user = User::getKV('uri', $uri);
             if ($user instanceof User) {
                 $profile = $user->getProfile();
+            } else {
+                $group = User_group::getKV('uri', $uri);
+                if ($group instanceof User_group) {
+                    $profile = $group->getProfile();
+                }
             }
             Event::handle('EndGetProfileFromURI', array($uri, $profile));
         }