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 OwnerDesignAction
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 $tagger_arg = $this->arg('tagger');
75 $tag_arg = $this->arg('tag');
77 $tagger = common_canonical_nickname($tagger_arg);
78 $tag = common_canonical_tag($tag_arg);
80 $current = common_current_user();
82 // Permanent redirect on non-canonical tag
84 if ($tagger_arg != $tagger || $tag_arg != $tag) {
85 $args = array('tagger' => $tagger, 'tag' => $tag);
86 common_redirect(common_local_url('editpeopletag', $args), 301);
92 $this->peopletag = Profile_list::staticGet('id', $id);
93 if (!empty($this->peopletag)) {
94 $user = User::staticGet('id', $this->peopletag->tagger);
98 // TRANS: Error message displayed when trying to perform an action that requires a tagging user or ID.
99 $this->clientError(_('No tagger or ID.'), 404);
103 $user = User::staticGet('nickname', $tagger);
104 $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
107 if (!$this->peopletag) {
108 // TRANS: Client error displayed when referring to a non-existing list.
109 $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);
120 if ($current->id != $user->id) {
121 // TRANS: Client error displayed when reting to edit a tag that was not self-created.
122 $this->clientError(_('You must be the creator of the tag to edit it.'), 404);
126 $this->tagger = $user->getProfile();
134 * On GET, show the form. On POST, try to save the group.
136 * @param array $args unused
140 function handle($args)
142 parent::handle($args);
143 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
150 function showConfirm($msg=null, $fwd=null)
152 $this->confirm = $msg;
153 $this->confirm_args = $fwd;
157 function showConfirmForm()
159 $this->elementStart('form', array('id' => 'form_peopletag_edit_confirm',
160 'class' => 'form_settings',
162 'action' => common_local_url('editpeopletag',
163 array('tagger' => $this->tagger->nickname,
164 'tag' => $this->peopletag->tag))));
165 $this->elementStart('fieldset');
166 $this->hidden('token', common_session_token());
167 $this->hidden('id', $this->arg('id'));
169 foreach ($this->confirm_args as $key => $val) {
170 $this->hidden($key, $val);
173 $this->submit('form_action-no',
175 'submit form_action-primary',
177 $this->submit('form_action-yes',
179 'submit form_action-secondary',
181 $this->elementEnd('fieldset');
182 $this->elementEnd('form');
185 function showForm($msg=null)
191 function showObjectNav()
193 $nav = new PeopletagGroupNav($this, $this->peopletag);
197 function showContent()
199 if ($this->confirm) {
200 $this->showConfirmForm();
204 $form = new PeopletagEditForm($this, $this->peopletag);
207 $form->showProfileList();
210 function showPageNotice()
213 $this->element('p', 'error', $this->msg);
214 } else if ($this->confirm) {
215 $this->element('p', 'instructions', $this->confirm);
217 $this->element('p', 'instructions',
218 // TRANS: Form instruction for edit list form.
219 _('Use this form to edit the list.'));
223 function showScripts()
225 parent::showScripts();
226 $this->autofocus('tag');
231 $tag = common_canonical_tag($this->trimmed('tag'));
232 $description = $this->trimmed('description');
233 $private = $this->boolean('private');
234 $delete = $this->arg('delete');
235 $confirm = $this->arg('confirm');
236 $cancel = $this->arg('cancel');
238 if ($delete && $cancel) {
239 // TRANS: Form validation error displayed if the form data for deleting a tag was incorrect.
240 $this->showForm(_('Delete aborted.'));
244 $set_private = $private && $this->peopletag->private != $private;
246 if ($delete && !$confirm) {
247 // TRANS: Text in confirmation dialog for deleting a tag.
248 $this->showConfirm(_('Deleting this tag will permanantly remove ' .
249 'all its subscription and membership records. ' .
250 'Do you still want to continue?'), array('delete' => 1));
252 } else if (common_valid_tag($tag)) {
253 // TRANS: Form validation error displayed if a given tag is invalid.
254 $this->showForm(_('Invalid tag.'));
256 } else if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
257 // TRANS: Form validation error displayed if a given tag is already present.
258 // TRANS: %s is the already present tag.
259 $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
261 } else if (Profile_list::descriptionTooLong($description)) {
262 $this->showForm(sprintf(
263 // TRANS: Client error shown when providing too long a description when editing a list.
264 // TRANS: %d is the maximum number of allowed characters.
265 _m('Description is too long (maximum %d character).',
266 'Description is too long (maximum %d characters).',
267 Profile_list::maxDescription()),
268 Profile_list::maxDescription()));
270 } else if ($set_private && !$confirm && !$cancel) {
271 $fwd = array('tag' => $tag,
272 'description' => $description,
273 'private' => (int) $private);
275 // TRANS: Text in confirmation dialog for setting a tag from public to private.
276 $this->showConfirm(_('Setting a public tag as private will ' .
277 'permanently remove all the existing ' .
278 'subscriptions to it. Do you still want to continue?'), $fwd);
282 $this->peopletag->query('BEGIN');
284 $orig = clone($this->peopletag);
286 $this->peopletag->tag = $tag;
287 $this->peopletag->description = $description;
288 if (!$set_private || $confirm) {
289 $this->peopletag->private = $private;
292 $result = $this->peopletag->update($orig);
295 common_log_db_error($this->group, 'UPDATE', __FILE__);
296 // TRANS: TRANS: Server error displayed when updating a list fails.
297 $this->serverError(_('Could not update list.'));
300 $this->peopletag->query('COMMIT');
302 if ($set_private && $confirm) {
303 Profile_tag_subscription::cleanup($this->peopletag);
307 // This might take quite a bit of time.
308 $this->peopletag->delete();
310 common_redirect(common_local_url('all',
311 array('nickname' => $this->tagger->nickname)),
315 if ($tag != $orig->tag) {
316 common_redirect(common_local_url('editpeopletag',
317 array('tagger' => $this->tagger->nickname,
321 // TRANS: Edit list form success message.
322 $this->showForm(_('Options saved.'));
326 function tagExists($tag)
328 $args = array('tagger' => $this->tagger->id, 'tag' => $tag);
329 $ptag = Profile_list::pkeyGet($args);
331 return !empty($ptag);