]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
More Favorite pluginification (favecount, cache, menus(favecount, cache, menus))
[quix0rs-gnu-social.git] / classes / Notice.php
index 917095acab075b383e6a754aba3d9c0f1e5ea010..4c831c7cc75645ccfdead4b2f1fc6cd5d8324e6d 100644 (file)
@@ -194,7 +194,6 @@ class Notice extends Managed_DataObject
 
             $this->clearReplies();
             $this->clearRepeats();
-            $this->clearFaves();
             $this->clearTags();
             $this->clearGroupInboxes();
             $this->clearFiles();
@@ -232,6 +231,19 @@ class Notice extends Managed_DataObject
         return common_local_url('shownotice', array('notice' => $this->id), null, null, false);
     }
 
+    public function getTitle()
+    {
+        $title = null;
+        if (Event::handle('GetNoticeTitle', array($this, &$title))) {
+            // TRANS: Title of a notice posted without a title value.
+            // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
+            $title = sprintf(_('%1$s\'s status on %2$s'),
+                             $this->getProfile()->getFancyName(),
+                             common_exact_date($this->created));
+        }
+        return $title;
+    }
+
     /*
      * Get the original representation URL of this notice.
      */
@@ -1717,16 +1729,18 @@ class Notice extends Managed_DataObject
 
         // favorite and repeated
 
+        $scoped = null;
         if (!empty($cur)) {
-            $cp = $cur->getProfile();
-            $noticeInfoAttr['favorite'] = ($cp->hasFave($this)) ? "true" : "false";
-            $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this)) ? "true" : "false";
+            $scoped = $cur->getProfile();
+            $noticeInfoAttr['repeated'] = ($scoped->hasRepeated($this)) ? "true" : "false";
         }
 
         if (!empty($this->repeat_of)) {
             $noticeInfoAttr['repeat_of'] = $this->repeat_of;
         }
 
+        Event::handle('StatusNetApiNoticeInfo', array($this, &$noticeInfoAttr, $scoped));
+
         return array('statusnet:notice_info', $noticeInfoAttr, null);
     }
 
@@ -2008,24 +2022,6 @@ class Notice extends Managed_DataObject
         }
     }
 
-    function clearFaves()
-    {
-        $fave = new Fave();
-        $fave->notice_id = $this->id;
-
-        if ($fave->find()) {
-            while ($fave->fetch()) {
-                self::blow('fave:ids_by_user_own:%d', $fave->user_id);
-                self::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
-                self::blow('fave:ids_by_user:%d', $fave->user_id);
-                self::blow('fave:ids_by_user:%d;last', $fave->user_id);
-                $fave->delete();
-            }
-        }
-
-        $fave->free();
-    }
-
     function clearTags()
     {
         $tag = new Notice_tag();
@@ -2557,14 +2553,13 @@ class Notice extends Managed_DataObject
                }
        }
 
-    static function _idsOf(&$notices)
+    static function _idsOf(array &$notices)
     {
                $ids = array();
                foreach ($notices as $notice) {
-                       $ids[] = $notice->id;
+                       $ids[$notice->id] = true;
                }
-               $ids = array_unique($ids);
-        return $ids;
+               return array_keys($ids);
     }
 
     static function fillAttachments(&$notices)
@@ -2596,47 +2591,6 @@ class Notice extends Managed_DataObject
                }
     }
 
-    protected $_faves = array();
-
-    /**
-     * All faves of this notice
-     *
-     * @return array Array of Fave objects
-     */
-
-    function getFaves()
-    {
-        if (isset($this->_faves[$this->id])) {
-            return $this->_faves[$this->id];
-        }
-        $faveMap = Fave::listGet('notice_id', array($this->id));
-        $this->_faves[$this->id] = $faveMap[$this->id];
-        return $this->_faves[$this->id];
-    }
-
-    function _setFaves($faves)
-    {
-        $this->_faves[$this->id] = $faves;
-    }
-
-    static function fillFaves(&$notices)
-    {
-        $ids = self::_idsOf($notices);
-        $faveMap = Fave::listGet('notice_id', $ids);
-        $cnt = 0;
-        $faved = array();
-        foreach ($faveMap as $id => $faves) {
-            $cnt += count($faves);
-            if (count($faves) > 0) {
-                $faved[] = $id;
-            }
-        }
-        foreach ($notices as $notice) {
-               $faves = $faveMap[$notice->id];
-            $notice->_setFaves($faves);
-        }
-    }
-
     static function fillReplies(&$notices)
     {
         $ids = self::_idsOf($notices);