]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupeditform.php
Merge branch 'testing' into privategroup
[quix0rs-gnu-social.git] / lib / groupeditform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for editing a group
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 editing a group
39  *
40  * @category Form
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Sarven Capadisli <csarven@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  * @see      UnsubscribeForm
48  */
49 class GroupEditForm extends Form
50 {
51     /**
52      * group for user to join
53      */
54     var $group = null;
55
56     /**
57      * Constructor
58      *
59      * @param Action     $out   output channel
60      * @param User_group $group group to join
61      */
62     function __construct($out=null, $group=null)
63     {
64         parent::__construct($out);
65
66         $this->group = $group;
67     }
68
69     /**
70      * ID of the form
71      *
72      * @return string ID of the form
73      */
74     function id()
75     {
76         if ($this->group) {
77             return 'form_group_edit-' . $this->group->id;
78         } else {
79             return 'form_group_add';
80         }
81     }
82
83     /**
84      * class of the form
85      *
86      * @return string of the form class
87      */
88     function formClass()
89     {
90         return 'form_settings';
91     }
92
93     /**
94      * Action of the form
95      *
96      * @return string URL of the action
97      */
98     function action()
99     {
100         if ($this->group) {
101             return common_local_url('editgroup',
102                                     array('nickname' => $this->group->nickname));
103         } else {
104             return common_local_url('newgroup');
105         }
106     }
107
108     /**
109      * Name of the form
110      *
111      * @return void
112      */
113     function formLegend()
114     {
115         $this->out->element('legend', null, _('Create a new group'));
116     }
117
118     /**
119      * Data elements of the form
120      *
121      * @return void
122      */
123     function formData()
124     {
125         if ($this->group) {
126             $id = $this->group->id;
127             $nickname = $this->group->nickname;
128             $fullname = $this->group->fullname;
129             $homepage = $this->group->homepage;
130             $description = $this->group->description;
131             $location = $this->group->location;
132         } else {
133             $id = '';
134             $nickname = '';
135             $fullname = '';
136             $homepage = '';
137             $description = '';
138             $location = '';
139         }
140
141         $this->out->elementStart('ul', 'form_data');
142         if (Event::handle('StartGroupEditFormData', array($this))) {
143             $this->out->elementStart('li');
144             $this->out->hidden('groupid', $id);
145             $this->out->input('nickname', _('Nickname'),
146                               ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $nickname,
147                               _('1-64 lowercase letters or numbers, no punctuation or spaces'));
148             $this->out->elementEnd('li');
149             $this->out->elementStart('li');
150             $this->out->input('fullname', _('Full name'),
151                               ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname);
152             $this->out->elementEnd('li');
153             $this->out->elementStart('li');
154             $this->out->input('homepage', _('Homepage'),
155                               ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
156                               _('URL of the homepage or blog of the group or topic.'));
157             $this->out->elementEnd('li');
158             $this->out->elementStart('li');
159             $desclimit = User_group::maxDescription();
160             if ($desclimit == 0) {
161                 $descinstr = _('Describe the group or topic');
162             } else {
163                 $descinstr = sprintf(_m('Describe the group or topic in %d character or less',
164                                         'Describe the group or topic in %d characters or less',
165                                         $desclimit),
166                                      $desclimit);
167             }
168             $this->out->textarea('description', _('Description'),
169                                  ($this->out->arg('description')) ? $this->out->arg('description') : $description,
170                                  $descinstr);
171             $this->out->elementEnd('li');
172             $this->out->elementStart('li');
173             $this->out->input('location', _('Location'),
174                               ($this->out->arg('location')) ? $this->out->arg('location') : $location,
175                               _('Location for the group, if any, like "City, State (or Region), Country".'));
176             $this->out->elementEnd('li');
177             if (common_config('group', 'maxaliases') > 0) {
178                 $aliases = (empty($this->group)) ? array() : $this->group->getAliases();
179                 $this->out->elementStart('li');
180                 $this->out->input('aliases', _('Aliases'),
181                                   ($this->out->arg('aliases')) ? $this->out->arg('aliases') :
182                                   (!empty($aliases)) ? implode(' ', $aliases) : '',
183                                   sprintf(_m('Extra nicknames for the group, separated with commas or spaces. Maximum %d alias allowed.',
184                                              'Extra nicknames for the group, separated with commas or spaces. Maximum %d aliases allowed.',
185                                              common_config('group', 'maxaliases')),
186                                           common_config('group', 'maxaliases')));;
187                 $this->out->elementEnd('li');
188             }
189             Event::handle('EndGroupEditFormData', array($this));
190         }
191         $this->out->elementEnd('ul');
192     }
193
194     /**
195      * Action elements
196      *
197      * @return void
198      */
199     function formActions()
200     {
201         $this->out->submit('submit', _m('BUTTON','Save'));
202     }
203 }