diff options
author | Mike Cochrane <mikec@mikenz.geek.nz> | 2008-07-20 01:57:02 -0400 |
---|---|---|
committer | Mike Cochrane <mikec@mikenz.geek.nz> | 2008-07-20 01:57:02 -0400 |
commit | 5d84485001ace75c49cdc295b4ed3540db83e988 (patch) | |
tree | 4100b04f90ecfecf95082c5fc2472bd7707e28f3 /classes | |
parent | e4f1d6f50444cf2ca6e9aaf7116d40eaa17b0f1c (diff) |
First cut at hastags support.
darcs-hash:20080720055702-533db-193ed842b0d0a952bef71a3c5287213ada0ef15c.gz
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Notice.php | 24 | ||||
-rw-r--r-- | classes/Notice_tag.php | 22 |
2 files changed, 46 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; + } } diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php new file mode 100644 index 000000000..0dc862bf3 --- /dev/null +++ b/classes/Notice_tag.php @@ -0,0 +1,22 @@ +<?php +/** + * Table Definition for notice_tag + */ +require_once 'DB/DataObject.php'; + +class Notice_tag extends DB_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'notice_tag'; // table name + public $tag; // varchar(64) primary_key not_null + public $notice_id; // int(4) primary_key not_null + public $created; // datetime() not_null + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice_tag',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} |