summaryrefslogtreecommitdiff
path: root/lib/activity.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-25 11:26:33 -0800
committerBrion Vibber <brion@pobox.com>2010-02-25 11:26:33 -0800
commit79c0d52daa92b60e8eed80fa9459367c26f97122 (patch)
tree6bb2e206ef30cab5ce0cfbcf46b413f0633d57ee /lib/activity.php
parent39a8e9d8e679cfd02e47fa93aa26373101515cf9 (diff)
OStatus: save categories from the Atom entry as hashtags.
Diffstat (limited to 'lib/activity.php')
-rw-r--r--lib/activity.php61
1 files changed, 60 insertions, 1 deletions
diff --git a/lib/activity.php b/lib/activity.php
index 3de5f62c7..e592aad6f 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -859,6 +859,7 @@ class Activity
public $content; // HTML content of activity
public $id; // ID of the activity
public $title; // title of the activity
+ public $categories = array(); // list of AtomCategory objects
/**
* Turns a regular old Atom <entry> into a magical activity
@@ -947,6 +948,14 @@ class Activity
$this->summary = ActivityUtils::childContent($entry, 'summary');
$this->id = ActivityUtils::childContent($entry, 'id');
$this->content = ActivityUtils::getContent($entry);
+
+ $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category');
+ if ($catEls) {
+ for ($i = 0; $i < $catEls->length; $i++) {
+ $catEl = $catEls->item($i);
+ $this->categories[] = new AtomCategory($catEl);
+ }
+ }
}
/**
@@ -1011,6 +1020,10 @@ class Activity
$xs->raw($this->target->asString('activity:target'));
}
+ foreach ($this->categories as $cat) {
+ $xs->raw($cat->asString());
+ }
+
$xs->elementEnd('entry');
return $xs->getString();
@@ -1020,4 +1033,50 @@ class Activity
{
return ActivityUtils::child($element, $tag, $namespace);
}
-} \ No newline at end of file
+}
+
+class AtomCategory
+{
+ public $term;
+ public $scheme;
+ public $label;
+
+ function __construct($element=null)
+ {
+ if ($element && $element->attributes) {
+ $this->term = $this->extract($element, 'term');
+ $this->scheme = $this->extract($element, 'scheme');
+ $this->label = $this->extract($element, 'label');
+ }
+ }
+
+ protected function extract($element, $attrib)
+ {
+ $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib);
+ if ($node) {
+ return trim($node->textContent);
+ }
+ $node = $element->attributes->getNamedItem($attrib);
+ if ($node) {
+ return trim($node->textContent);
+ }
+ return null;
+ }
+
+ function asString()
+ {
+ $attribs = array();
+ if ($this->term !== null) {
+ $attribs['term'] = $this->term;
+ }
+ if ($this->scheme !== null) {
+ $attribs['scheme'] = $this->scheme;
+ }
+ if ($this->label !== null) {
+ $attribs['label'] = $this->label;
+ }
+ $xs = new XMLStringer();
+ $xs->element('category', $attribs);
+ return $xs->asString();
+ }
+}