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
46 var $msg, $confirm, $confirm_args=array();
50 if ($_SERVER['REQUEST_METHOD'] == 'POST' && $this->boolean('delete')) {
51 return sprintf(_('Delete %s people tag'), $this->peopletag->tag);
53 return sprintf(_('Edit people tag %s'), $this->peopletag->tag);
60 function prepare($args)
62 parent::prepare($args);
64 if (!common_logged_in()) {
65 $this->clientError(_('Not logged in.'));
69 $id = $this->arg('id');
70 $tagger_arg = $this->arg('tagger');
71 $tag_arg = $this->arg('tag');
73 $tagger = common_canonical_nickname($tagger_arg);
74 $tag = common_canonical_tag($tag_arg);
76 $current = common_current_user();
78 // Permanent redirect on non-canonical tag
80 if ($tagger_arg != $tagger || $tag_arg != $tag) {
81 $args = array('tagger' => $tagger, 'tag' => $tag);
82 common_redirect(common_local_url('editpeopletag', $args), 301);
88 $this->peopletag = Profile_list::staticGet('id', $id);
89 if (!empty($this->peopletag)) {
90 $user = User::staticGet('id', $this->peopletag->tagger);
94 $this->clientError(_('No tagger or ID.'), 404);
98 $user = User::staticGet('nickname', $tagger);
99 $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
102 if (!$this->peopletag) {
103 $this->clientError(_('No such peopletag.'), 404);
108 // This should not be happening
109 $this->clientError(_('Not a local user.'), 404);
113 if ($current->id != $user->id) {
114 $this->clientError(_('You must be the creator of the tag to edit it.'), 404);
118 $this->tagger = $user->getProfile();
126 * On GET, show the form. On POST, try to save the group.
128 * @param array $args unused
133 function handle($args)
135 parent::handle($args);
136 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
143 function showConfirm($msg=null, $fwd=null)
145 $this->confirm = $msg;
146 $this->confirm_args = $fwd;
150 function showConfirmForm()
152 $this->elementStart('form', array('id' => 'form_peopletag_edit_confirm',
153 'class' => 'form_settings',
155 'action' => common_local_url('editpeopletag',
156 array('tagger' => $this->tagger->nickname,
157 'tag' => $this->peopletag->tag))));
158 $this->elementStart('fieldset');
159 $this->hidden('token', common_session_token());
160 $this->hidden('id', $this->arg('id'));
162 foreach ($this->confirm_args as $key => $val) {
163 $this->hidden($key, $val);
166 $this->submit('form_action-no',
168 'submit form_action-primary',
170 $this->submit('form_action-yes',
172 'submit form_action-secondary',
174 $this->elementEnd('fieldset');
175 $this->elementEnd('form');
178 function showForm($msg=null)
184 function showLocalNav()
186 $nav = new PeopletagGroupNav($this, $this->peopletag);
190 function showContent()
192 if ($this->confirm) {
193 $this->showConfirmForm();
197 $form = new PeopletagEditForm($this, $this->peopletag);
200 $form->showProfileList();
203 function showPageNotice()
206 $this->element('p', 'error', $this->msg);
207 } else if ($this->confirm) {
208 $this->element('p', 'instructions', $this->confirm);
210 $this->element('p', 'instructions',
211 _('Use this form to edit the people tag.'));
215 function showScripts()
217 parent::showScripts();
218 $this->autofocus('tag');
223 $tag = common_canonical_tag($this->trimmed('tag'));
224 $description = $this->trimmed('description');
225 $private = $this->boolean('private');
226 $delete = $this->arg('delete');
227 $confirm = $this->arg('confirm');
228 $cancel = $this->arg('cancel');
230 if ($delete && $cancel) {
231 $this->showForm(_('Delete aborted.'));
235 $set_private = $private && $this->peopletag->private != $private;
237 if ($delete && !$confirm) {
238 $this->showConfirm(_('Deleting this tag will permanantly remove ' .
239 'all its subscription and membership records. ' .
240 'Do you still want to continue?'), array('delete' => 1));
242 } else if (common_valid_tag($tag)) {
243 $this->showForm(_('Invalid tag.'));
245 } else if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
246 $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
248 } else if (Profile_list::descriptionTooLong($description)) {
249 $this->showForm(sprintf(_('description is too long (max %d chars).'), Profile_list::maxDescription()));
251 } else if ($set_private && !$confirm && !$cancel) {
252 $fwd = array('tag' => $tag,
253 'description' => $description,
254 'private' => (int) $private);
256 $this->showConfirm(_('Setting a public tag as private will ' .
257 'permanently remove all the existing ' .
258 'subscriptions to it. Do you still want to continue?'), $fwd);
262 $this->peopletag->query('BEGIN');
264 $orig = clone($this->peopletag);
266 $this->peopletag->tag = $tag;
267 $this->peopletag->description = $description;
268 if (!$set_private || $confirm) {
269 $this->peopletag->private = $private;
272 $result = $this->peopletag->update($orig);
275 common_log_db_error($this->group, 'UPDATE', __FILE__);
276 $this->serverError(_('Could not update peopletag.'));
279 $this->peopletag->query('COMMIT');
281 if ($set_private && $confirm) {
282 Profile_tag_subscription::cleanup($this->peopletag);
286 // This might take quite a bit of time.
287 $this->peopletag->delete();
289 common_redirect(common_local_url('all',
290 array('nickname' => $this->tagger->nickname)),
294 if ($tag != $orig->tag) {
295 common_redirect(common_local_url('editpeopletag',
296 array('tagger' => $this->tagger->nickname,
300 $this->showForm(_('Options saved.'));
304 function tagExists($tag)
306 $args = array('tagger' => $this->tagger->id, 'tag' => $tag);
307 $ptag = Profile_list::pkeyGet($args);
309 return !empty($ptag);