]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/facebooknoticeform.php
Merge branch 'inblob' of git@gitorious.org:~evan/statusnet/evans-mainline into inblob
[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
57 class FacebookNoticeForm extends Form
58 {
59     /**
60      * Current action, used for returning to this page.
61      */
62
63     var $action = null;
64
65     /**
66      * Pre-filled content of the form
67      */
68
69     var $content = null;
70
71     /**
72      * The current user
73      */
74
75     var $user = null;
76
77     /**
78      * The notice being replied to
79      */
80
81     var $inreplyto = null;
82
83     /**
84      * Constructor
85      *
86      * @param HTMLOutputter $out     output channel
87      * @param string        $action  action to return to, if any
88      * @param string        $content content to pre-fill
89      */
90
91     function __construct($out=null, $action=null, $content=null, $post_action=null, $user=null, $inreplyto=null)
92     {
93         parent::__construct($out);
94
95         $this->action  = $action;
96         $this->post_action = $post_action;
97         $this->content = $content;
98         $this->inreplyto = $inreplyto;
99
100         if ($user) {
101             $this->user = $user;
102         } else {
103             $this->user = common_current_user();
104         }
105         
106         // Note: Facebook doesn't allow multipart/form-data posting to
107         // canvas pages, so don't try to set it--no file uploads, at
108         // least not this way.  It can be done using multiple servers
109         // and iFrames, but it's a pretty hacky process.
110     }
111
112     /**
113      * ID of the form
114      *
115      * @return string ID of the form
116      */
117
118     function id()
119     {
120         return 'form_notice';
121     }
122
123    /**
124      * Class of the form
125      *
126      * @return string class of the form
127      */
128
129     function formClass()
130     {
131         return 'form_notice';
132     }
133
134     /**
135      * Action of the form
136      *
137      * @return string URL of the action
138      */
139
140     function action()
141     {
142         return $this->post_action;
143     }
144
145     /**
146      * Legend of the Form
147      *
148      * @return void
149      */
150     function formLegend()
151     {
152         $this->out->element('legend', null, _('Send a notice'));
153     }
154
155     /**
156      * Data elements
157      *
158      * @return void
159      */
160
161     function formData()
162     {
163         if (Event::handle('StartShowNoticeFormData', array($this))) {
164             $this->out->element('label', array('for' => 'notice_data-text'),
165                                 sprintf(_('What\'s up, %s?'), $this->user->nickname));
166             // XXX: vary by defined max size
167             $this->out->element('textarea', array('id' => 'notice_data-text',
168                                                   'cols' => 35,
169                                                   'rows' => 4,
170                                                   'name' => 'status_textarea'),
171                                 ($this->content) ? $this->content : '');
172
173             $contentLimit = Notice::maxContent();
174
175             if ($contentLimit > 0) {
176                 $this->out->elementStart('dl', 'form_note');
177                 $this->out->element('dt', null, _('Available characters'));
178                 $this->out->element('dd', array('id' => 'notice_text-count'),
179                                     $contentLimit);
180                 $this->out->elementEnd('dl');
181             }
182
183             if ($this->action) {
184                 $this->out->hidden('notice_return-to', $this->action, 'returnto');
185             }
186             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
187
188             Event::handle('StartShowNoticeFormData', array($this));
189         }
190     }
191
192     /**
193      * Action elements
194      *
195      * @return void
196      */
197
198     function formActions()
199     {
200         $this->out->element('input', array('id' => 'notice_action-submit',
201                                            'class' => 'submit',
202                                            'name' => 'status_submit',
203                                            'type' => 'submit',
204                                            'value' => _('Send')));
205     }
206 }