From 5d84485001ace75c49cdc295b4ed3540db83e988 Mon Sep 17 00:00:00 2001 From: Mike Cochrane Date: Sun, 20 Jul 2008 01:57:02 -0400 Subject: First cut at hastags support. darcs-hash:20080720055702-533db-193ed842b0d0a952bef71a3c5287213ada0ef15c.gz --- classes/Notice.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'classes/Notice.php') 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; + } } -- cgit v1.2.3-54-g00ecf