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('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/form.php';
38 * Form for posting a notice
40 * Frequently-used form for posting a notice
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/
51 class NoticeForm extends Form
54 * Current action, used for returning to this page.
56 var $actionName = null;
59 * Pre-filled content of the form
69 * The notice being replied to
71 var $inreplyto = null;
74 * Pre-filled location content of the form
82 /** select this group from the drop-down by default. */
85 /** select this user from the drop-down by default. */
88 /** Pre-click the private checkbox. */
94 * @param Action $action Action we're being embedded into
95 * @param array $options Array of optional parameters
96 * 'user' a user instead of current
97 * 'content' notice content
98 * 'inreplyto' ID of notice to reply to
101 * 'location_id' ID of location
102 * 'location_ns' Namespace of location
104 function __construct($action, $options=null)
106 // XXX: ??? Is this to keep notice forms distinct?
107 // Do we have to worry about sub-second race conditions?
108 // XXX: Needs to be above the parent::__construct() call...?
110 $this->id_suffix = time();
112 parent::__construct($action);
114 if (is_null($options)) {
118 $this->actionName = $action->trimmed('action');
120 $prefill = array('content', 'inreplyto', 'lat',
121 'lon', 'location_id', 'location_ns',
122 'to_group', 'to_profile', 'private');
124 foreach ($prefill as $fieldName) {
125 if (array_key_exists($fieldName, $options)) {
126 $this->$fieldName = $options[$fieldName];
130 // Prefill the profile if we're replying
132 if (empty($this->to_profile) &&
133 !empty($this->inreplyto)) {
134 $notice = Notice::staticGet('id', $this->inreplyto);
135 if (!empty($notice)) {
136 $this->to_profile = $notice->getProfile();
140 if (array_key_exists('user', $options)) {
141 $this->user = $options['user'];
143 $this->user = common_current_user();
146 $this->profile = $this->user->getProfile();
148 if (common_config('attachments', 'uploads')) {
149 $this->enctype = 'multipart/form-data';
156 * @return string ID of the form
161 return 'form_notice_' . $this->id_suffix;
167 * @return string class of the form
172 return 'form_notice ajax-notice';
178 * @return string URL of the action
183 return common_local_url('newnotice');
191 function formLegend()
193 // TRANS: Form legend for notice form.
194 $this->out->element('legend', null, _('Send a notice'));
204 if (Event::handle('StartShowNoticeFormData', array($this))) {
205 $this->out->element('label', array('for' => 'notice_data-text',
206 'id' => 'notice_data-text-label'),
207 // TRANS: Title for notice label. %s is the user's nickname.
208 sprintf(_('What\'s up, %s?'), $this->user->nickname));
209 // XXX: vary by defined max size
210 $this->out->element('textarea', array('class' => 'notice_data-text',
213 'name' => 'status_textarea'),
214 ($this->content) ? $this->content : '');
216 $contentLimit = Notice::maxContent();
218 if ($contentLimit > 0) {
219 $this->out->element('span',
220 array('class' => 'count'),
224 if (common_config('attachments', 'uploads')) {
225 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
226 $this->out->elementStart('label', array('class' => 'notice_data-attach'));
227 // TRANS: Input label in notice form for adding an attachment.
228 $this->out->text(_('Attach'));
229 $this->out->element('input', array('class' => 'notice_data-attach',
232 // TRANS: Title for input field to attach a file to a notice.
233 'title' => _('Attach a file.')));
234 $this->out->elementEnd('label');
236 if (!empty($this->actionName)) {
237 $this->out->hidden('notice_return-to', $this->actionName, 'returnto');
239 $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
241 $this->out->elementStart('div', 'to-selector');
242 $toWidget = new ToSelector($this->out,
244 (!empty($this->to_group) ? $this->to_group : $this->to_profile));
247 $this->out->elementEnd('div');
249 if ($this->user->shareLocation()) {
250 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
251 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
252 $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');
253 $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');
255 $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap',
256 'data-api' => common_local_url('geocode')));
258 // @fixme checkbox method allows no way to change the id without changing the name
259 //// TRANS: Checkbox label to allow sharing geo location in notices.
260 //$this->out->checkbox('notice_data-geo', _('Share my location'), true);
261 $this->out->elementStart('label', 'notice_data-geo');
262 $this->out->element('input', array(
263 'name' => 'notice_data-geo',
264 'type' => 'checkbox',
265 'class' => 'checkbox',
266 'id' => $this->id() . '-notice_data-geo',
267 'checked' => true, // ?
269 $this->out->text(' ');
270 // TRANS: Field label to add location to a notice.
271 $this->out->text(_('Share my location'));
272 $this->out->elementEnd('label');
274 $this->out->elementEnd('div');
275 // TRANS: Text to not share location for a notice in notice form.
276 $share_disable_text = _('Do not share my location');
277 // TRANS: Timeout error text for location retrieval in notice form.
278 $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
279 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
280 'ShareDisable: ' .json_encode($share_disable_text).','.
281 'ErrorTimeout: ' .json_encode($error_timeout_text).
285 Event::handle('EndShowNoticeFormData', array($this));
295 function formActions()
297 $this->out->element('input', array('id' => 'notice_action-submit',
299 'name' => 'status_submit',
301 // TRANS: Button text for sending notice.
302 'value' => _m('BUTTON', 'Send')));