]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
fix call of common_find_mentions() in Notice::saveReplies()
[quix0rs-gnu-social.git] / classes / Notice.php
index 754c126ed150e5d74189a1ef27d9787d6e3b5c6f..3702dbcfa8e59010b1ee07aba9983eb8b1f1e3a8 100644 (file)
@@ -121,6 +121,9 @@ class Notice extends Memcached_DataObject
         $result = parent::delete();
     }
 
+    /**
+     * Extract #hashtags from this notice's content and save them to the database.
+     */
     function saveTags()
     {
         /* extract all #hastags */
@@ -129,14 +132,22 @@ class Notice extends Memcached_DataObject
             return true;
         }
 
+        /* Add them to the database */
+        return $this->saveKnownTags($match[1]);
+    }
+
+    /**
+     * Record the given set of hash tags in the db for this notice.
+     * Given tag strings will be normalized and checked for dupes.
+     */
+    function saveKnownTags($hashtags)
+    {
         //turn each into their canonical tag
         //this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
-        $hashtags = array();
-        for($i=0; $i<count($match[1]); $i++) {
-            $hashtags[] = common_canonical_tag($match[1][$i]);
+        for($i=0; $i<count($hashtags); $i++) {
+            $hashtags[$i] = common_canonical_tag($hashtags[$i]);
         }
 
-        /* Add them to the database */
         foreach(array_unique($hashtags) as $hashtag) {
             /* elide characters we don't want in the tag */
             $this->saveTag($hashtag);
@@ -145,6 +156,10 @@ class Notice extends Memcached_DataObject
         return true;
     }
 
+    /**
+     * Record a single hash tag as associated with this notice.
+     * Tag format and uniqueness must be validated by caller.
+     */
     function saveTag($hashtag)
     {
         $tag = new Notice_tag();
@@ -194,6 +209,8 @@ class Notice extends Memcached_DataObject
      *                              place of extracting @-replies from content.
      *              array 'groups' list of group IDs to deliver to, in place of
      *                              extracting ! tags from content
+     *              array 'tags' list of hashtag strings to save with the notice
+     *                           in place of extracting # tags from content
      * @fixme tag override
      *
      * @return Notice
@@ -265,12 +282,6 @@ class Notice extends Memcached_DataObject
 
         $notice->content = $final;
 
-        if (!empty($rendered)) {
-            $notice->rendered = $rendered;
-        } else {
-            $notice->rendered = common_render_content($final, $notice);
-        }
-
         $notice->source = $source;
         $notice->uri = $uri;
         $notice->url = $url;
@@ -298,6 +309,12 @@ class Notice extends Memcached_DataObject
             $notice->location_ns = $location_ns;
         }
 
+        if (!empty($rendered)) {
+            $notice->rendered = $rendered;
+        } else {
+            $notice->rendered = common_render_content($final, $notice);
+        }
+
         if (Event::handle('StartNoticeSave', array(&$notice))) {
 
             // XXX: some of these functions write to the DB
@@ -343,6 +360,8 @@ class Notice extends Memcached_DataObject
 
         $notice->blowOnInsert();
 
+        // Save per-notice metadata...
+
         if (isset($replies)) {
             $notice->saveKnownReplies($replies);
         } else {
@@ -355,6 +374,16 @@ class Notice extends Memcached_DataObject
             $notice->saveGroups();
         }
 
+        if (isset($tags)) {
+            $notice->saveKnownTags($tags);
+        } else {
+            $notice->saveTags();
+        }
+
+        // @fixme pass in data for URLs too?
+        $notice->saveUrls();
+
+        // Prepare inbox delivery, may be queued to background.
         $notice->distribute();
 
         return $notice;
@@ -915,6 +944,8 @@ class Notice extends Memcached_DataObject
                 $reply->profile_id = $user->id;
 
                 $id = $reply->insert();
+
+                self::blow('reply:stream:%d', $user->id);
             }
         }
 
@@ -942,7 +973,10 @@ class Notice extends Memcached_DataObject
 
         $sender = Profile::staticGet($this->profile_id);
 
-        $mentions = common_find_mentions($this->profile_id, $this->content);
+        // @todo ideally this parser information would only
+        // be calculated once.
+
+        $mentions = common_find_mentions($this->content, $this);
 
         $replied = array();
 
@@ -1067,6 +1101,8 @@ class Notice extends Memcached_DataObject
                            'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
                            'xmlns:georss' => 'http://www.georss.org/georss',
                            'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
+                           'xmlns:media' => 'http://purl.org/syndication/atommedia',
+                           'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
                            'xmlns:ostatus' => 'http://ostatus.org/schema/1.0');
         } else {
             $attrs = array();
@@ -1218,25 +1254,8 @@ class Notice extends Memcached_DataObject
      */
     function asActivityNoun($element)
     {
-        $xs = new XMLStringer(true);
-
-        $xs->elementStart('activity:' . $element);
-        $xs->element('activity:object-type',
-                     null,
-                     'http://activitystrea.ms/schema/1.0/note');
-        $xs->element('id',
-                     null,
-                     $this->uri);
-        $xs->element('content',
-                     array('type' => 'text/html'),
-                     $this->rendered);
-        $xs->element('link',
-                     array('type' => 'text/html',
-                           'rel'  => 'alternate',
-                           'href' => $this->bestUrl()));
-        $xs->elementEnd('activity:' . $element);
-
-        return $xs->getString();
+        $noun = ActivityObject::fromNotice($this);
+        return $noun->asString('activity:' . $element);
     }
 
     function bestUrl()