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.'));
73 $id = $this->arg('id');
74 if (common_config('singleuser', 'enabled')) {
75 $tagger_arg = User::singleUserNickname();
77 $tagger_arg = $this->arg('tagger');
79 $tag_arg = $this->arg('tag');
81 $tagger = common_canonical_nickname($tagger_arg);
82 $tag = common_canonical_tag($tag_arg);
84 $current = common_current_user();
86 // Permanent redirect on non-canonical tag
88 if ($tagger_arg != $tagger || $tag_arg != $tag) {
89 $args = array('tagger' => $tagger, 'tag' => $tag);
90 common_redirect(common_local_url('editpeopletag', $args), 301);
96 $this->peopletag = Profile_list::getKV('id', $id);
97 if (!empty($this->peopletag)) {
98 $user = User::getKV('id', $this->peopletag->tagger);
102 // TRANS: Error message displayed when trying to perform an action that requires a tagging user or ID.
103 $this->clientError(_('No tagger or ID.'), 404);
107 $user = User::getKV('nickname', $tagger);
108 $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
111 if (!$this->peopletag) {
112 // TRANS: Client error displayed when referring to a non-existing list.
113 $this->clientError(_('No such list.'), 404);
118 // This should not be happening
119 // TRANS: Client error displayed when referring to non-local user.
120 $this->clientError(_('Not a local user.'), 404);
124 if ($current->id != $user->id) {
125 // TRANS: Client error displayed when reting to edit a tag that was not self-created.
126 $this->clientError(_('You must be the creator of the tag to edit it.'), 404);
130 $this->tagger = $user->getProfile();
138 * On GET, show the form. On POST, try to save the group.
140 * @param array $args unused
144 function handle($args)
146 parent::handle($args);
147 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
154 function showConfirm($msg=null, $fwd=null)
156 $this->confirm = $msg;
157 $this->confirm_args = $fwd;
161 function showConfirmForm()
163 $this->elementStart('form', array('id' => 'form_peopletag_edit_confirm',
164 'class' => 'form_settings',
166 'action' => common_local_url('editpeopletag',
167 array('tagger' => $this->tagger->nickname,
168 'tag' => $this->peopletag->tag))));
169 $this->elementStart('fieldset');
170 $this->hidden('token', common_session_token());
171 $this->hidden('id', $this->arg('id'));
173 foreach ($this->confirm_args as $key => $val) {
174 $this->hidden($key, $val);
177 $this->submit('form_action-no',
179 'submit form_action-primary',
181 $this->submit('form_action-yes',
183 'submit form_action-secondary',
185 $this->elementEnd('fieldset');
186 $this->elementEnd('form');
189 function showForm($msg=null)
195 function showObjectNav()
197 $nav = new PeopletagGroupNav($this, $this->peopletag);
201 function showContent()
203 if ($this->confirm) {
204 $this->showConfirmForm();
208 $form = new PeopletagEditForm($this, $this->peopletag);
211 $form->showProfileList();
214 function showPageNotice()
217 $this->element('p', 'error', $this->msg);
218 } else if ($this->confirm) {
219 $this->element('p', 'instructions', $this->confirm);
221 $this->element('p', 'instructions',
222 // TRANS: Form instruction for edit list form.
223 _('Use this form to edit the list.'));
227 function showScripts()
229 parent::showScripts();
230 $this->autofocus('tag');
235 $tag = common_canonical_tag($this->trimmed('tag'));
236 $description = $this->trimmed('description');
237 $private = $this->boolean('private');
238 $delete = $this->arg('delete');
239 $confirm = $this->arg('confirm');
240 $cancel = $this->arg('cancel');
242 if ($delete && $cancel) {
243 // TRANS: Form validation error displayed if the form data for deleting a tag was incorrect.
244 $this->showForm(_('Delete aborted.'));
248 $set_private = $private && $this->peopletag->private != $private;
250 if ($delete && !$confirm) {
251 // TRANS: Text in confirmation dialog for deleting a tag.
252 $this->showConfirm(_('Deleting this tag will permanantly remove ' .
253 'all its subscription and membership records. ' .
254 'Do you still want to continue?'), array('delete' => 1));
256 } else if (common_valid_tag($tag)) {
257 // TRANS: Form validation error displayed if a given tag is invalid.
258 $this->showForm(_('Invalid tag.'));
260 } else if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
261 // TRANS: Form validation error displayed if a given tag is already present.
262 // TRANS: %s is the already present tag.
263 $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
265 } else if (Profile_list::descriptionTooLong($description)) {
266 $this->showForm(sprintf(
267 // TRANS: Client error shown when providing too long a description when editing a list.
268 // TRANS: %d is the maximum number of allowed characters.
269 _m('Description is too long (maximum %d character).',
270 'Description is too long (maximum %d characters).',
271 Profile_list::maxDescription()),
272 Profile_list::maxDescription()));
274 } else if ($set_private && !$confirm && !$cancel) {
275 $fwd = array('tag' => $tag,
276 'description' => $description,
277 'private' => (int) $private);
279 // TRANS: Text in confirmation dialog for setting a tag from public to private.
280 $this->showConfirm(_('Setting a public tag as private will ' .
281 'permanently remove all the existing ' .
282 'subscriptions to it. Do you still want to continue?'), $fwd);
286 $this->peopletag->query('BEGIN');
288 $orig = clone($this->peopletag);
290 $this->peopletag->tag = $tag;
291 $this->peopletag->description = $description;
292 if (!$set_private || $confirm) {
293 $this->peopletag->private = $private;
296 $result = $this->peopletag->update($orig);
299 common_log_db_error($this->group, 'UPDATE', __FILE__);
300 // TRANS: Server error displayed when updating a list fails.
301 $this->serverError(_('Could not update list.'));
304 $this->peopletag->query('COMMIT');
306 if ($set_private && $confirm) {
307 Profile_tag_subscription::cleanup($this->peopletag);
311 // This might take quite a bit of time.
312 $this->peopletag->delete();
314 common_redirect(common_local_url('all',
315 array('nickname' => $this->tagger->nickname)),
319 if ($tag != $orig->tag) {
320 common_redirect(common_local_url('editpeopletag',
321 array('tagger' => $this->tagger->nickname,
325 // TRANS: Edit list form success message.
326 $this->showForm(_('Options saved.'));
330 function tagExists($tag)
332 $args = array('tagger' => $this->tagger->id, 'tag' => $tag);
333 $ptag = Profile_list::pkeyGet($args);
335 return !empty($ptag);