]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/noticeform.php
Merge branch '3cl' 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 $action = 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 HTMLOutputter $out     output channel
86      * @param string        $action  action to return to, if any
87      * @param string        $content content to pre-fill
88      */
89     function __construct($out=null, $action=null, $content=null, $user=null, $inreplyto=null, $lat=null, $lon=null, $location_id=null, $location_ns=null)
90     {
91         $this->id_suffix = time();
92
93         parent::__construct($out);
94
95         $this->action  = $action;
96         $this->content = $content;
97         $this->inreplyto = $inreplyto;
98         $this->lat = $lat;
99         $this->lon = $lon;
100         $this->location_id = $location_id;
101         $this->location_ns = $location_ns;
102
103         if ($user) {
104             $this->user = $user;
105         } else {
106             $this->user = common_current_user();
107         }
108
109         $this->profile = $this->user->getProfile();
110
111         if (common_config('attachments', 'uploads')) {
112             $this->enctype = 'multipart/form-data';
113         }
114     }
115
116     /**
117      * ID of the form
118      *
119      * @return string ID of the form
120      */
121
122     function id()
123     {
124         return 'form_notice_' . $this->id_suffix;
125     }
126
127    /**
128      * Class of the form
129      *
130      * @return string class of the form
131      */
132
133     function formClass()
134     {
135         return 'form_notice';
136     }
137
138     /**
139      * Action of the form
140      *
141      * @return string URL of the action
142      */
143
144     function action()
145     {
146         return common_local_url('newnotice');
147     }
148
149     /**
150      * Legend of the Form
151      *
152      * @return void
153      */
154     function formLegend()
155     {
156         // TRANS: Form legend for notice form.
157         $this->out->element('legend', null, _('Send a notice'));
158     }
159
160     /**
161      * Data elements
162      *
163      * @return void
164      */
165     function formData()
166     {
167         if (Event::handle('StartShowNoticeFormData', array($this))) {
168             $this->out->element('label', array('for' => 'notice_data-text',
169                                                'id' => 'notice_data-text-label'),
170                                 // TRANS: Title for notice label. %s is the user's nickname.
171                                 sprintf(_('What\'s up, %s?'), $this->user->nickname));
172             // XXX: vary by defined max size
173             $this->out->element('textarea', array('id' => 'notice_data-text',
174                                                   'cols' => 35,
175                                                   'rows' => 4,
176                                                   'name' => 'status_textarea'),
177                                 ($this->content) ? $this->content : '');
178
179             $contentLimit = Notice::maxContent();
180
181             if ($contentLimit > 0) {
182                 $this->out->element('span',
183                                     array('class' => 'count'),
184                                     $contentLimit);
185             }
186
187             if (common_config('attachments', 'uploads')) {
188                 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
189                 // TRANS: Input label in notice form for adding an attachment.
190                 $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
191                 $this->out->element('input', array('id' => 'notice_data-attach',
192                                                    'type' => 'file',
193                                                    'name' => 'attach',
194                                                    // TRANS: Title for input field to attach a file to a notice.
195                                                    'title' => _('Attach a file.')));
196             }
197             if ($this->action) {
198                 $this->out->hidden('notice_return-to', $this->action, 'returnto');
199             }
200             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
201
202             if ($this->user->shareLocation()) {
203                 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
204                 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
205                 $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');
206                 $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');
207
208                 $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap',
209                                                       'title' => common_local_url('geocode')));
210
211                 // @fixme checkbox method allows no way to change the id without changing the name
212                 //$this->out->checkbox('notice_data-geo', _('Share my location'), true);
213                 $this->out->element('input', array(
214                     'name' => 'notice_data-geo',
215                     'type' => 'checkbox',
216                     'class' => 'checkbox',
217                     'id' => $this->id() . '-notice_data-geo',
218                     'checked' => true, // ?
219                 ));
220                 $this->out->text(' ');
221                 $this->out->element('label', array('class' => 'notice_data-geo',
222                                               'for' => $this->id() . '-notice_data-geo'),
223                                // TRANS: Field label to add location to a notice.
224                                _('Share my location'));
225
226                 $this->out->elementEnd('div');
227                 // TRANS: Text to not share location for a notice in notice form.
228                 $share_disable_text = _('Do not share my location');
229                 // TRANS: Timeout error text for location retrieval in notice form.
230                 $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
231                 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
232                     'ShareDisable: ' .json_encode($share_disable_text).','.
233                     'ErrorTimeout: ' .json_encode($error_timeout_text).
234                     '}');
235             }
236
237             Event::handle('EndShowNoticeFormData', array($this));
238         }
239     }
240
241     /**
242      * Action elements
243      *
244      * @return void
245      */
246
247     function formActions()
248     {
249         $this->out->element('input', array('id' => 'notice_action-submit',
250                                            'class' => 'submit',
251                                            'name' => 'status_submit',
252                                            'type' => 'submit',
253                                            // TRANS: Button text for sending notice.
254                                            'value' => _m('BUTTON', 'Send')));
255     }
256 }