summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-08-13 11:29:18 -0700
committerEvan Prodromou <evan@status.net>2010-08-13 11:29:18 -0700
commite2128b201952131ab78344b089b72a0b74521c86 (patch)
treeb3e0ad2da25dcfe7a88c268ca7eeeba9e1745759
parent7dd46222a86a54be9d268a36291b795087fbd5c8 (diff)
save the notice title when the notice is saved
-rw-r--r--plugins/NoticeTitle/NoticeTitlePlugin.php33
-rw-r--r--plugins/NoticeTitle/Notice_title.php2
2 files changed, 34 insertions, 1 deletions
diff --git a/plugins/NoticeTitle/NoticeTitlePlugin.php b/plugins/NoticeTitle/NoticeTitlePlugin.php
index 524faef3a..86a74a4da 100644
--- a/plugins/NoticeTitle/NoticeTitlePlugin.php
+++ b/plugins/NoticeTitle/NoticeTitlePlugin.php
@@ -70,7 +70,7 @@ class NoticeTitlePlugin extends Plugin
$schema->ensureTable('notice_title',
array(new ColumnDef('notice_id', 'integer', null, true, 'PRI'),
- new ColumnDef('title', 'varchar', 255, false)));
+ new ColumnDef('title', 'varchar', Notice_title::MAXCHARS, false)));
return true;
}
@@ -114,11 +114,42 @@ class NoticeTitlePlugin extends Plugin
'id' => 'notice_title',
'name' => 'notice_title',
'size' => 40,
+ 'maxlength' => Notice_title::MAXCHARS,
'value' => _m('Title'),
'style' => 'color: 333333',
'onFocus' => 'this.value = ""; this.style = \'color: black\';'));
return true;
}
+ function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options)
+ {
+ $title = $action->trimmed('notice_title');
+ if (!empty($title)) {
+ if (mb_strlen($title) > Notice_title::MAXCHARS) {
+ throw new Exception(sprintf(_m("Notice title too long (max %d chars)", Notice_title::MAXCHARS)));
+ }
+ }
+ return true;
+ }
+
+ function onEndNoticeSaveWeb($action, $notice)
+ {
+ if (!empty($notice)) {
+
+ $title = $action->trimmed('notice_title');
+
+ if (!empty($title)) {
+
+ $nt = new Notice_title();
+
+ $nt->notice_id = $notice->id;
+ $nt->title = $title;
+
+ $nt->insert();
+ }
+ }
+
+ return true;
+ }
}
diff --git a/plugins/NoticeTitle/Notice_title.php b/plugins/NoticeTitle/Notice_title.php
index ed71f1356..44d56b496 100644
--- a/plugins/NoticeTitle/Notice_title.php
+++ b/plugins/NoticeTitle/Notice_title.php
@@ -47,6 +47,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Notice_title extends Memcached_DataObject
{
+ const MAXCHARS = 255;
+
public $__table = 'notice_title'; // table name
public $notice_id; // int(4) primary_key not_null
public $title; // varchar(255)