]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' into 0.9.x
authorBrion Vibber <brion@pobox.com>
Thu, 29 Apr 2010 22:14:51 +0000 (15:14 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 29 Apr 2010 22:14:51 +0000 (15:14 -0700)
Conflicts:
index.php

15 files changed:
classes/Notice.php
classes/Reply.php
lib/activity.php
lib/activityutils.php
lib/plugin.php
plugins/Blacklist/BlacklistPlugin.php
plugins/Blacklist/Homepage_blacklist.php
plugins/Blacklist/Nickname_blacklist.php
plugins/Blacklist/blacklistadminpanel.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/scripts/resub-feed.php [new file with mode: 0644]
plugins/OStatus/scripts/update-profile.php [new file with mode: 0644]
plugins/OpenID/openid.php
plugins/RSSCloud/RSSCloudPlugin.php
tests/ActivityParseTests.php

index 42c235b1a33c75466f05bb55914b629597e3d499..c0828674d17e5643b514316992644a5728e0a8a6 100644 (file)
@@ -1007,8 +1007,6 @@ class Notice extends Memcached_DataObject
                 $reply->profile_id = $user->id;
 
                 $id = $reply->insert();
-
-                self::blow('reply:stream:%d', $user->id);
             }
         }
 
@@ -1074,6 +1072,7 @@ class Notice extends Memcached_DataObject
                     throw new ServerException("Couldn't save reply for {$this->id}, {$mentioned->id}");
                 } else {
                     $replied[$mentioned->id] = 1;
+                    self::blow('reply:stream:%d', $mentioned->id);
                 }
             }
         }
@@ -1129,7 +1128,6 @@ class Notice extends Memcached_DataObject
         foreach ($recipientIds as $recipientId) {
             $user = User::staticGet('id', $recipientId);
             if (!empty($user)) {
-                self::blow('reply:stream:%d', $recipientId);
                 mail_notify_attn($user, $this);
             }
         }
