]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Start and End EmailFormData events include current profile
[quix0rs-gnu-social.git] / classes / Profile.php
index 862e8ff11a4f34acecb8c982f116672b9a4b90d3..e5d00b392d88811c7c5932a59ff6b10403568ab3 100644 (file)
@@ -22,8 +22,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 /**
  * Table Definition for profile
  */
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-
 class Profile extends Managed_DataObject
 {
     ###START_AUTOCODE
@@ -140,6 +138,16 @@ class Profile extends Managed_DataObject
         return true;
     }
 
+    public function getObjectType()
+    {
+        // FIXME: More types... like peopletags and whatever
+        if ($this->isGroup()) {
+            return ActivityObject::GROUP;
+        } else {
+            return ActivityObject::PERSON;
+        }
+    }
+
     public function getAvatar($width, $height=null)
     {
         return Avatar::byProfile($this, $width, $height);
@@ -760,39 +768,6 @@ class Profile extends Managed_DataObject
           $other->isSubscribed($this);
     }
 
-    function hasFave($notice)
-    {
-        $fave = Fave::pkeyGet(array('user_id' => $this->id,
-                                    'notice_id' => $notice->id));
-        return ((is_null($fave)) ? false : true);
-    }
-
-    function faveCount()
-    {
-        $c = Cache::instance();
-        if (!empty($c)) {
-            $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id));
-            if (is_integer($cnt)) {
-                return (int) $cnt;
-            }
-        }
-
-        $faves = new Fave();
-        $faves->user_id = $this->id;
-        $cnt = (int) $faves->count('notice_id');
-
-        if (!empty($c)) {
-            $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt);
-        }
-
-        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();
@@ -815,20 +790,6 @@ class Profile extends Managed_DataObject
         return $cnt;
     }
 
-    function blowFavesCache()
-    {
-        $cache = Cache::instance();
-        if ($cache) {
-            // Faves don't happen chronologically, so we need to blow
-            // ;last cache, too
-            $cache->delete(Cache::key('fave:ids_by_user:'.$this->id));
-            $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last'));
-            $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id));
-            $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last'));
-        }
-        $this->blowFaveCount();
-    }
-
     function blowSubscriberCount()
     {
         $c = Cache::instance();
@@ -845,14 +806,6 @@ class Profile extends Managed_DataObject
         }
     }
 
-    function blowFaveCount()
-    {
-        $c = Cache::instance();
-        if (!empty($c)) {
-            $c->delete(Cache::key('profile:fave_count:'.$this->id));
-        }
-    }
-
     function blowNoticeCount()
     {
         $c = Cache::instance();
@@ -1358,10 +1311,66 @@ class Profile extends Managed_DataObject
      */
     function asActivityNoun($element)
     {
-        $noun = ActivityObject::fromProfile($this);
+        $noun = $this->asActivityObject();
         return $noun->asString('activity:' . $element);
     }
 
+    public function asActivityObject()
+    {
+        $object = new ActivityObject();
+
+        if (Event::handle('StartActivityObjectFromProfile', array($this, &$object))) {
+            $object->type   = $this->getObjectType();
+            $object->id     = $this->getUri();
+            $object->title  = $this->getBestName();
+            $object->link   = $this->getUrl();
+
+            try {
+                $avatar = Avatar::getUploaded($this);
+                $object->avatarLinks[] = AvatarLink::fromAvatar($avatar);
+            } catch (NoAvatarException $e) {
+                // Could not find an original avatar to link
+            }
+
+            $sizes = array(
+                AVATAR_PROFILE_SIZE,
+                AVATAR_STREAM_SIZE,
+                AVATAR_MINI_SIZE
+            );
+
+            foreach ($sizes as $size) {
+                $alink  = null;
+                try {
+                    $avatar = Avatar::byProfile($this, $size);
+                    $alink = AvatarLink::fromAvatar($avatar);
+                } catch (NoAvatarException $e) {
+                    $alink = new AvatarLink();
+                    $alink->type   = 'image/png';
+                    $alink->height = $size;
+                    $alink->width  = $size;
+                    $alink->url    = Avatar::defaultImage($size);
+                }
+
+                $object->avatarLinks[] = $alink;
+            }
+
+            if (isset($this->lat) && isset($this->lon)) {
+                $object->geopoint = (float)$this->lat
+                    . ' ' . (float)$this->lon;
+            }
+
+            $object->poco = PoCo::fromProfile($this);
+
+            if ($this->isLocal()) {
+                $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $this->getNickname()))));
+            }
+
+            Event::handle('EndActivityObjectFromProfile', array($this, &$object));
+        }
+
+        return $object;
+    }
+
     /**
      * Returns the profile's canonical url, not necessarily a uri/unique id
      *