]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / Notice.php
index de5104fdbba3ff3018e42241d784d75b72aa001a..c1150626b39f3ffddc92a2993f1321a881b072da 100644 (file)
@@ -599,7 +599,7 @@ class Notice extends Memcached_DataObject
 
     function getStreamByIds($ids)
     {
-        $cache = common_memcache();
+        $cache = Cache::instance();
 
         if (!empty($cache)) {
             $notices = array();
@@ -775,7 +775,7 @@ class Notice extends Memcached_DataObject
         $c = self::memcache();
 
         if (!empty($c)) {
-            $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id));
+            $ni = $c->get(Cache::key('notice:who_gets:'.$this->id));
             if ($ni !== false) {
                 return $ni;
             }
@@ -827,7 +827,7 @@ class Notice extends Memcached_DataObject
 
         if (!empty($c)) {
             // XXX: pack this data better
-            $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni);
+            $c->set(Cache::key('notice:who_gets:'.$this->id), $ni);
         }
 
         return $ni;
@@ -1234,12 +1234,18 @@ class Notice extends Memcached_DataObject
      * @return Activity activity object representing this Notice.
      */
 
-    function asActivity($cur = null, $source = false)
+    function asActivity()
     {
+        $act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
+
+        if (!empty($act)) {
+            return $act;
+        }
+
         $act = new Activity();
        
         if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
-           
+
             $profile = $this->getProfile();
            
             $act->actor     = ActivityObject::fromProfile($profile);
@@ -1326,68 +1332,37 @@ class Notice extends Memcached_DataObject
            
             $act->context = $ctx;
 
-            $noticeInfoAttr = array('local_id' => $this->id); // local notice ID (useful to clients for ordering)
-
-            $ns = $this->getSource();
-
-            if (!empty($ns)) {
-                $noticeInfoAttr['source'] =  $ns->code;
-                if (!empty($ns->url)) {
-                    $noticeInfoAttr['source_link'] = $ns->url;
-                    if (!empty($ns->name)) {
-                        $noticeInfoAttr['source'] =  '<a href="'
-                            . htmlspecialchars($ns->url)
-                            . '" rel="nofollow">'
-                            . htmlspecialchars($ns->name)
-                            . '</a>';
-                    }
-                }
-            }
-
-            if (!empty($cur)) {
-                $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
-                $cp = $cur->getProfile();
-                $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
-            }
-
-            if (!empty($this->repeat_of)) {
-                $noticeInfoAttr['repeat_of'] = $this->repeat_of;
-            }
-
-            $act->extra[] = array('statusnet:notice_info', $noticeInfoAttr, null);
+            // Source
 
-            if ($source) {
-               
-                $atom_feed = $profile->getAtomFeed();
+            $atom_feed = $profile->getAtomFeed();
 
-                if (!empty($atom_feed)) {
+            if (!empty($atom_feed)) {
 
-                    $act->source = new ActivitySource();
+                $act->source = new ActivitySource();
                    
-                    // XXX: we should store the actual feed ID
+                // XXX: we should store the actual feed ID
 
-                    $act->source->id = $atom_feed;
+                $act->source->id = $atom_feed;
 
-                    // XXX: we should store the actual feed title
+                // XXX: we should store the actual feed title
 
-                    $act->source->title = $profile->getBestName();
+                $act->source->title = $profile->getBestName();
 
-                    $act->source->links['alternate'] = $profile->profileurl;
-                    $act->source->links['self']      = $atom_feed;
+                $act->source->links['alternate'] = $profile->profileurl;
+                $act->source->links['self']      = $atom_feed;
 
-                    $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+                $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
                    
-                    $notice = $profile->getCurrentNotice();
+                $notice = $profile->getCurrentNotice();
 
-                    if (!empty($notice)) {
-                        $act->source->updated = self::utcDate($notice->created);
-                    }
+                if (!empty($notice)) {
+                    $act->source->updated = self::utcDate($notice->created);
+                }
 
-                    $user = User::staticGet('id', $profile->id);
+                $user = User::staticGet('id', $profile->id);
 
-                    if (!empty($user)) {
-                        $act->source->links['license'] = common_config('license', 'url');
-                    }
+                if (!empty($user)) {
+                    $act->source->links['license'] = common_config('license', 'url');
                 }
             }
 
@@ -1400,18 +1375,73 @@ class Notice extends Memcached_DataObject
             Event::handle('EndNoticeAsActivity', array($this, &$act));
         }
        
+        self::cacheSet(Cache::codeKey('notice:as-activity:'.$this->id), $act);
+
         return $act;
     }
 
     // This has gotten way too long. Needs to be sliced up into functional bits
     // or ideally exported to a utility class.
 
-    function asAtomEntry($namespace=false, $source=false, $author=true, $cur=null)
+    function asAtomEntry($namespace=false,
+                         $source=false,
+                         $author=true, 
+                         $cur=null)
+    {
+        $act = $this->asActivity();
+        $act->extra[] = $this->noticeInfo($cur);
+        return $act->asString($namespace, $author, $source);
+    }
+
+    /**
+     * Extra notice info for atom entries
+     * 
+     * Clients use some extra notice info in the atom stream.
+     * This gives it to them.
+     *
+     * @param User $cur Current user
+     *
+     * @return array representation of <statusnet:notice_info> element
+     */
+
+    function noticeInfo($cur)
     {
-        $act = $this->asActivity($cur, $source);
-        return $act->asString($namespace, $author);
+        // local notice ID (useful to clients for ordering)
+
+        $noticeInfoAttr = array('local_id' => $this->id);
+
+        // notice source
+
+        $ns = $this->getSource();
+
+        if (!empty($ns)) {
+            $noticeInfoAttr['source'] =  $ns->code;
+            if (!empty($ns->url)) {
+                $noticeInfoAttr['source_link'] = $ns->url;
+                if (!empty($ns->name)) {
+                    $noticeInfoAttr['source'] =  '<a href="'
+                        . htmlspecialchars($ns->url)
+                        . '" rel="nofollow">'
+                        . htmlspecialchars($ns->name)
+                        . '</a>';
+                }
+            }
+        }
+
+        // favorite and repeated
+
+        if (!empty($cur)) {
+            $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
+            $cp = $cur->getProfile();
+            $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
+        }
+
+        if (!empty($this->repeat_of)) {
+            $noticeInfoAttr['repeat_of'] = $this->repeat_of;
+        }
+
+        return array('statusnet:notice_info', $noticeInfoAttr, null);
     }
-    
 
     /**
      * Returns an XML string fragment with a reference to a notice as an
@@ -1443,7 +1473,7 @@ class Notice extends Memcached_DataObject
 
     function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0)
     {
-        $cache = common_memcache();
+        $cache = Cache::instance();
 
         if (empty($cache) ||
             $since_id != 0 || $max_id != 0 ||
@@ -1453,7 +1483,7 @@ class Notice extends Memcached_DataObject
                                                                       $max_id)));
         }
 
-        $idkey = common_cache_key($cachekey);
+        $idkey = Cache::key($cachekey);
 
         $idstr = $cache->get($idkey);
 
@@ -1635,17 +1665,17 @@ class Notice extends Memcached_DataObject
 
     function repeatStream($limit=100)
     {
-        $cache = common_memcache();
+        $cache = Cache::instance();
 
         if (empty($cache)) {
             $ids = $this->_repeatStreamDirect($limit);
         } else {
-            $idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id));
+            $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
             if ($idstr !== false) {
                 $ids = explode(',', $idstr);
             } else {
                 $ids = $this->_repeatStreamDirect(100);
-                $cache->set(common_cache_key('notice:repeats:'.$this->id), implode(',', $ids));
+                $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
             }
             if ($limit < 100) {
                 // We do a max of 100, so slice down to limit
@@ -1796,10 +1826,10 @@ class Notice extends Memcached_DataObject
 
         if ($tag->find()) {
             while ($tag->fetch()) {
-                self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, common_keyize($tag->tag));
-                self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, common_keyize($tag->tag));
-                self::blow('notice_tag:notice_ids:%s', common_keyize($tag->tag));
-                self::blow('notice_tag:notice_ids:%s;last', common_keyize($tag->tag));
+                self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, Cache::keyize($tag->tag));
+                self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, Cache::keyize($tag->tag));
+                self::blow('notice_tag:notice_ids:%s', Cache::keyize($tag->tag));
+                self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($tag->tag));
                 $tag->delete();
             }
         }