123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class DeletegroupAction extends RedirectingAction
- {
- var $group = null;
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
- if (!common_logged_in()) {
-
- $this->clientError(_('You must be logged in to delete a group.'));
- }
- $nickname_arg = $this->trimmed('nickname');
- $id = intval($this->arg('id'));
- if ($id) {
- $this->group = User_group::getKV('id', $id);
- } else if ($nickname_arg) {
- $nickname = common_canonical_nickname($nickname_arg);
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- common_redirect(common_local_url('leavegroup', $args), 301);
- }
- $local = Local_group::getKV('nickname', $nickname);
- if (!$local) {
-
- $this->clientError(_('No such group.'), 404);
- }
- $this->group = User_group::getKV('id', $local->group_id);
- } else {
-
- $this->clientError(_('No nickname or ID.'), 404);
- }
- if (!$this->group) {
-
- $this->clientError(_('No such group.'), 404);
- }
- $cur = common_current_user();
- if (!$cur->hasRight(Right::DELETEGROUP)) {
-
- $this->clientError(_('You are not allowed to delete this group.'), 403);
- }
- return true;
- }
-
- function handle()
- {
- parent::handle();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($this->arg('no')) {
- $this->returnToPrevious();
- return;
- } elseif ($this->arg('yes')) {
- $this->handlePost();
- return;
- }
- }
- $this->showPage();
- }
- function handlePost()
- {
- $cur = common_current_user();
- try {
- if (Event::handle('StartDeleteGroup', array($this->group))) {
- $this->group->delete();
- Event::handle('EndDeleteGroup', array($this->group));
- }
- } catch (Exception $e) {
-
-
- $this->serverError(sprintf(_('Could not delete group %s.'),
- $this->group->nickname));
- }
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
-
- $this->element('title', null, sprintf(_('Deleted group %s'),
- $this->group->nickname));
- $this->elementEnd('head');
- $this->elementStart('body');
-
- $this->elementEnd('body');
- $this->endHTML();
- } else {
-
-
- common_redirect(common_local_url('groups'), 303);
- }
- }
- function title() {
-
- return _('Delete group');
- }
- function showContent() {
- $this->areYouSureForm();
- $block = new GroupProfileBlock($this, $this->group);
- $block->show();
- }
-
- function areYouSureForm()
- {
- $id = $this->group->id;
- $this->elementStart('form', array('id' => 'deletegroup-' . $id,
- 'method' => 'post',
- 'class' => 'form_settings form_entity_block',
- 'action' => common_local_url('deletegroup', array('id' => $this->group->id))));
- $this->elementStart('fieldset');
- $this->hidden('token', common_session_token());
-
- $this->element('legend', _('Delete group'));
- if (Event::handle('StartDeleteGroupForm', array($this, $this->group))) {
- $this->element('p', null,
-
- _('Are you sure you want to delete this group? '.
- 'This will clear all data about the group from the '.
- 'database, without a backup. ' .
- 'Public posts to this group will still appear in ' .
- 'individual timelines.'));
- foreach ($this->args as $k => $v) {
- if (substr($k, 0, 9) == 'returnto-') {
- $this->hidden($k, $v);
- }
- }
- Event::handle('EndDeleteGroupForm', array($this, $this->group));
- }
- $this->submit('form_action-no',
-
- _m('BUTTON','No'),
- 'submit form_action-primary',
- 'no',
-
- _('Do not delete this group.'));
- $this->submit('form_action-yes',
-
- _m('BUTTON','Yes'),
- 'submit form_action-secondary',
- 'yes',
-
- _('Delete this group.'));
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
- }
|