diff options
author | Evan Prodromou <evan@status.net> | 2010-02-25 18:45:32 -0500 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2010-02-25 18:45:32 -0500 |
commit | 4aa82f75ed692e254c573096168e1cd7c0890ac6 (patch) | |
tree | 9fb87849f1f09c69c1c8e1a7c93d76fa283d5330 /classes/Notice.php | |
parent | 6578e0e1afed8e8738bbcb31d200927e10074f11 (diff) | |
parent | e254c660f66e1a04ac18220c95ef47aa88117e3c (diff) |
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'classes/Notice.php')
-rw-r--r-- | classes/Notice.php | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/classes/Notice.php b/classes/Notice.php index e8d5c45cb..46c5ebb37 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -121,6 +121,9 @@ class Notice extends Memcached_DataObject $result = parent::delete(); } + /** + * Extract #hashtags from this notice's content and save them to the database. + */ function saveTags() { /* extract all #hastags */ @@ -129,14 +132,22 @@ class Notice extends Memcached_DataObject 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); @@ -145,6 +156,10 @@ class Notice extends Memcached_DataObject 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(); @@ -194,6 +209,8 @@ class Notice extends Memcached_DataObject * 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 @@ -343,6 +360,8 @@ class Notice extends Memcached_DataObject $notice->blowOnInsert(); + // Save per-notice metadata... + if (isset($replies)) { $notice->saveKnownReplies($replies); } else { @@ -355,6 +374,16 @@ class Notice extends Memcached_DataObject $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; |