Add events for filtering and logging new notices

This commit is contained in:
Evan Prodromou 2009-02-13 10:52:26 -05:00
parent 47c5d508b3
commit 4ad5d55ecf
3 changed files with 43 additions and 29 deletions

View File

@ -76,3 +76,9 @@ StartShowContentBlock: Showing before the content container
EndShowContentBlock: Showing after the content container
- $action: the current action
StartNoticeSave: before inserting a notice (good place for content filters)
- $notice: notice being saved (no ID or URI)
EndNoticeSave: after inserting a notice and related code
- $notice: notice that was saved (with ID and URI)

View File

@ -98,7 +98,12 @@ class NewnoticeAction extends Action
return;
}
try {
$this->saveNewNotice();
} catch (Exception $e) {
$this->showForm($e->getMessage());
return;
}
} else {
$this->showForm();
}
@ -123,15 +128,13 @@ class NewnoticeAction extends Action
$content = $this->trimmed('status_textarea');
if (!$content) {
$this->showForm(_('No content!'));
return;
$this->clientError(_('No content!'));
} else {
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
$this->showForm(_('That\'s too long. '.
$this->clientError(_('That\'s too long. '.
'Max notice size is 140 chars.'));
return;
}
}
@ -154,7 +157,7 @@ class NewnoticeAction extends Action
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
$this->showForm($notice);
$this->clientError($notice);
return;
}

View File

@ -154,6 +154,8 @@ class Notice extends Memcached_DataObject
$notice->source = $source;
$notice->uri = $uri;
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
if (!$id) {
@ -181,6 +183,9 @@ class Notice extends Memcached_DataObject
$notice->addToInboxes();
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
}
# Clear the cache for subscribed users, so they'll update at next request
# XXX: someone clever could prepend instead of clearing the cache