]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
allow html content in summary and clean it out of title
authorEvan Prodromou <evan@status.net>
Sat, 20 Mar 2010 14:30:28 +0000 (09:30 -0500)
committerEvan Prodromou <evan@status.net>
Sat, 20 Mar 2010 14:30:28 +0000 (09:30 -0500)
lib/activity.php

index 478fcf7ae95f1e3cf0a2f9c14c0ed12a24dee1cc..de4e38c3cb0193fcec2396df2a5ba0c6e3d72434 100644 (file)
@@ -434,6 +434,17 @@ class ActivityUtils
         }
     }
 
+    static function childHtmlContent(DOMNode $element, $tag, $namespace=self::ATOM)
+    {
+        $el = self::child($element, $tag, $namespace);
+
+        if (empty($el)) {
+            return null;
+        } else {
+            return self::textConstruct($el);
+        }
+    }
+
     /**
      * Get the content of an atom:entry-like object
      *
@@ -448,47 +459,47 @@ class ActivityUtils
 
     static function getContent($element)
     {
-        $contentEl = ActivityUtils::child($element, self::CONTENT);
-
-        if (!empty($contentEl)) {
+        return self::childHtmlContent($element, self::CONTENT, self::ATOM);
+    }
 
-            $src  = $contentEl->getAttribute(self::SRC);
+    static function textConstruct($el)
+    {
+        $src  = $el->getAttribute(self::SRC);
 
-            if (!empty($src)) {
-                throw new ClientException(_("Can't handle remote content yet."));
-            }
+        if (!empty($src)) {
+            throw new ClientException(_("Can't handle remote content yet."));
+        }
 
-            $type = $contentEl->getAttribute(self::TYPE);
+        $type = $el->getAttribute(self::TYPE);
 
-            // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
+        // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
 
-            if (empty($type) || $type == 'text') {
-                return $contentEl->textContent;
-            } else if ($type == 'html') {
-                $text = $contentEl->textContent;
-                return htmlspecialchars_decode($text, ENT_QUOTES);
-            } else if ($type == 'xhtml') {
-                $divEl = ActivityUtils::child($contentEl, 'div', 'http://www.w3.org/1999/xhtml');
-                if (empty($divEl)) {
-                    return null;
-                }
-                $doc = $divEl->ownerDocument;
-                $text = '';
-                $children = $divEl->childNodes;
+        if (empty($type) || $type == 'text') {
+            return $el->textContent;
+        } else if ($type == 'html') {
+            $text = $el->textContent;
+            return htmlspecialchars_decode($text, ENT_QUOTES);
+        } else if ($type == 'xhtml') {
+            $divEl = ActivityUtils::child($el, 'div', 'http://www.w3.org/1999/xhtml');
+            if (empty($divEl)) {
+                return null;
+            }
+            $doc = $divEl->ownerDocument;
+            $text = '';
+            $children = $divEl->childNodes;
 
-                for ($i = 0; $i < $children->length; $i++) {
-                    $child = $children->item($i);
-                    $text .= $doc->saveXML($child);
-                }
-                return trim($text);
-            } else if (in_array($type, array('text/xml', 'application/xml')) ||
-                       preg_match('#(+|/)xml$#', $type)) {
-                throw new ClientException(_("Can't handle embedded XML content yet."));
-            } else if (strncasecmp($type, 'text/', 5)) {
-                return $contentEl->textContent;
-            } else {
-                throw new ClientException(_("Can't handle embedded Base64 content yet."));
+            for ($i = 0; $i < $children->length; $i++) {
+                $child = $children->item($i);
+                $text .= $doc->saveXML($child);
             }
+            return trim($text);
+        } else if (in_array($type, array('text/xml', 'application/xml')) ||
+                   preg_match('#(+|/)xml$#', $type)) {
+            throw new ClientException(_("Can't handle embedded XML content yet."));
+        } else if (strncasecmp($type, 'text/', 5)) {
+            return $el->textContent;
+        } else {
+            throw new ClientException(_("Can't handle embedded Base64 content yet."));
         }
     }
 }
@@ -700,12 +711,16 @@ class ActivityObject
         }
 
         $this->id      = $this->_childContent($element, self::ID);
-        $this->title   = $this->_childContent($element, self::TITLE);
-        $this->summary = $this->_childContent($element, self::SUMMARY);
+        $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
+        $this->content = ActivityUtils::getContent($element);
 
-        $this->source  = $this->_getSource($element);
+        // We don't like HTML in our titles, although it's technically allowed
 
-        $this->content = ActivityUtils::getContent($element);
+        $title = ActivityUtils::childHtmlContent($element, self::TITLE);
+
+        $this->title = html_entity_decode(strip_tags($title));
+
+        $this->source  = $this->_getSource($element);
 
         $this->link = ActivityUtils::getPermalink($element);
     }