From d79dc8344b529281dfb8a8383c529720a429472b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Jul 2008 22:28:56 -0400 Subject: refactor notice-adding code to one static method on Notice darcs-hash:20080730022856-84dde-f19e4ff5d5ae2603b63b8aebd8f878ec90b3ce22.gz --- actions/newnotice.php | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'actions/newnotice.php') diff --git a/actions/newnotice.php b/actions/newnotice.php index 5f6a22484..8de6643a0 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -38,44 +38,27 @@ class NewnoticeAction extends Action { $user = common_current_user(); assert($user); # XXX: maybe an error instead... - $notice = new Notice(); - assert($notice); - $notice->profile_id = $user->id; # user id *is* profile id - $notice->is_local = 1; - $notice->created = DB_DataObject_Cast::dateTime(); - # Default theme uses 'content' for something else - $notice->content = $this->trimmed('status_textarea'); - - if (!$notice->content) { + $content = $this->trimmed('status_textarea'); + + if (!$content) { $this->show_form(_('No content!')); return; - } else if (strlen($notice->content) > 140) { + } else if (strlen($content) > 140) { $this->show_form(_('That\'s too long. Max notice size is 140 chars.')); return; } - $notice->rendered = common_render_content($notice->content, $notice); - - $id = $notice->insert(); - - if (!$id) { - common_server_error(_('Problem saving notice.')); + $notice = Notice::saveNew($user->id, $content, 'web'); + + if (is_string($notice)) { + $this->show_form($notice); return; } - - $orig = clone($notice); - $notice->uri = common_notice_uri($notice); - - if (!$notice->update($orig)) { - common_server_error(_('Problem saving notice.')); - return; - } - - common_save_replies($notice); - $notice->saveTags(); + common_broadcast_notice($notice); - + $returnto = $this->trimmed('returnto'); + if ($returnto) { $url = common_local_url($returnto, array('nickname' => $user->nickname)); -- cgit v1.2.3-54-g00ecf