]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/messageform.php
Replies don't have verbs (we'll do some join magic later)
[quix0rs-gnu-social.git] / lib / messageform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for posting a direct message
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Form
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/form.php';
36
37 /**
38  * Form for posting a direct message
39  *
40  * @category Form
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Sarven Capadisli <csarven@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  *
47  * @see      HTMLOutputter
48  */
49 class MessageForm extends Form
50 {
51     /**
52      * User to send a direct message to
53      */
54     var $to = null;
55
56     /**
57      * Pre-filled content of the form
58      */
59     var $content = null;
60
61     /**
62      * Constructor
63      *
64      * @param HTMLOutputter $out     output channel
65      * @param User          $to      user to send a message to
66      * @param string        $content content to pre-fill
67      */
68     function __construct($out=null, $to=null, $content=null)
69     {
70         parent::__construct($out);
71
72         $this->to      = $to;
73         $this->content = $content;
74     }
75
76     /**
77      * ID of the form
78      *
79      * @return string ID of the form
80      */
81     function id()
82     {
83         return 'form_notice-direct';
84     }
85
86    /**
87      * Class of the form
88      *
89      * @return string class of the form
90      */
91     function formClass()
92     {
93         return 'form_notice ajax-notice';
94     }
95
96     /**
97      * Action of the form
98      *
99      * @return string URL of the action
100      */
101     function action()
102     {
103         return common_local_url('newmessage');
104     }
105
106     /**
107      * Legend of the Form
108      *
109      * @return void
110      */
111     function formLegend()
112     {
113         // TRANS: Form legend for direct notice.
114         $this->out->element('legend', null, _('Send a direct notice'));
115     }
116
117     /**
118      * Data elements
119      *
120      * @return void
121      */
122     function formData()
123     {
124         $user = common_current_user();
125
126         $mutual_users = $user->mutuallySubscribedUsers();
127
128         $mutual = array();
129         // TRANS: Label entry in drop-down selection box in direct-message inbox/outbox.
130         // TRANS: This is the default entry in the drop-down box, doubling as instructions
131         // TRANS: and a brake against accidental submissions with the first user in the list.
132         $mutual[0] = _('Select recipient:');
133
134         while ($mutual_users->fetch()) {
135             if ($mutual_users->id != $user->id) {
136                 $mutual[$mutual_users->id] = $mutual_users->nickname;
137             }
138         }
139
140         $mutual_users->free();
141         unset($mutual_users);
142
143         if (count($mutual) == 1) {
144             // TRANS: Entry in drop-down selection box in direct-message inbox/outbox when no one is available to message.
145             $mutual[0] = _('No mutual subscribers.');
146         }
147
148         // TRANS: Dropdown label in direct notice form.
149         $this->out->dropdown('to', _('To'), $mutual, null, false,
150                              ($this->to) ? $this->to->id : null);
151
152         $this->out->element('textarea', array('class' => 'notice_data-text',
153                                               'cols' => 35,
154                                               'rows' => 4,
155                                               'name' => 'content'),
156                             ($this->content) ? $this->content : '');
157
158         $contentLimit = Message::maxContent();
159
160         if ($contentLimit > 0) {
161             $this->out->element('span',
162                                 array('class' => 'count'),
163                                 $contentLimit);
164         }
165     }
166
167     /**
168      * Action elements
169      *
170      * @return void
171      */
172     function formActions()
173     {
174         $this->out->element('input', array('id' => 'notice_action-submit',
175                                            'class' => 'submit',
176                                            'name' => 'message_send',
177                                            'type' => 'submit',
178                                            // TRANS: Button text for sending a direct notice.
179                                            'value' => _m('Send button for sending notice', 'Send')));
180     }
181
182
183     /**
184      * Show the form
185      *
186      * Uses a recipe to output the form.
187      *
188      * @return void
189      * @see Widget::show()
190      */
191
192     function show()
193     {
194         $this->elementStart('div', 'input_forms');
195         $this->elementStart(
196             'div',
197             array(
198                 'id'    => 'input_form_direct',
199                 'class' => 'input_form current nonav'
200             )
201         );
202
203         parent::show();
204
205         $this->elementEnd('div');
206         $this->elementEnd('div');
207
208     }
209 }