$result = parent::delete();
}
+ /**
+ * Extract #hashtags from this notice's content and save them to the database.
+ */
function saveTags()
{
/* extract all #hastags */
return true;
}
+ /* Add them to the database */
+ return $this->saveKnownTags($match[1]);
+ }
+
+ /**
+ * Record the given set of hash tags in the db for this notice.
+ * Given tag strings will be normalized and checked for dupes.
+ */
+ function saveKnownTags($hashtags)
+ {
//turn each into their canonical tag
//this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
- $hashtags = array();
- for($i=0; $i<count($match[1]); $i++) {
- $hashtags[] = common_canonical_tag($match[1][$i]);
+ for($i=0; $i<count($hashtags); $i++) {
+ $hashtags[$i] = common_canonical_tag($hashtags[$i]);
}
- /* Add them to the database */
foreach(array_unique($hashtags) as $hashtag) {
/* elide characters we don't want in the tag */
$this->saveTag($hashtag);
return true;
}
+ /**
+ * Record a single hash tag as associated with this notice.
+ * Tag format and uniqueness must be validated by caller.
+ */
function saveTag($hashtag)
{
$tag = new Notice_tag();
* place of extracting @-replies from content.
* array 'groups' list of group IDs to deliver to, in place of
* extracting ! tags from content
+ * array 'tags' list of hashtag strings to save with the notice
+ * in place of extracting # tags from content
* @fixme tag override
*
* @return Notice
$notice->blowOnInsert();
+ // Save per-notice metadata...
+
if (isset($replies)) {
$notice->saveKnownReplies($replies);
} else {
$notice->saveGroups();
}
+ if (isset($tags)) {
+ $notice->saveKnownTags($tags);
+ } else {
+ $notice->saveTags();
+ }
+
+ // @fixme pass in data for URLs too?
+ $notice->saveUrls();
+
+ // Prepare inbox delivery, may be queued to background.
$notice->distribute();
return $notice;
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
$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);
+ }
+ }
}
/**
$xs->raw($this->target->asString('activity:target'));
}
+ foreach ($this->categories as $cat) {
+ $xs->raw($cat->asString());
+ }
+
$xs->elementEnd('entry');
return $xs->getString();
{
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();
+ }
+}
{
// XXX: do we need to change this for remote users?
- try {
- $notice->saveTags();
- } catch (Exception $e) {
- $this->logit($notice, $e);
- }
-
try {
$notice->addToInboxes();
} catch (Exception $e) {
$this->logit($notice, $e);
}
- try {
- $notice->saveUrls();
- } catch (Exception $e) {
- $this->logit($notice, $e);
- }
-
try {
Event::handle('EndNoticeSave', array($notice));
// Enqueue for other handlers
'uri' => $sourceUri,
'rendered' => $rendered,
'replies' => array(),
- 'groups' => array());
+ 'groups' => array(),
+ 'tags' => array());
+
// Check for optional attributes...
}
}
+ // Atom categories <-> hashtags
+ foreach ($activity->categories as $cat) {
+ if ($cat->term) {
+ $term = common_canonical_tag($cat->term);
+ if ($term) {
+ $options['tags'][] = $term;
+ }
+ }
+ }
+
try {
$saved = Notice::saveNew($oprofile->profile_id,
$content,