summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-21 09:15:57 -0500
committerEvan Prodromou <evan@status.net>2010-02-21 09:15:57 -0500
commit229f9bd069a25af9635a9eaaa822a614bf6e9348 (patch)
tree6309269f0f8d66c3c1c9254a9cc15cf7a6d53e04
parent6f1ccfc5770776c39bfe28543629e63a566ab541 (diff)
more complete content retrieval in ActivityObject::__construct()
-rw-r--r--plugins/OStatus/lib/activity.php67
1 files changed, 64 insertions, 3 deletions
diff --git a/plugins/OStatus/lib/activity.php b/plugins/OStatus/lib/activity.php
index 6d15f85b0..5f174d86f 100644
--- a/plugins/OStatus/lib/activity.php
+++ b/plugins/OStatus/lib/activity.php
@@ -183,6 +183,8 @@ class ActivityObject
const TITLE = 'title';
const SUMMARY = 'summary';
const CONTENT = 'content';
+ const TYPE = 'type';
+ const SRC = 'src';
const ID = 'id';
const SOURCE = 'source';
@@ -199,7 +201,7 @@ class ActivityObject
public $link;
public $source;
- /**
+ /**
* Constructor
*
* This probably needs to be refactored
@@ -243,10 +245,11 @@ class ActivityObject
$this->id = $this->_childContent($element, self::ID);
$this->title = $this->_childContent($element, self::TITLE);
$this->summary = $this->_childContent($element, self::SUMMARY);
- $this->content = $this->_childContent($element, self::CONTENT);
$this->source = $this->_getSource($element);
+ $this->content = $this->_getContent($element);
+
$this->link = ActivityUtils::getPermalink($element);
// XXX: grab PoCo stuff
@@ -284,7 +287,65 @@ class ActivityObject
}
}
- static fromNotice($notice)
+ /**
+ * Get the content of an atom:entry-like object
+ *
+ * @param DOMElement $element The element to examine.
+ *
+ * @return string unencoded HTML content of the element, like "This -&lt; is <b>HTML</b>."
+ *
+ * @todo handle remote content
+ * @todo handle embedded XML mime types
+ * @todo handle base64-encoded non-XML and non-text mime types
+ */
+
+ private function _getContent($element)
+ {
+ $contentEl = ActivityUtils::child($element, self::CONTENT);
+
+ if (!empty($contentEl)) {
+
+ $src = $contentEl->getAttribute(self::SRC);
+
+ if (!empty($src)) {
+ throw new ClientException(_("Can't handle remote content yet."));
+ }
+
+ $type = $contentEl->getAttribute(self::TYPE);
+
+ // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
+
+ if ($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');
+ 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(array('text/xml', 'application/xml'), $type) ||
+ 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."));
+ }
+ }
+ }
+
+ static function fromNotice($notice)
{
$object = new ActivityObject();