123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class NoticeForm extends Form
- {
-
- var $actionName = null;
-
- var $content = null;
-
- var $user = null;
-
- var $inreplyto = null;
-
- var $lat;
- var $lon;
- var $location_id;
- var $location_ns;
-
- var $to_group;
-
- var $to_profile;
-
- var $private;
-
- function __construct(Action $action, array $options = [])
- {
- parent::__construct($action);
-
-
- $this->id_suffix = rand();
- $this->actionName = $action->trimmed('action');
- $prefill = array('content', 'inreplyto', 'lat',
- 'lon', 'location_id', 'location_ns',
- 'to_group', 'to_profile', 'private');
- foreach ($prefill as $fieldName) {
- if (array_key_exists($fieldName, $options)) {
- $this->$fieldName = $options[$fieldName];
- }
- }
-
- if (empty($this->to_profile) &&
- !empty($this->inreplyto)) {
- $notice = Notice::getKV('id', $this->inreplyto);
- if (!empty($notice)) {
- $this->to_profile = $notice->getProfile();
- }
- }
- if (array_key_exists('user', $options)) {
- $this->user = $options['user'];
- } else {
- $this->user = common_current_user();
- }
- $this->profile = $this->user->getProfile();
- if (common_config('attachments', 'uploads')) {
- $this->enctype = 'multipart/form-data';
- }
- }
-
- function id()
- {
- return 'form_notice_' . $this->id_suffix;
- }
-
- function formClass()
- {
- return 'form_notice ajax-notice';
- }
-
- function action()
- {
- return common_local_url('newnotice');
- }
-
- function formLegend()
- {
-
- $this->out->element('legend', null, _('Send a notice'));
- }
- protected function placeholderText()
- {
- if ($this->inreplyto) {
- return _('Write a reply...');
- }
- return _('Share your status...');
- }
-
- function formData()
- {
- if (Event::handle('StartShowNoticeFormData', array($this))) {
- $this->out->element('label', array('for' => 'notice_data-text',
- 'id' => 'notice_data-text-label'),
-
- sprintf(_('What\'s up, %s?'), $this->user->nickname));
-
- $this->out->element('textarea', array('class' => 'notice_data-text',
- 'required' => 'required',
- 'placeholder' => $this->placeholderText(),
- 'cols' => 35,
- 'rows' => 4,
- 'name' => 'status_textarea'),
- ($this->content) ? $this->content : '');
- $contentLimit = Notice::maxContent();
- if ($contentLimit > 0) {
- $this->out->element('span',
- array('class' => 'count'),
- $contentLimit);
- }
- if (common_config('attachments', 'uploads')) {
- $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
- $this->out->element('label', array('class' => 'notice_data-attach',
- 'for' => $this->id().'-notice_data-attach'),
-
- _('Attach'));
-
- $this->out->element('input', array('class' => 'notice_data-attach',
- 'type' => 'file',
- 'name' => 'attach',
- 'id' => $this->id().'-notice_data-attach',
-
- 'title' => _('Attach a file.')));
- }
- if (!empty($this->actionName)) {
- $this->out->hidden('notice_return-to', $this->actionName, 'returnto');
- }
- $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
- $this->out->elementStart('div', 'to-selector');
- $toWidget = new ToSelector($this->out,
- $this->user,
- (!empty($this->to_group) ? $this->to_group : $this->to_profile));
- $toWidget->show();
- $this->out->elementEnd('div');
- if ($this->profile->shareLocation()) {
- $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
- $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
- $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');
- $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');
- $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap',
- 'data-api' => common_local_url('geocode')));
-
-
- $this->out->element('input', array(
- 'name' => 'notice_data-geo',
- 'type' => 'checkbox',
- 'class' => 'checkbox',
- 'id' => $this->id() . '-notice_data-geo',
- 'checked' => true,
- ));
- $this->out->element('label', array('class' => 'notice_data-geo',
- 'for' => $this->id().'-notice_data-geo'),
-
- _('Share my location'));
-
- $this->out->elementEnd('div');
-
- $share_disable_text = _('Do not share my location');
-
- $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
- $this->out->inlineScript(' var NoticeDataGeo_text = {'.
- 'ShareDisable: ' .json_encode($share_disable_text).','.
- 'ErrorTimeout: ' .json_encode($error_timeout_text).
- '}');
- }
- Event::handle('EndShowNoticeFormData', array($this));
- }
- }
-
- function formActions()
- {
- $this->out->element('input', array('id' => 'notice_action-submit',
- 'class' => 'submit',
- 'name' => 'status_submit',
- 'type' => 'submit',
-
- 'value' => _m('BUTTON', 'Send')));
- }
- }
|