summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/Notice.php24
-rw-r--r--classes/Notice_tag.php22
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
+}