summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
authorMike Cochrane <mikec@mikenz.geek.nz>2008-07-20 01:57:02 -0400
committerMike Cochrane <mikec@mikenz.geek.nz>2008-07-20 01:57:02 -0400
commit5d84485001ace75c49cdc295b4ed3540db83e988 (patch)
tree4100b04f90ecfecf95082c5fc2472bd7707e28f3 /classes/Notice.php
parente4f1d6f50444cf2ca6e9aaf7116d40eaa17b0f1c (diff)
First cut at hastags support.
darcs-hash:20080720055702-533db-193ed842b0d0a952bef71a3c5287213ada0ef15c.gz
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 1b9191ad6..02526bae2 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -51,4 +51,28 @@ class Notice extends DB_DataObject
function getProfile() {
return Profile::staticGet($this->profile_id);
}
+
+ function saveTags() {
+ /* extract all #hastags */
+ $count = preg_match_all('/(?:^|\s)#([a-z0-9]{1,64})/', strtolower($this->content), $match);
+ if (!$count) {
+ return true;
+ }
+
+ /* Add them to the database */
+ foreach(array_unique($match[1]) as $hashtag) {
+ $tag = DB_DataObject::factory('Notice_tag');
+ $tag->notice_id = $this->id;
+ $tag->tag = $hashtag;
+ $tag->created = $this->created;
+ $id = $tag->insert();
+ if (!$id) {
+ $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
+ common_log(LOG_ERROR, 'DB error inserting hashtag: ' . $last_error->message);
+ common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
+ return;
+ }
+ }
+ return true;
+ }
}