]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/newnotice.php
considerable coding
[quix0rs-gnu-social.git] / actions / newnotice.php
1 <?php
2
3 class NewnoticeAction extends Action {
4         
5         function handle($args) {
6                 parent::handle($args);
7                 # XXX: Ajax!
8
9                 if (!common_logged_in()) {
10                         common_user_error(_t('Not logged in.'));
11                 } else if ($this->arg('METHOD') == 'POST') {
12                         if ($this->save_new_notice()) {
13                                 # XXX: smarter redirects
14                                 $user = common_current_user();
15                                 assert(!is_null($user)); # see if... above
16                                 # XXX: redirect to source
17                                 # XXX: use Ajax instead of a redirect
18                                 common_redirect(common_local_url('all',
19                                                                                                  array('nickname' =>
20                                                                                                            $user->nickname)));
21                         } else {
22                                 common_server_error(_t('Problem saving notice.'));
23                         }
24                 } else {
25                         $this->show_form();
26                 }
27         }
28         
29         function save_new_notice() {
30                 $user = common_current_user();
31                 assert($user); # XXX: maybe an error instead...
32                 $notice = DB_DataObject::factory('notice');
33                 assert($notice);
34                 $notice->profile_id = $user->id; # user id *is* profile id
35                 $notice->content = $this->arg('content');
36                 $notice->created = time();
37                 return $notice->insert();
38         }
39         
40         function show_form() {
41                 common_start_element('form', array('id' => 'newnotice', 'method' => 'POST',
42                                                                                    'action' => common_local_url('newnotice')));
43                 common_element('span', 'nickname', $profile->nickname);
44                 common_element('textarea', array('rows' => 4, 'cols' => 80, 'id' => 'content'));
45                 common_element('input', array('type' => 'submit'), 'Send');
46                 common_end_element('form');
47         }
48 }