index 659e04c9253934ad82dad90b0cd2ce4d198b32f5..dc6296bda347b9f78e8e31fa856a5f1c7681670c 100644 (file)
@@ -22,6 +22,20 @@ class Reply extends Memcached_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+    /**
+     * Wrapper for record insertion to update related caches
+     */
+    function insert()
+    {
+        $result = parent::insert();
+
+        if ($result) {
+            self::blow('reply:stream:%d', $this->profile_id);
+        }
+
+        return $result;
+    }
+
     function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
     {
         $ids = Notice::stream(array('Reply', '_streamDirect'),
index 365bb6258e919d9e2f95d9cae8997f6575649e78..8e2da99bb3afe46cb559a97178bc9e970178b86d 100644 (file)
@@ -83,6 +83,7 @@ class Activity
     const CREATOR = 'creator';
 
     const CONTENTNS = 'http://purl.org/rss/1.0/modules/content/';
+    const ENCODED = 'encoded';
 
     public $actor;   // an ActivityObject
     public $verb;    // a string (the URL)
@@ -269,14 +270,21 @@ class Activity
 
         $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, self::RSS);
 
-        $contentEl = ActivityUtils::child($item, ActivityUtils::CONTENT, self::CONTENTNS);
+        $contentEl = ActivityUtils::child($item, self::ENCODED, self::CONTENTNS);
 
         if (!empty($contentEl)) {
-            $this->content = htmlspecialchars_decode($contentEl->textContent, ENT_QUOTES);
+            // <content:encoded> XML node's text content is HTML; no further processing needed.
+            $this->content = $contentEl->textContent;
         } else {
             $descriptionEl = ActivityUtils::child($item, self::DESCRIPTION, self::RSS);
             if (!empty($descriptionEl)) {
-                $this->content = htmlspecialchars_decode($descriptionEl->textContent, ENT_QUOTES);
+                // Per spec, <description> must be plaintext.
+                // In practice, often there's HTML... but these days good
+                // feeds are using <content:encoded> which is explicitly
+                // real HTML.
+                // We'll treat this following spec, and do HTML escaping
+                // to convert from plaintext to HTML.
+                $this->content = htmlspecialchars($descriptionEl->textContent);
             }
         }
 
index a7e99fb11e32b91762649247fb51a2b80c9d3b42..401fd7fc283ff92b9b5d5a021ecbd6e74780fa74 100644 (file)
@@ -213,11 +213,19 @@ class ActivityUtils
         // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
 
         if (empty($type) || $type == 'text') {
-            return $el->textContent;
+            // We have plaintext saved as the XML text content.
+            // Since we want HTML, we need to escape any special chars.
+            return htmlspecialchars($el->textContent);
         } else if ($type == 'html') {
+            // We have HTML saved as the XML text content.
+            // No additional processing required once we've got it.
             $text = $el->textContent;
-            return htmlspecialchars_decode($text, ENT_QUOTES);
+            return $text;
         } else if ($type == 'xhtml') {
+            // Per spec, the <content type="xhtml"> contains a single
+            // HTML <div> with XHTML namespace on it as a child node.
+            // We need to pull all of that <div>'s child nodes and
+            // serialize them back to an (X)HTML source fragment.
             $divEl = ActivityUtils::child($el, 'div', 'http://www.w3.org/1999/xhtml');
             if (empty($divEl)) {
                 return null;
index 65ccdafbb02af1b82277b42f77aa7cd1734f446e..f63bdf30936b1e08f96e44424630d11cecefc79a 100644 (file)
@@ -91,6 +91,7 @@ class Plugin
             $path = INSTALLDIR . "/plugins/$name/locale";
             if (file_exists($path) && is_dir($path)) {
                 bindtextdomain($name, $path);
+                bind_textdomain_codeset($name, 'UTF-8');
             }
         }
     }
index adc4d9d7e21b2779cdb6296fc0bc3e71c7baad9c..63bffe2c6fb8babb1f62531f33b58519d7672a4a 100644 (file)
@@ -262,7 +262,7 @@ class BlacklistPlugin extends Plugin
         $patterns = $this->_getUrlPatterns();
 
         foreach ($patterns as $pattern) {
-            if (preg_match("/$pattern/", $url)) {
+            if ($pattern != '' && preg_match("/$pattern/", $url)) {
                 return false;
             }
         }
@@ -285,7 +285,7 @@ class BlacklistPlugin extends Plugin
         $patterns = $this->_getNicknamePatterns();
 
         foreach ($patterns as $pattern) {
-            if (preg_match("/$pattern/", $nickname)) {
+            if ($pattern != '' && preg_match("/$pattern/", $nickname)) {
                 return false;
             }
         }
index 32080667e1e7bf1889f9f5a52d0731e3816b71b8..ec89ee4bd884b87afa79f80eb635c87e34636d3b 100644 (file)
@@ -94,7 +94,7 @@ class Homepage_blacklist extends Memcached_DataObject
 
     function keys()
     {
-        return array('pattern' => 'K');
+        return array_keys($this->keyTypes());
     }
 
     /**
@@ -108,7 +108,7 @@ class Homepage_blacklist extends Memcached_DataObject
 
     function keyTypes()
     {
-        return $this->keys();
+        return array('pattern' => 'K');
     }
 
     /**
index 981063144485315f4f688a207b720154c1895495..e8545292d18ce18ebb3d47aee6147d74f2346eec 100644 (file)
@@ -88,7 +88,7 @@ class Nickname_blacklist extends Memcached_DataObject
 
     function keys()
     {
-        return array('pattern' => 'K');
+        return array_keys($this->keyTypes());
     }
 
     /**
@@ -99,7 +99,7 @@ class Nickname_blacklist extends Memcached_DataObject
 
     function keyTypes()
     {
-        return $this->keys();
+        return array('pattern' => 'K');
     }
 
     /**
index b996aba8dc932a4b47283fcde5d2fcf56e71d71e..4289dec1ba4326a79558a0950fe495ff0978be0f 100644 (file)
@@ -88,28 +88,27 @@ class BlacklistadminpanelAction extends AdminPanelAction
 
     function saveSettings()
     {
-        $nickPatterns = array();
-
-        $rawNickPatterns = explode("\n", $this->trimmed('blacklist-nicknames'));
-
-        foreach ($rawNickPatterns as $raw) {
-            $nickPatterns[] = trim($raw);
-        }
-
+        $nickPatterns = $this->splitPatterns($this->trimmed('blacklist-nicknames'));
         Nickname_blacklist::saveNew($nickPatterns);
 
-        $rawUrlPatterns = explode("\n", $this->trimmed('blacklist-urls'));
-        $urlPatterns  = array();
-
-        foreach ($rawUrlPatterns as $raw) {
-            $urlPatterns[] = trim($raw);
-        }
-
+        $urlPatterns = $this->splitPatterns($this->trimmed('blacklist-urls'));
         Homepage_blacklist::saveNew($urlPatterns);
 
         return;
     }
 
+    protected function splitPatterns($text)
+    {
+        $patterns = array();
+        foreach (explode("\n", $text) as $raw) {
+            $trimmed = trim($raw);
+            if ($trimmed != '') {
+                $patterns[] = $trimmed;
+            }
+        }
+        return $patterns;
+    }
+
     /**
      * Validate the values
      *
index e3b3daa2c56e7d4fa8037119936a4991794a8ff5..5d3f37cd07e00f4bdeb1349917639020a7ea0cb3 100644 (file)
@@ -1001,7 +1001,7 @@ class Ostatus_profile extends Memcached_DataObject
             return;
         }
         if (!common_valid_http_url($url)) {
-            throw new ServerException(_m("Invalid avatar URL %s"), $url);
+            throw new ServerException(sprintf(_m("Invalid avatar URL %s"), $url));
         }
 
         if ($this->isGroup()) {
@@ -1303,15 +1303,23 @@ class Ostatus_profile extends Memcached_DataObject
 
         $ok = $oprofile->insert();
 
-        if ($ok) {
-            $avatar = self::getActivityObjectAvatar($object, $hints);
-            if ($avatar) {
+        if (!$ok) {
+            throw new ServerException("Can't save OStatus profile");
+        }
+
+        $avatar = self::getActivityObjectAvatar($object, $hints);
+
+        if ($avatar) {
+            try {
                 $oprofile->updateAvatar($avatar);
+            } catch (Exception $ex) {
+                // Profile is saved, but Avatar is messed up. We're
+                // just going to continue.
+                common_log(LOG_WARNING, "Exception saving OStatus profile avatar: ". $ex->getMessage());
             }
-            return $oprofile;
-        } else {
-            throw new ServerException("Can't save OStatus profile");
         }
+
+        return $oprofile;
     }
 
     /**
@@ -1330,7 +1338,11 @@ class Ostatus_profile extends Memcached_DataObject
         }
         $avatar = self::getActivityObjectAvatar($object, $hints);
         if ($avatar) {
-            $this->updateAvatar($avatar);
+            try {
+                $this->updateAvatar($avatar);
+            } catch (Exception $ex) {
+                common_log(LOG_WARNING, "Exception saving OStatus profile avatar: " . $ex->getMessage());
+            }
         }
     }
 
diff --git a/plugins/OStatus/scripts/resub-feed.php b/plugins/OStatus/scripts/resub-feed.php
new file mode 100644 (file)
index 0000000..121d121
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$helptext = <<<END_OF_HELP
+resub-feed.php [options] http://example.com/atom-feed-url
+Reinitialize the PuSH subscription for the given feed. This may help get
+things restarted if we and the hub have gotten our states out of sync.
+
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (empty($args[0]) || !Validate::uri($args[0])) {
+    print "$helptext";
+    exit(1);
+}
+
+$feedurl = $args[0];
+
+
+$sub = FeedSub::staticGet('topic', $feedurl);
+if (!$sub) {
+    print "Feed $feedurl is not subscribed.\n";
+    exit(1);
+}
+
+print "Old state:\n";
+showSub($sub);
+
+print "\n";
+print "Pinging hub $sub->huburi with new subscription for $sub->uri\n";
+$ok = $sub->subscribe();
+
+if ($ok) {
+    print "ok\n";
+} else {
+    print "Could not confirm.\n";
+}
+
+$sub2 = FeedSub::staticGet('topic', $feedurl);
+
+print "\n";
+print "New state:\n";
+showSub($sub2);
+
+function showSub($sub)
+{
+    print "  Subscription state: $sub->sub_state\n";
+    print "  Verify token: $sub->verify_token\n";
+    print "  Signature secret: $sub->secret\n";
+    print "  Sub start date: $sub->sub_start\n";
+    print "  Record created: $sub->created\n";
+    print "  Record modified: $sub->modified\n";
+}
diff --git a/plugins/OStatus/scripts/update-profile.php b/plugins/OStatus/scripts/update-profile.php
new file mode 100644 (file)
index 0000000..d06de4f
--- /dev/null
@@ -0,0 +1,147 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$helptext = <<<END_OF_HELP
+update-profile.php [options] http://example.com/profile/url
+
+Rerun profile and feed info discovery for the given OStatus remote profile,
+and reinitialize its PuSH subscription for the given feed. This may help get
+things restarted if the hub or feed URLs have changed for the profile.
+
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (empty($args[0]) || !Validate::uri($args[0])) {
+    print "$helptext";
+    exit(1);
+}
+
+$uri = $args[0];
+
+
+$oprofile = Ostatus_profile::staticGet('uri', $uri);
+
+if (!$oprofile) {
+    print "No OStatus remote profile known for URI $uri\n";
+    exit(1);
+}
+
+print "Old profile state for $oprofile->uri\n";
+showProfile($oprofile);
+
+print "\n";
+print "Re-running feed discovery for profile URL $oprofile->uri\n";
+// @fixme will bork where the URI isn't the profile URL for now
+$discover = new FeedDiscovery();
+$feedurl = $discover->discoverFromURL($oprofile->uri);
+$huburi = $discover->getAtomLink('hub');
+$salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
+
+print "  Feed URL: $feedurl\n";
+print "  Hub URL: $huburi\n";
+print "  Salmon URL: $salmonuri\n";
+
+if ($feedurl != $oprofile->feeduri || $salmonuri != $oprofile->salmonuri) {
+    print "\n";
+    print "Updating...\n";
+    // @fixme update keys :P
+    #$orig = clone($oprofile);
+    #$oprofile->feeduri = $feedurl;
+    #$oprofile->salmonuri = $salmonuri;
+    #$ok = $oprofile->update($orig);
+    $ok = $oprofile->query('UPDATE ostatus_profile SET ' .
+        'feeduri=\'' . $oprofile->escape($feedurl) . '\',' .
+        'salmonuri=\'' . $oprofile->escape($salmonuri) . '\' ' .
+        'WHERE uri=\'' . $oprofile->escape($uri) . '\'');
+
+    if (!$ok) {
+        print "Failed to update profile record...\n";
+        exit(1);
+    }
+
+    $oprofile->decache();
+} else {
+    print "\n";
+    print "Ok, ostatus_profile record unchanged.\n\n";
+}
+
+$sub = FeedSub::ensureFeed($feedurl);
+
+if ($huburi != $sub->huburi) {
+    print "\n";
+    print "Updating hub record for feed; was $sub->huburi\n";
+    $orig = clone($sub);
+    $sub->huburi = $huburi;
+    $ok = $sub->update($orig);
+
+    if (!$ok) {
+        print "Failed to update sub record...\n";
+        exit(1);
+    }
+} else {
+    print "\n";
+    print "Feed record ok, not changing.\n\n";
+}
+
+print "\n";
+print "Pinging hub $sub->huburi with new subscription for $sub->uri\n";
+$ok = $sub->subscribe();
+
+if ($ok) {
+    print "ok\n";
+} else {
+    print "Could not confirm.\n";
+}
+
+$o2 = Ostatus_profile::staticGet('uri', $uri);
+
+print "\n";
+print "New profile state:\n";
+showProfile($o2);
+
+print "\n";
+print "New feed state:\n";
+$sub2 = FeedSub::ensureFeed($feedurl);
+showSub($sub2);
+
+function showProfile($oprofile)
+{
+    print "  Feed URL: $oprofile->feeduri\n";
+    print "  Salmon URL: $oprofile->salmonuri\n";
+    print "  Avatar URL: $oprofile->avatar\n";
+    print "  Profile ID: $oprofile->profile_id\n";
+    print "  Group ID: $oprofile->group_id\n";
+    print "  Record created: $oprofile->created\n";
+    print "  Record modified: $oprofile->modified\n";
+}
+
+function showSub($sub)
+{
+    print "  Subscription state: $sub->sub_state\n";
+    print "  Verify token: $sub->verify_token\n";
+    print "  Signature secret: $sub->secret\n";
+    print "  Sub start date: $sub->sub_start\n";
+    print "  Record created: $sub->created\n";
+    print "  Record modified: $sub->modified\n";
+}
index 1524389177eb5ee0e6eb158655539927ec30b343..4ec336e1c3d95fb3b421db1e25dbbee7c770aae4 100644 (file)
@@ -299,11 +299,21 @@ class AutosubmitAction extends Action
 
     function title()
     {
-        return _m('OpenID Auto-Submit');
+        return _m('OpenID Login Submission');
     }
 
     function showContent()
     {
+        $this->raw('<p style="margin: 20px 80px">');
+        // @fixme this would be better using standard CSS class, but the present theme's a bit scary.
+        $this->element('img', array('src' => Theme::path('images/icons/icon_processing.gif', 'base'),
+                                    // for some reason the base CSS sets <img>s as block display?!
+                                    'style' => 'display: inline'));
+        $this->text(_m('Requesting authorization from your login provider...'));
+        $this->raw('</p>');
+        $this->raw('<p style="margin-top: 60px; font-style: italic">');
+        $this->text(_m('If you are not redirected to your login provider in a few seconds, try pushing the button below.'));
+        $this->raw('</p>');
         $this->raw($this->form_html);
     }
 
@@ -311,8 +321,6 @@ class AutosubmitAction extends Action
     {
         parent::showScripts();
         $this->element('script', null,
-                       '$(document).ready(function() { ' .
-                       '    $(\'#'. $this->form_id .'\').submit(); '.
-                       '});');
+                       'document.getElementById(\'' . $this->form_id . '\').submit();');
     }
 }
index 001106aceceb4606b2a4e3a741bb90351720b704..661c32141faedf7a3f23c4edf86036543b3365df 100644 (file)
@@ -100,7 +100,7 @@ class RSSCloudPlugin extends Plugin
      *
      * Hook for RouterInitialized event.
      *
-     * @param Mapper &$m URL parser and mapper
+     * @param Mapper $m URL parser and mapper
      *
      * @return boolean hook return
      */
index 4563da914689cb1d642799509364bfef0ff0b0d9..378478d741d1cd3ce205a206ab8aaa7df0f6923b 100644 (file)
@@ -32,6 +32,18 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase
         $this->assertEquals('tag:versioncentral.example.org,2009:/change/1643245', $act->objects[0]->id);
     }
 
+    public function testExample2()
+    {
+        global $_example2;
+        $dom = DOMDocument::loadXML($_example2);
+        $act = new Activity($dom->documentElement);
+
+        $this->assertFalse(empty($act));
+        // Did we handle <content type="html"> correctly with a typical payload?
+        $this->assertEquals("<p>Geraldine posted a Photo on PhotoPanic</p>\n     " .
+                            "<img src=\"/geraldine/photo1.jpg\">", trim($act->content));
+    }
+
     public function testExample3()
     {
         global $_example3;
@@ -305,6 +317,71 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase
 
     }
 
+    public function testAtomContent()
+    {
+        $tests = array(array("<content>Some regular plain text.</content>",
+                             "Some regular plain text."),
+                       array("<content>&lt;b&gt;this is not HTML&lt;/b&gt;</content>",
+                             "&lt;b&gt;this is not HTML&lt;/b&gt;"),
+                       array("<content type='html'>Some regular plain HTML.</content>",
+                             "Some regular plain HTML."),
+                       array("<content type='html'>&lt;b&gt;this is too HTML&lt;/b&gt;</content>",
+                             "<b>this is too HTML</b>"),
+                       array("<content type='html'>&amp;lt;b&amp;gt;but this is not HTML!&amp;lt;/b&amp;gt;</content>",
+                             "&lt;b&gt;but this is not HTML!&lt;/b&gt;"),
+                       array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
+                             "Some regular plain XHTML."),
+                       array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is some XHTML!</b></div></content>",
+                             "<b>This is some XHTML!</b>"),
+                       array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML!&lt;/b&gt;</div></content>",
+                             "&lt;b&gt;This is not some XHTML!&lt;/b&gt;"),
+                       array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;</div></content>",
+                             "&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;"));
+        foreach ($tests as $data) {
+            list($source, $output) = $data;
+            $xml = "<entry xmlns='http://www.w3.org/2005/Atom'>" .
+                   "<id>http://example.com/fakeid</id>" .
+                   "<author><name>Test</name></author>" .
+                   "<title>Atom content tests</title>" .
+                   $source .
+                   "</entry>";
+            $dom = DOMDocument::loadXML($xml);
+            $act = new Activity($dom->documentElement);
+
+            $this->assertFalse(empty($act));
+            $this->assertEquals($output, trim($act->content));
+        }
+    }
+
+    public function testRssContent()
+    {
+        $tests = array(array("<content:encoded>Some regular plain HTML.</content:encoded>",
+                             "Some regular plain HTML."),
+                       array("<content:encoded>Some &lt;b&gt;exciting bold HTML&lt;/b&gt;</content:encoded>",
+                             "Some <b>exciting bold HTML</b>"),
+                       array("<content:encoded>Some &amp;lt;b&amp;gt;escaped non-HTML.&amp;lt;/b&amp;gt;</content:encoded>",
+                             "Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;"),
+                       array("<description>Some plain text.</description>",
+                             "Some plain text."),
+                       array("<description>Some &lt;b&gt;non-HTML text&lt;/b&gt;</description>",
+                             "Some &lt;b&gt;non-HTML text&lt;/b&gt;"),
+                       array("<description>Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;</description>",
+                             "Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;"));
+        foreach ($tests as $data) {
+            list($source, $output) = $data;
+            $xml = "<item xmlns:content='http://purl.org/rss/1.0/modules/content/'>" .
+                   "<guid>http://example.com/fakeid</guid>" .
+                   "<title>RSS content tests</title>" .
+                   $source .
+                   "</item>";
+            $dom = DOMDocument::loadXML($xml);
+            $act = new Activity($dom->documentElement);
+
+            $this->assertFalse(empty($act));
+            $this->assertEquals($output, trim($act->content));
+        }
+    }
+
 }
 
 $_example1 = <<<EXAMPLE1