git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

groupeditform.php 8.96 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2
<?php
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Form for editing a group
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Form
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
26
 * @copyright 2009 StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
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/
Evan Prodromou's avatar
Evan Prodromou committed
29 30
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Evan Prodromou's avatar
Evan Prodromou committed
32 33 34 35 36 37 38 39 40
    exit(1);
}

require_once INSTALLDIR.'/lib/form.php';

/**
 * Form for editing a group
 *
 * @category Form
41
 * @package  StatusNet
42 43
 * @author   Evan Prodromou <evan@status.net>
 * @author   Sarven Capadisli <csarven@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
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/
Evan Prodromou's avatar
Evan Prodromou committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
 *
 * @see      UnsubscribeForm
 */
class GroupEditForm extends Form
{
    /**
     * group for user to join
     */
    var $group = null;

    /**
     * Constructor
     *
     * @param Action     $out   output channel
     * @param User_group $group group to join
     */
    function __construct($out=null, $group=null)
    {
        parent::__construct($out);

        $this->group = $group;
    }

    /**
     * ID of the form
     *
     * @return string ID of the form
     */
    function id()
    {
        if ($this->group) {
77
            return 'form_group_edit-' . $this->group->id;
Evan Prodromou's avatar
Evan Prodromou committed
78
        } else {
79
            return 'form_group_add';
Evan Prodromou's avatar
Evan Prodromou committed
80 81 82 83 84 85 86 87 88 89
        }
    }

    /**
     * class of the form
     *
     * @return string of the form class
     */
    function formClass()
    {
90
        return 'form_settings';
Evan Prodromou's avatar
Evan Prodromou committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    }

    /**
     * Action of the form
     *
     * @return string URL of the action
     */
    function action()
    {
        if ($this->group) {
            return common_local_url('editgroup',
                                    array('nickname' => $this->group->nickname));
        } else {
            return common_local_url('newgroup');
        }
    }

108 109 110 111 112 113 114
    /**
     * Name of the form
     *
     * @return void
     */
    function formLegend()
    {
115
        // TRANS: Form legend for group edit form.
116 117 118
        $this->out->element('legend', null, _('Create a new group'));
    }

Evan Prodromou's avatar
Evan Prodromou committed
119 120 121 122 123 124 125
    /**
     * Data elements of the form
     *
     * @return void
     */
    function formData()
    {
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        if ($this->group) {
            $id = $this->group->id;
            $nickname = $this->group->nickname;
            $fullname = $this->group->fullname;
            $homepage = $this->group->homepage;
            $description = $this->group->description;
            $location = $this->group->location;
        } else {
            $id = '';
            $nickname = '';
            $fullname = '';
            $homepage = '';
            $description = '';
            $location = '';
        }

Evan Prodromou's avatar
Evan Prodromou committed
142
        $this->out->elementStart('ul', 'form_data');
143 144 145
        if (Event::handle('StartGroupEditFormData', array($this))) {
            $this->out->elementStart('li');
            $this->out->hidden('groupid', $id);
146
            // TRANS: Field label on group edit form.
147 148
            $this->out->input('newnickname', _('Nickname'),
                              ($this->out->arg('newnickname')) ? $this->out->arg('newnickname') : $nickname,
149
                              // TRANS: Field title on group edit form.
150 151 152 153 154
                              _('1-64 lowercase letters or numbers, no punctuation or spaces.'),
                              null, false,
                              $this->group instanceof User_group && !common_config('profile', 'changenick')
                                    ? array('disabled'=>'disabled') // can't change nickname
                                    : array()); // either we can change nickname, or we're creating a new group.
155 156
            $this->out->elementEnd('li');
            $this->out->elementStart('li');
157
            // TRANS: Field label on group edit form.
158 159 160 161
            $this->out->input('fullname', _('Full name'),
                              ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname);
            $this->out->elementEnd('li');
            $this->out->elementStart('li');
162
            // TRANS: Field label on group edit form; points to "more info" for a group.
163 164
            $this->out->input('homepage', _('Homepage'),
                              ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
165
                              // TRANS: Field title on group edit form.
166 167 168 169 170
                              _('URL of the homepage or blog of the group or topic.'));
            $this->out->elementEnd('li');
            $this->out->elementStart('li');
            $desclimit = User_group::maxDescription();
            if ($desclimit == 0) {
171 172
                // TRANS: Text area title for group description when there is no text limit.
                $descinstr = _('Describe the group or topic.');
173
            } else {
174 175 176 177
                // TRANS: Text area title for group description.
                // TRANS: %d is the number of characters available for the description.
                $descinstr = sprintf(_m('Describe the group or topic in %d character or less.',
                                        'Describe the group or topic in %d characters or less.',
178 179 180
                                        $desclimit),
                                     $desclimit);
            }
181
            // TRANS: Text area label on group edit form; contains description of group.
182 183 184 185
            $this->out->textarea('description', _('Description'),
                                 ($this->out->arg('description')) ? $this->out->arg('description') : $description,
                                 $descinstr);
            $this->out->elementEnd('li');
186
            $this->out->elementStart('li');
187
            // TRANS: Field label on group edit form.
188 189
            $this->out->input('location', _('Location'),
                              ($this->out->arg('location')) ? $this->out->arg('location') : $location,
190
                              // TRANS: Field title on group edit form.
191
                              _('Location for the group, if any, like "City, State (or Region), Country".'));
192
            $this->out->elementEnd('li');
193 194 195
            if (common_config('group', 'maxaliases') > 0) {
                $aliases = (empty($this->group)) ? array() : $this->group->getAliases();
                $this->out->elementStart('li');
196
                // TRANS: Field label on group edit form.
197 198 199
                $this->out->input('aliases', _('Aliases'),
                                  ($this->out->arg('aliases')) ? $this->out->arg('aliases') :
                                  (!empty($aliases)) ? implode(' ', $aliases) : '',
200 201
                                  // TRANS: Input field title for group aliases.
                                  // TRANS: %d is the maximum number of group aliases available.
202 203 204 205 206 207
                                  sprintf(_m('Extra nicknames for the group, separated with commas or spaces. Maximum %d alias allowed.',
                                             'Extra nicknames for the group, separated with commas or spaces. Maximum %d aliases allowed.',
                                             common_config('group', 'maxaliases')),
                                          common_config('group', 'maxaliases')));;
                $this->out->elementEnd('li');
            }
208
            $this->out->elementStart('li');
209 210
            // TRANS: Checkbox field label on group edit form to mark a group private.
            $this->out->checkbox('private', _m('LABEL','Private'), 
211 212
                                  ($this->out->arg('private')) ? $this->out->arg('private') :
                                 ((!empty($this->group)) ? $this->group->isPrivate() : false),
213 214
                                 // TRANS: Checkbox field title on group edit form to mark a group private.
                                 _('New members must be approved by admin and all posts are forced to be private.'));
215
            $this->out->elementEnd('li');
216
            Event::handle('EndGroupEditFormData', array($this));
217
        }
Evan Prodromou's avatar
Evan Prodromou committed
218 219 220 221 222 223 224 225 226 227
        $this->out->elementEnd('ul');
    }

    /**
     * Action elements
     *
     * @return void
     */
    function formActions()
    {
228
        // TRANS: Text for save button on group edit form.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
229
        $this->out->submit('submit', _m('BUTTON','Save'));
Evan Prodromou's avatar
Evan Prodromou committed
230 231
    }
}