]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/noticeform.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / lib / noticeform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for posting a notice
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 notice
39  *
40  * Frequently-used form for posting a notice
41  *
42  * @category Form
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @author   Sarven Capadisli <csarven@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  *
49  * @see      HTMLOutputter
50  */
51 class NoticeForm extends Form
52 {
53     /**
54      * Current action, used for returning to this page.
55      */
56     var $actionName = null;
57
58     /**
59      * Pre-filled content of the form
60      */
61     var $content = null;
62
63     /**
64      * The current user
65      */
66     var $user = null;
67
68     /**
69      * The notice being replied to
70      */
71     var $inreplyto = null;
72
73     /**
74      * Pre-filled location content of the form
75      */
76
77     var $lat;
78     var $lon;
79     var $location_id;
80     var $location_ns;
81
82     /**
83      * Constructor
84      *
85      * @param Action $action  Action we're being embedded into
86      * @param array  $options Array of optional parameters
87      *                        'user' a user instead of current
88      *                        'content' notice content
89      *                        'inreplyto' ID of notice to reply to
90      *                        'lat' Latitude
91      *                        'lon' Longitude
92      *                        'location_id' ID of location
93      *                        'location_ns' Namespace of location
94      */
95     function __construct($action, $options=null)
96     {
97         // XXX: ??? Is this to keep notice forms distinct?
98         // Do we have to worry about sub-second race conditions?
99         // XXX: Needs to be above the parent::__construct() call...?
100
101         $this->id_suffix = time();
102
103         parent::__construct($action);
104
105         if (is_null($options)) {
106             $options = array();
107         }
108
109         $this->actionName  = $action->trimmed('action');
110
111         $prefill = array('content', 'inreplyto', 'lat', 
112                          'lon', 'location_id', 'location_ns');
113
114         foreach ($prefill as $fieldName) {
115             if (array_key_exists($fieldName, $options)) {
116                 $this->$fieldName = $options[$fieldName];
117             }
118         }
119
120         if (array_key_exists('user', $options)) {
121             $this->user = $options['user'];
122         } else {
123             $this->user = common_current_user();
124         }
125
126         $this->profile = $this->user->getProfile();
127
128         if (common_config('attachments', 'uploads')) {
129             $this->enctype = 'multipart/form-data';
130         }
131     }
132
133     /**
134      * ID of the form
135      *
136      * @return string ID of the form
137      */
138
139     function id()
140     {
141         return 'form_notice_' . $this->id_suffix;
142     }
143
144    /**
145      * Class of the form
146      *
147      * @return string class of the form
148      */
149
150     function formClass()
151     {
152         return 'form_notice ajax-notice';
153     }
154
155     /**
156      * Action of the form
157      *
158      * @return string URL of the action
159      */
160
161     function action()
162     {
163         return common_local_url('newnotice');
164     }
165
166     /**
167      * Legend of the Form
168      *
169      * @return void
170      */
171     function formLegend()
172     {
173         // TRANS: Form legend for notice form.
174         $this->out->element('legend', null, _('Send a notice'));
175     }
176
177     /**
178      * Data elements
179      *
180      * @return void
181      */
182     function formData()
183     {
184         if (Event::handle('StartShowNoticeFormData', array($this))) {
185             $this->out->element('label', array('for' => 'notice_data-text',
186                                                'id' => 'notice_data-text-label'),
187                                 // TRANS: Title for notice label. %s is the user's nickname.
188                                 sprintf(_('What\'s up, %s?'), $this->user->nickname));
189             // XXX: vary by defined max size
190             $this->out->element('textarea', array('class' => 'notice_data-text',
191                                                   'cols' => 35,
192                                                   'rows' => 4,
193                                                   'name' => 'status_textarea'),
194                                 ($this->content) ? $this->content : '');
195
196             $contentLimit = Notice::maxContent();
197
198             if ($contentLimit > 0) {
199                 $this->out->element('span',
200                                     array('class' => 'count'),
201                                     $contentLimit);
202             }
203
204             if (common_config('attachments', 'uploads')) {
205                 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
206                 $this->out->elementStart('label', array('class' => 'notice_data-attach'));
207                 // TRANS: Input label in notice form for adding an attachment.
208                 $this->out->text(_('Attach'));
209                 $this->out->element('input', array('class' => 'notice_data-attach',
210                                                    'type' => 'file',
211                                                    'name' => 'attach',
212                                                    // TRANS: Title for input field to attach a file to a notice.
213                                                    'title' => _('Attach a file.')));
214                 $this->out->elementEnd('label');
215             }
216             if (!empty($this->actionName)) {
217                 $this->out->hidden('notice_return-to', $this->actionName, 'returnto');
218             }
219             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
220
221             if ($this->user->shareLocation()) {
222                 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
223                 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
224                 $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id');
225                 $this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? (empty($this->profile->location_ns) ? null : $this->profile->location_ns) : $this->location_ns, 'location_ns');
226
227                 $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap',
228                                                       'data-api' => common_local_url('geocode')));
229
230                 // @fixme checkbox method allows no way to change the id without changing the name
231                 //$this->out->checkbox('notice_data-geo', _('Share my location'), true);
232                 $this->out->elementStart('label', 'notice_data-geo');
233                 $this->out->element('input', array(
234                     'name' => 'notice_data-geo',
235                     'type' => 'checkbox',
236                     'class' => 'checkbox',
237                     'id' => $this->id() . '-notice_data-geo',
238                     'checked' => true, // ?
239                 ));
240                 $this->out->text(' ');
241                 // TRANS: Field label to add location to a notice.
242                 $this->out->text(_('Share my location'));
243                 $this->out->elementEnd('label');
244                                
245                 $this->out->elementEnd('div');
246                 // TRANS: Text to not share location for a notice in notice form.
247                 $share_disable_text = _('Do not share my location');
248                 // TRANS: Timeout error text for location retrieval in notice form.
249                 $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
250                 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
251                     'ShareDisable: ' .json_encode($share_disable_text).','.
252                     'ErrorTimeout: ' .json_encode($error_timeout_text).
253                     '}');
254             }
255
256             Event::handle('EndShowNoticeFormData', array($this));
257         }
258     }
259
260     /**
261      * Action elements
262      *
263      * @return void
264      */
265
266     function formActions()
267     {
268         $this->out->element('input', array('id' => 'notice_action-submit',
269                                            'class' => 'submit',
270                                            'name' => 'status_submit',
271                                            'type' => 'submit',
272                                            // TRANS: Button text for sending notice.
273                                            'value' => _m('BUTTON', 'Send')));
274     }
275 }