]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileactionform.php
Don't accept non-objects before testing with "instanceof".
[quix0rs-gnu-social.git] / lib / profileactionform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Superclass for forms that operate on a profile
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  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Superclass for forms that operate on a profile
36  *
37  * Certain forms (block, silence, userflag, sandbox, delete) work on
38  * a single profile and work almost the same. So, this form extracts
39  * a lot of the common code to simplify those forms.
40  *
41  * @category Form
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class ProfileActionForm extends Form
49 {
50     /**
51      * Profile of user to act on
52      */
53
54     var $profile = null;
55
56     /**
57      * Return-to args
58      */
59
60     var $args = null;
61
62     /**
63      * Constructor
64      *
65      * @param HTMLOutputter $out     output channel
66      * @param Profile       $profile profile of user to act on
67      * @param array         $args    return-to args
68      */
69
70     function __construct($out=null, $profile=null, $args=null)
71     {
72         parent::__construct($out);
73
74         $this->profile = $profile;
75         $this->args    = $args;
76     }
77
78     /**
79      * ID of the form
80      *
81      * @return int ID of the form
82      */
83
84     function id()
85     {
86         return $this->target() . '-' . $this->profile->id;
87     }
88
89     /**
90      * class of the form
91      *
92      * @return string class of the form
93      */
94
95     function formClass()
96     {
97         return 'form_user_'.$this->target();
98     }
99
100     /**
101      * Action of the form
102      *
103      * @return string URL of the action
104      */
105
106     function action()
107     {
108         return common_local_url($this->target());
109     }
110
111     /**
112      * Legend of the Form
113      *
114      * @return void
115      */
116
117     function formLegend()
118     {
119         $this->out->element('legend', null, $this->description());
120     }
121
122     /**
123      * Data elements of the form
124      *
125      * @return void
126      */
127
128     function formData()
129     {
130         $action = $this->target();
131
132         $this->out->hidden($action.'to-' . $this->profile->id,
133                            $this->profile->id,
134                            'profileid');
135
136         if ($this->args) {
137             foreach ($this->args as $k => $v) {
138                 $this->out->hidden('returnto-' . $k, $v);
139             }
140         }
141     }
142
143     /**
144      * Action elements
145      *
146      * @return void
147      */
148
149     function formActions()
150     {
151         $this->out->submit('submit', $this->title(), 'submit',
152                            null, $this->description());
153     }
154
155     /**
156      * Action this form targets
157      *
158      * @return string Name of the action, lowercased.
159      */
160
161     function target()
162     {
163         return null;
164     }
165
166     /**
167      * Title of the form
168      *
169      * @return string Title of the form, internationalized
170      */
171
172     function title()
173     {
174         return null;
175     }
176
177     /**
178      * Description of the form
179      *
180      * @return string description of the form, internationalized
181      */
182
183     function description()
184     {
185         return null;
186     }
187 }