3 * StatusNet, the distributed open-source microblogging tool
5 * Edit an existing group
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.
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.
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/>.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://status.net/
28 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 * This is the form for adding a new group
39 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40 * @link http://status.net/
43 class EditpeopletagAction extends Action
45 var $msg, $confirm, $confirm_args=array();
49 if ($_SERVER['REQUEST_METHOD'] == 'POST' && $this->boolean('delete')) {
50 // TRANS: Title for edit list page after deleting a tag.
51 // TRANS: %s is a list.
52 return sprintf(_('Delete %s list'), $this->peopletag->tag);
54 // TRANS: Title for edit list page.
55 // TRANS: %s is a list.
56 return sprintf(_('Edit list %s'), $this->peopletag->tag);
63 function prepare($args)
65 parent::prepare($args);
67 if (!common_logged_in()) {
68 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
69 $this->clientError(_('Not logged in.'));
72 $id = $this->arg('id');
73 if (common_config('singleuser', 'enabled')) {
74 $tagger_arg = User::singleUserNickname();
76 $tagger_arg = $this->arg('tagger');
78 $tag_arg = $this->arg('tag');
80 $tagger = common_canonical_nickname($tagger_arg);
81 $tag = common_canonical_tag($tag_arg);
83 $current = common_current_user();
85 // Permanent redirect on non-canonical tag
87 if ($tagger_arg != $tagger || $tag_arg != $tag) {
88 $args = array('tagger' => $tagger, 'tag' => $tag);
89 common_redirect(common_local_url('editpeopletag', $args), 301);
94 $this->peopletag = Profile_list::getKV('id', $id);
95 if (!empty($this->peopletag)) {
96 $user = User::getKV('id', $this->peopletag->tagger);
100 // TRANS: Error message displayed when trying to perform an action that requires a tagging user or ID.
101 $this->clientError(_('No tagger or ID.'), 404);
104 $user = User::getKV('nickname', $tagger);
105 $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
108 if (!$this->peopletag) {
109 // TRANS: Client error displayed when referring to a non-existing list.
110 $this->clientError(_('No such list.'), 404);
114 // This should not be happening
115 // TRANS: Client error displayed when referring to non-local user.
116 $this->clientError(_('Not a local user.'), 404);
119 if ($current->id != $user->id) {
120 // TRANS: Client error displayed when reting to edit a tag that was not self-created.
121 $this->clientError(_('You must be the creator of the tag to edit it.'), 404);
124 $this->tagger = $user->getProfile();
132 * On GET, show the form. On POST, try to save the group.
134 * @param array $args unused
138 function handle($args)
140 parent::handle($args);
141 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
148 function showConfirm($msg=null, $fwd=null)
150 $this->confirm = $msg;
151 $this->confirm_args = $fwd;
155 function showConfirmForm()
157 $this->elementStart('form', array('id' => 'form_peopletag_edit_confirm',
158 'class' => 'form_settings',
160 'action' => common_local_url('editpeopletag',
161 array('tagger' => $this->tagger->nickname,
162 'tag' => $this->peopletag->tag))));
163 $this->elementStart('fieldset');
164 $this->hidden('token', common_session_token());
165 $this->hidden('id', $this->arg('id'));
167 foreach ($this->confirm_args as $key => $val) {
168 $this->hidden($key, $val);
171 $this->submit('form_action-no',
173 'submit form_action-primary',
175 $this->submit('form_action-yes',
177 'submit form_action-secondary',
179 $this->elementEnd('fieldset');
180 $this->elementEnd('form');
183 function showForm($msg=null)
189 function showObjectNav()
191 $nav = new PeopletagGroupNav($this, $this->peopletag);
195 function showContent()
197 if ($this->confirm) {
198 $this->showConfirmForm();
202 $form = new PeopletagEditForm($this, $this->peopletag);
205 $form->showProfileList();
208 function showPageNotice()
211 $this->element('p', 'error', $this->msg);
212 } else if ($this->confirm) {
213 $this->element('p', 'instructions', $this->confirm);
215 $this->element('p', 'instructions',
216 // TRANS: Form instruction for edit list form.
217 _('Use this form to edit the list.'));
221 function showScripts()
223 parent::showScripts();
224 $this->autofocus('tag');
229 $tag = common_canonical_tag($this->trimmed('tag'));
230 $description = $this->trimmed('description');
231 $private = $this->boolean('private');
232 $delete = $this->arg('delete');
233 $confirm = $this->arg('confirm');
234 $cancel = $this->arg('cancel');
236 if ($delete && $cancel) {
237 // TRANS: Form validation error displayed if the form data for deleting a tag was incorrect.
238 $this->showForm(_('Delete aborted.'));
242 $set_private = $private && $this->peopletag->private != $private;
244 if ($delete && !$confirm) {
245 // TRANS: Text in confirmation dialog for deleting a tag.
246 $this->showConfirm(_('Deleting this tag will permanantly remove ' .
247 'all its subscription and membership records. ' .
248 'Do you still want to continue?'), array('delete' => 1));
250 } else if (common_valid_tag($tag)) {
251 // TRANS: Form validation error displayed if a given tag is invalid.
252 $this->showForm(_('Invalid tag.'));
254 } else if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
255 // TRANS: Form validation error displayed if a given tag is already present.
256 // TRANS: %s is the already present tag.
257 $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
259 } else if (Profile_list::descriptionTooLong($description)) {
260 $this->showForm(sprintf(
261 // TRANS: Client error shown when providing too long a description when editing a list.
262 // TRANS: %d is the maximum number of allowed characters.
263 _m('Description is too long (maximum %d character).',
264 'Description is too long (maximum %d characters).',
265 Profile_list::maxDescription()),
266 Profile_list::maxDescription()));
268 } else if ($set_private && !$confirm && !$cancel) {
269 $fwd = array('tag' => $tag,
270 'description' => $description,
271 'private' => (int) $private);
273 // TRANS: Text in confirmation dialog for setting a tag from public to private.
274 $this->showConfirm(_('Setting a public tag as private will ' .
275 'permanently remove all the existing ' .
276 'subscriptions to it. Do you still want to continue?'), $fwd);
280 // We tested $delete && !$confirm earlier so confirmation is required before getting here
282 // This might take quite a bit of time.
283 $this->peopletag->delete();
285 common_redirect(common_local_url('all', array('nickname' => $this->tagger->getNickname())), 303);
288 $this->peopletag->query('BEGIN');
290 $orig = clone($this->peopletag);
292 $this->peopletag->tag = $tag;
293 $this->peopletag->description = $description;
294 if (!$set_private || $confirm) {
295 $this->peopletag->private = $private;
298 $result = $this->peopletag->update($orig);
301 common_log_db_error($this->group, 'UPDATE', __FILE__);
302 // TRANS: Server error displayed when updating a list fails.
303 $this->serverError(_('Could not update list.'));
306 $this->peopletag->query('COMMIT');
308 if ($set_private && $confirm) {
309 Profile_tag_subscription::cleanup($this->peopletag);
312 if ($tag != $orig->tag) {
313 common_redirect(common_local_url('editpeopletag',
314 array('tagger' => $this->tagger->nickname,
318 // TRANS: Edit list form success message.
319 $this->showForm(_('Options saved.'));
323 function tagExists($tag)
325 $args = array('tagger' => $this->tagger->id, 'tag' => $tag);
326 $ptag = Profile_list::pkeyGet($args);
328 return !empty($ptag);