3 * StatusNet, the distributed open-source microblogging tool
5 * Form for posting a notice
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.
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.
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/>.
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/
31 if (!defined('GNUSOCIAL')) { exit(1); }
34 * Form for posting a notice
36 * Frequently-used form for posting a notice
40 * @author Evan Prodromou <evan@status.net>
41 * @author Sarven Capadisli <csarven@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
47 class NoticeForm extends Form
50 * Current action, used for returning to this page.
52 var $actionName = null;
55 * Pre-filled content of the form
65 * The notice being replied to
67 var $inreplyto = null;
70 * Pre-filled location content of the form
78 /** select this group from the drop-down by default. */
81 /** select this user from the drop-down by default. */
84 /** Pre-click the private checkbox. */
90 * @param Action $action Action we're being embedded into
91 * @param array $options Array of optional parameters
92 * 'user' a user instead of current
93 * 'content' notice content
94 * 'inreplyto' ID of notice to reply to
97 * 'location_id' ID of location
98 * 'location_ns' Namespace of location
100 function __construct(Action $action, array $options = array())
102 // XXX: ??? Is this to keep notice forms distinct?
103 // Do we have to worry about sub-second race conditions?
104 // XXX: Needs to be above the parent::__construct() call...?
106 $this->id_suffix = rand();
108 parent::__construct($action);
110 $this->actionName = $action->trimmed('action');
112 $prefill = array('content', 'inreplyto', 'lat',
113 'lon', 'location_id', 'location_ns',
114 'to_group', 'to_profile', 'private');
116 foreach ($prefill as $fieldName) {
117 if (array_key_exists($fieldName, $options)) {
118 $this->$fieldName = $options[$fieldName];
122 // Prefill the profile if we're replying
124 if (empty($this->to_profile) &&
125 !empty($this->inreplyto)) {
126 $notice = Notice::getKV('id', $this->inreplyto);
127 if (!empty($notice)) {
128 $this->to_profile = $notice->getProfile();
132 if (array_key_exists('user', $options)) {
133 $this->user = $options['user'];
135 $this->user = common_current_user();
138 $this->profile = $this->user->getProfile();
140 if (common_config('attachments', 'uploads')) {
141 $this->enctype = 'multipart/form-data';
148 * @return string ID of the form
153 return 'form_notice_' . $this->id_suffix;
159 * @return string class of the form
164 return 'form_notice ajax-notice';
170 * @return string URL of the action
175 return common_local_url('newnotice');
183 function formLegend()
185 // TRANS: Form legend for notice form.
186 $this->out->element('legend', null, _('Send a notice'));
196 if (Event::handle('StartShowNoticeFormData', array($this))) {
197 $this->out->element('label', array('for' => 'notice_data-text',
198 'id' => 'notice_data-text-label'),
199 // TRANS: Title for notice label. %s is the user's nickname.
200 sprintf(_('What\'s up, %s?'), $this->user->nickname));
201 // XXX: vary by defined max size
202 $this->out->element('textarea', array('class' => 'notice_data-text',
203 'required' => 'required',
204 'placeholder' => _('Share your status...'),
207 'name' => 'status_textarea'),
208 ($this->content) ? $this->content : '');
210 $contentLimit = Notice::maxContent();
212 if ($contentLimit > 0) {
213 $this->out->element('span',
214 array('class' => 'count'),
218 if (common_config('attachments', 'uploads')) {
219 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
220 $this->out->elementStart('label', array('class' => 'notice_data-attach'));
221 // TRANS: Input label in notice form for adding an attachment.
222 $this->out->text(_('Attach'));
223 $this->out->element('input', array('class' => 'notice_data-attach',
226 // TRANS: Title for input field to attach a file to a notice.
227 'title' => _('Attach a file.')));
228 $this->out->elementEnd('label');
230 if (!empty($this->actionName)) {
231 $this->out->hidden('notice_return-to', $this->actionName, 'returnto');
233 $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
235 $this->out->elementStart('div', 'to-selector');
236 $toWidget = new ToSelector($this->out,
238 (!empty($this->to_group) ? $this->to_group : $this->to_profile));
241 $this->out->elementEnd('div');
243 if ($this->profile->shareLocation()) {
244 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
245 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
246 $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');
247 $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');
249 $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap',
250 'data-api' => common_local_url('geocode')));
252 // @fixme checkbox method allows no way to change the id without changing the name
253 //// TRANS: Checkbox label to allow sharing geo location in notices.
254 //$this->out->checkbox('notice_data-geo', _('Share my location'), true);
255 $this->out->elementStart('label', 'notice_data-geo');
256 $this->out->element('input', array(
257 'name' => 'notice_data-geo',
258 'type' => 'checkbox',
259 'class' => 'checkbox',
260 'id' => $this->id() . '-notice_data-geo',
261 'checked' => true, // ?
263 $this->out->text(' ');
264 // TRANS: Field label to add location to a notice.
265 $this->out->text(_('Share my location'));
266 $this->out->elementEnd('label');
268 $this->out->elementEnd('div');
269 // TRANS: Text to not share location for a notice in notice form.
270 $share_disable_text = _('Do not share my location');
271 // TRANS: Timeout error text for location retrieval in notice form.
272 $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
273 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
274 'ShareDisable: ' .json_encode($share_disable_text).','.
275 'ErrorTimeout: ' .json_encode($error_timeout_text).
279 Event::handle('EndShowNoticeFormData', array($this));
289 function formActions()
291 $this->out->element('input', array('id' => 'notice_action-submit',
293 'name' => 'status_submit',
295 // TRANS: Button text for sending notice.
296 'value' => _m('BUTTON', 'Send')));