]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebooknoticeform.php
Merge branch '1.0.x' into schema-x
[quix0rs-gnu-social.git] / plugins / Facebook / facebooknoticeform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for posting a notice from within the Facebook App.
6  *
7  * This is a stripped down version of the normal NoticeForm (sans
8  * location stuff and media upload stuff). I'm not sure we can share the
9  * location (from FB) and they don't allow posting multipart form data
10  * to Facebook canvas pages, so that won't work anyway. --Zach
11  *
12  * PHP version 5
13  *
14  * LICENCE: This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Affero General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Affero General Public License for more details.
23  *
24  * You should have received a copy of the GNU Affero General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  *
27  * @category  Form
28  * @package   StatusNet
29  * @author    Evan Prodromou <evan@status.net>
30  * @author    Sarven Capadisli <csarven@status.net>
31  * @author    Zach Copley <zach@status.net>
32  * @copyright 2009 StatusNet, Inc.
33  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
34  * @link      http://status.net/
35  */
36
37 if (!defined('STATUSNET') && !defined('LACONICA')) {
38     exit(1);
39 }
40
41 require_once INSTALLDIR . '/lib/form.php';
42
43 /**
44  * Form for posting a notice from within the Facebook app
45  *
46  * @category Form
47  * @package  StatusNet
48  * @author   Evan Prodromou <evan@status.net>
49  * @author   Sarven Capadisli <csarven@status.net>
50  * @author   Zach Copey <zach@status.net>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://status.net/
53  *
54  * @see      HTMLOutputter
55  */
56 class FacebookNoticeForm extends Form
57 {
58     /**
59      * Current action, used for returning to this page.
60      */
61     var $action = null;
62
63     /**
64      * Pre-filled content of the form
65      */
66     var $content = null;
67
68     /**
69      * The current user
70      */
71     var $user = null;
72
73     /**
74      * The notice being replied to
75      */
76     var $inreplyto = null;
77
78     /**
79      * Constructor
80      *
81      * @param HTMLOutputter $out     output channel
82      * @param string        $action  action to return to, if any
83      * @param string        $content content to pre-fill
84      */
85     function __construct($out=null, $action=null, $content=null, $post_action=null, $user=null, $inreplyto=null)
86     {
87         parent::__construct($out);
88
89         $this->action  = $action;
90         $this->post_action = $post_action;
91         $this->content = $content;
92         $this->inreplyto = $inreplyto;
93
94         if ($user) {
95             $this->user = $user;
96         } else {
97             $this->user = common_current_user();
98         }
99
100         // Note: Facebook doesn't allow multipart/form-data posting to
101         // canvas pages, so don't try to set it--no file uploads, at
102         // least not this way.  It can be done using multiple servers
103         // and iFrames, but it's a pretty hacky process.
104     }
105
106     /**
107      * ID of the form
108      *
109      * @return string ID of the form
110      */
111     function id()
112     {
113         return 'form_notice';
114     }
115
116    /**
117      * Class of the form
118      *
119      * @return string class of the form
120      */
121     function formClass()
122     {
123         return 'form_notice';
124     }
125
126     /**
127      * Action of the form
128      *
129      * @return string URL of the action
130      */
131     function action()
132     {
133         return $this->post_action;
134     }
135
136     /**
137      * Legend of the Form
138      *
139      * @return void
140      */
141     function formLegend()
142     {
143         // TRANS: Legend.
144         $this->out->element('legend', null, _m('Send a notice'));
145     }
146
147     /**
148      * Data elements
149      *
150      * @return void
151      */
152     function formData()
153     {
154         if (Event::handle('StartShowNoticeFormData', array($this))) {
155             $this->out->element('label', array('for' => 'notice_data-text'),
156                                 // TRANS: Field label.
157                                 sprintf(_m('What\'s up, %s?'), $this->user->nickname));
158             // XXX: vary by defined max size
159             $this->out->element('textarea', array('id' => 'notice_data-text',
160                                                   'cols' => 35,
161                                                   'rows' => 4,
162                                                   'name' => 'status_textarea'),
163                                 ($this->content) ? $this->content : '');
164
165             $contentLimit = Notice::maxContent();
166
167             if ($contentLimit > 0) {
168                 $this->out->elementStart('dl', 'form_note');
169                 $this->out->element('dt', null, _m('Available characters'));
170                 $this->out->element('dd', array('id' => 'notice_text-count'),
171                                     $contentLimit);
172                 $this->out->elementEnd('dl');
173             }
174
175             if ($this->action) {
176                 $this->out->hidden('notice_return-to', $this->action, 'returnto');
177             }
178             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
179
180             Event::handle('StartShowNoticeFormData', array($this));
181         }
182     }
183
184     /**
185      * Action elements
186      *
187      * @return void
188      */
189     function formActions()
190     {
191         $this->out->element('input', array('id' => 'notice_action-submit',
192                                            'class' => 'submit',
193                                            'name' => 'status_submit',
194                                            'type' => 'submit',
195                                            // TRANS: Button text.
196                                            'value' => _m('BUTTON','Send')));
197     }
198 }