summaryrefslogtreecommitdiff
path: root/lib/activity.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-03-20 09:30:28 -0500
committerEvan Prodromou <evan@status.net>2010-03-20 09:30:28 -0500
commit2fc0f0433ed5748edb5801473d653807db1c1462 (patch)
treedace72bbb692d5ea67809713a57ec6d45525fb6c /lib/activity.php
parent25cb9175231f1515c357035c797cb25ec0b01b44 (diff)
allow html content in summary and clean it out of title
Diffstat (limited to 'lib/activity.php')
-rw-r--r--lib/activity.php91
1 files changed, 53 insertions, 38 deletions
diff --git a/lib/activity.php b/lib/activity.php
index 478fcf7ae..de4e38c3c 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -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);
}