code:
<?php
/**
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2010, StatusNet, Inc.
 *
 * Delete your own account
 *
 * PHP version 5
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Account
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET')) {
    // This check helps protect against security problems;
    // your code file can't be executed directly from the web.
    exit(1);
}

/**
 * Action to delete your own account
 *
 * Note that this is distinct from DeleteuserAction, which see. I thought
 * that making that action do both things (delete another user and delete the
 * current user) would open a lot of holes. I'm open to refactoring, however.
 *
 * @category  Account
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://status.net/
 */
class DeleteaccountAction extends Action
{
    private $_complete = false;
    private $_error    = null;

    /**
     * For initializing members of the class.
     *
     * @param array $argarray misc. arguments
     *
     * @return boolean true
     */
    function prepare($argarray)
    {
        parent::prepare($argarray);

        $cur = common_current_user();

        if (empty($cur)) {
            // TRANS: Client exception displayed trying to delete a user account while not logged in.
            throw new ClientException(_("Only logged-in users ".
                                        "can delete their account."), 403);
        }

        if (!$cur->hasRight(Right::DELETEACCOUNT)) {
            // TRANS: Client exception displayed trying to delete a user account without have the rights to do that.
            throw new ClientException(_("You cannot delete your account."), 403);
        }

        return true;
    }

    /**
     * Handler method
     *
     * @param array $argarray is ignored since it's now passed in in prepare()
     *
     * @return void
     */
    function handle($argarray=null)
    {
        parent::handle($argarray);

        if ($this->isPost()) {
            $this->deleteAccount();
        } else {
            $this->showPage();
        }
        return;
    }

    /**
     * Return true if read only.
     *
     * MAY override
     *
     * @param array $args other arguments
     *
     * @return boolean is read only action?
     */
    function isReadOnly($args)
    {
        return false;
    }

    /**
     * Return last modified, if applicable.
     *
     * MAY override
     *
     * @return string last modified http header
     */
    function lastModified()
    {
        // For comparison with If-Last-Modified
        // If not applicable, return null
        return null;
    }

    /**
     * Return etag, if applicable.
     *
     * MAY override
     *
     * @return string etag http header
     */
    function etag()
    {
        return null;
    }

    /**
     * Delete the current user's account
     *
     * Checks for the "I am sure." string to make sure the user really
     * wants to delete their account.
     *
     * Then, marks the account as deleted and begins the deletion process
     * (actually done by a back-end handler).
     *
     * If successful it logs the user out, and shows a brief completion message.
     *
     * @return void
     */
    function deleteAccount()
    {
        $this->checkSessionToken();
        // !!! If this string is changed, it also needs to be changed in DeleteAccountForm::formData()
        // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
        $iamsure = _('I am sure.');
        if ($this->trimmed('iamsure') != $iamsure ) {
            // TRANS: Notification for user about the text that must be input to be able to delete a user account.
            // TRANS: %s is the text that needs to be input.
            $this->_error = sprintf(_('You must write "%s" exactly in the box.'), $iamsure);
            $this->showPage();
            return;
        }

        $cur = common_current_user();

        // Mark the account as deleted and shove low-level deletion tasks
        // to background queues. Removing a lot of posts can take a while...

        if (!$cur->hasRole(Profile_role::DELETED)) {
            $cur->grantRole(Profile_role::DELETED);
        }

        $qm = QueueManager::get();
        $qm->enqueue($cur, 'deluser');

        // The user is really-truly logged out

        common_set_user(null);
        common_real_login(false); // not logged in
        common_forgetme(); // don't log back in!

        $this->_complete = true;
        $this->showPage();
    }

    /**
     * Shows the page content.
     *
     * If the deletion is complete, just shows a completion message.
     *
     * Otherwise, shows the deletion form.
     *
     * @return void
     *
     */
    function showContent()
    {
        if ($this->_complete) {
            $this->element('p', 'confirmation',
                           // TRANS: Confirmation that a user account has been deleted.
                           _('Account deleted.'));
            return;
        }

        if (!empty($this->_error)) {
            $this->element('p', 'error', $this->_error);
            $this->_error = null;
        }

        $form = new DeleteAccountForm($this);
        $form->show();
    }

    /**
     * Show the title of the page
     *
     * @return string title
     */

    function title()
    {
        // TRANS: Page title for page on which a user account can be deleted.
        return _('Delete account');
    }
}

/**
 * Form for deleting your account
 *
 * Note that this mostly is here to keep you from accidentally deleting your
 * account.
 *
 * @category  Account
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://status.net/
 */
class DeleteAccountForm extends Form
{
    /**
     * Class of the form.
     *
     * @return string the form's class
     */
    function formClass()
    {
        return 'form_profile_delete';
    }

    /**
     * URL the form posts to
     *
     * @return string the form's action URL
     */
    function action()
    {
        return common_local_url('deleteaccount');
    }

    /**
     * Output form data
     *
     * Instructions plus an 'i am sure' entry box.
     *
     * @return void
     */
    function formData()
    {
        $cur = common_current_user();

        // TRANS: Form text for user deletion form.
        $msg = '
' . _('This will permanently delete '.
                 'your account data from this server.') . '
';

        if ($cur->hasRight(Right::BACKUPACCOUNT)) {
            // TRANS: Additional form text for user deletion form shown if a user has account backup rights.
            // TRANS: %s is a URL to the backup page.
            $msg .= '
' . sprintf(_('You are strongly advised to '.
                              'back up your data'.
                              ' before deletion.'),
                           common_local_url('backupaccount')) . '
';
        }

        $this->out->elementStart('p');
        $this->out->raw($msg);
        $this->out->elementEnd('p');

        // !!! If this string is changed, it also needs to be changed in class DeleteaccountAction.
        // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
        $iamsure = _("I am sure.");
        $this->out->input('iamsure',
                          // TRANS: Field label for delete account confirmation entry.
                          _('Confirm'),
                          null,
                          // TRANS: Input title for the delete account field.
                          // TRANS: %s is the text that needs to be input.
                          sprintf(_('Enter "%s" to confirm that '.
                            'you want to delete your account.'),$iamsure ));
    }

    /**
     * Buttons for the form
     *
     * In this case, a single submit button
     *
     * @return void
     */
    function formActions()
    {
        $this->out->submit('submit',
                           // TRANS: Button text for user account deletion.
                           _m('BUTTON', 'Delete'),
                           'submit',
                           null,
                           // TRANS: Button title for user account deletion.
                           _('Permanently delete your account.'));
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Action class to delete an OAuth application
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Action
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Delete an OAuth appliction
 *
 * @category Action
 * @package  StatusNet
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 */
class DeleteapplicationAction extends Action
{
    var $app = null;

    /**
     * Take arguments for running
     *
     * @param array $args $_REQUEST args
     *
     * @return boolean success flag
     */
    function prepare($args)
    {
        if (!parent::prepare($args)) {
            return false;
        }

        if (!common_logged_in()) {
            // TRANS: Client error displayed trying to delete an application while not logged in.
            $this->clientError(_('You must be logged in to delete an application.'));
        }

        $id        = (int)$this->arg('id');
        $this->app = Oauth_application::getKV('id', $id);

        if (empty($this->app)) {
            // TRANS: Client error displayed trying to delete an application that does not exist.
            $this->clientError(_('Application not found.'));
        }

        $cur = common_current_user();

        if ($cur->id != $this->app->owner) {
            // TRANS: Client error displayed trying to delete an application the current user does not own.
            $this->clientError(_('You are not the owner of this application.'), 401);
        }

        return true;
    }

    /**
     * Handle request
     *
     * Shows a page with list of favorite notices
     *
     * @param array $args $_REQUEST args; handled in prepare()
     *
     * @return void
     */
    function handle($args)
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {

            // CSRF protection
            $token = $this->trimmed('token');
            if (!$token || $token != common_session_token()) {
                // TRANS: Client error displayed when the session token does not match or is not given.
                $this->clientError(_('There was a problem with your session token.'));
            }

            if ($this->arg('no')) {
                common_redirect(common_local_url('showapplication',
                                                 array('id' => $this->app->id)), 303);
            } elseif ($this->arg('yes')) {
                $this->handlePost();
                common_redirect(common_local_url('oauthappssettings'), 303);
            } else {
                $this->showPage();
            }
        }
    }

    function showContent() {
        $this->areYouSureForm();
    }

    function title() {
        // TRANS: Title for delete application page.
        return _('Delete application');
    }

    function showNoticeForm() {
        // nop
    }

    /**
     * Confirm with user.
     *
     * Shows a confirmation form.
     *
     * @return void
     */
    function areYouSureForm()
    {
        $id = $this->app->id;
        $this->elementStart('form', array('id' => 'deleteapplication-' . $id,
                                          'method' => 'post',
                                          'class' => 'form_settings form_entity_block',
                                          'action' => common_local_url('deleteapplication',
                                                                       array('id' => $this->app->id))));
        $this->elementStart('fieldset');
        $this->hidden('token', common_session_token());
        // TRANS: Fieldset legend on delete application page.
        $this->element('legend', _('Delete application'));
        $this->element('p', null,
                       // TRANS: Confirmation text on delete application page.
                       _('Are you sure you want to delete this application? '.
                         'This will clear all data about the application from the '.
                         'database, including all existing user connections.'));
        $this->submit('form_action-no',
                      // TRANS: Button label on the delete application form.
                      _m('BUTTON','No'),
                      'submit form_action-primary',
                      'no',
                      // TRANS: Submit button title for 'No' when deleting an application.
                      _('Do not delete this application.'));
        $this->submit('form_action-yes',
                      // TRANS: Button label on the delete application form.
                      _m('BUTTON','Yes'),
                      'submit form_action-secondary',
                      // TRANS: Submit button title for 'Yes' when deleting an application.
                      'yes', _('Delete this application.'));
        $this->elementEnd('fieldset');
        $this->elementEnd('form');
    }

    /**
     * Actually delete the app
     *
     * @return void
     */
    function handlePost()
    {
        $this->app->delete();
    }
}

repo_name: dansup/gnu

license: mit


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Delete a group
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Group
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @author    Brion Vibber <brion@status.net>
 * @copyright 2008-2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Delete a group
 *
 * This is the action for deleting a group.
 *
 * @category Group
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Brion Vibber <brion@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 * @fixme merge more of this code with related variants
 */
class DeletegroupAction extends RedirectingAction
{
    var $group = null;

    /**
     * Prepare to run
     *
     * @fixme merge common setup code with other group actions
     * @fixme allow group admins to delete their own groups
     */
    function prepare($args)
    {
        parent::prepare($args);

        if (!common_logged_in()) {
            // TRANS: Client error when trying to delete group while not 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);

            // Permanent redirect on non-canonical nickname

            if ($nickname_arg != $nickname) {
                $args = array('nickname' => $nickname);
                common_redirect(common_local_url('leavegroup', $args), 301);
            }

            $local = Local_group::getKV('nickname', $nickname);

            if (!$local) {
                // TRANS: Client error when trying to delete a non-local group.
                $this->clientError(_('No such group.'), 404);
            }

            $this->group = User_group::getKV('id', $local->group_id);
        } else {
            // TRANS: Client error when trying to delete a group without providing a nickname or ID for the group.
            $this->clientError(_('No nickname or ID.'), 404);
        }

        if (!$this->group) {
            // TRANS: Client error when trying to delete a non-existing group.
            $this->clientError(_('No such group.'), 404);
        }

        $cur = common_current_user();
        if (!$cur->hasRight(Right::DELETEGROUP)) {
            // TRANS: Client error when trying to delete a group without having the rights to delete it.
            $this->clientError(_('You are not allowed to delete this group.'), 403);
        }

        return true;
    }

    /**
     * Handle the request
     *
     * On POST, delete the group.
     *
     * @param array $args unused
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);
        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) {
            // TRANS: Server error displayed if a group could not be deleted.
            // TRANS: %s is the name of the group that could not be deleted.
            $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');
            // TRANS: Message given after deleting a group.
            // TRANS: %s is the deleted group's name.
            $this->element('title', null, sprintf(_('Deleted group %s'),
                                                  $this->group->nickname));
            $this->elementEnd('head');
            $this->elementStart('body');
            // @fixme add a sensible AJAX response form!
            $this->elementEnd('body');
            $this->endHTML();
        } else {
            // @fixme if we could direct to the page on which this group
            // would have shown... that would be awesome
            common_redirect(common_local_url('groups'), 303);
        }
    }

    function title() {
        // TRANS: Title of delete group page.
        return _('Delete group');
    }

    function showContent() {
        $this->areYouSureForm();
        $block = new GroupProfileBlock($this, $this->group);
        $block->show();
    }

    /**
     * Confirm with user.
     * Ripped from DeleteuserAction
     *
     * Shows a confirmation form.
     *
     * @fixme refactor common code for things like this
     * @return void
     */
    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());
        // TRANS: Form legend for deleting a group.
        $this->element('legend', _('Delete group'));
        if (Event::handle('StartDeleteGroupForm', array($this, $this->group))) {
            $this->element('p', null,
                           // TRANS: Warning in form for deleleting a group.
                           _('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',
                      // TRANS: Button label on the delete group form.
                      _m('BUTTON','No'),
                      'submit form_action-primary',
                      'no',
                      // TRANS: Submit button title for 'No' when deleting a group.
                      _('Do not delete this group.'));
        $this->submit('form_action-yes',
                      // TRANS: Button label on the delete group form.
                      _m('BUTTON','Yes'),
                      'submit form_action-secondary',
                      'yes',
                      // TRANS: Submit button title for 'Yes' when deleting a group.
                      _('Delete this group.'));
        $this->elementEnd('fieldset');
        $this->elementEnd('form');
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Class for deleting a notice
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Personal
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
 * @copyright 2008 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('GNUSOCIAL')) { exit(1); }

// @todo FIXME: documentation needed.
class DeletenoticeAction extends FormAction
{
    protected $notice = null;

    protected function doPreparation()
    {
        $this->notice = Notice::getByID($this->trimmed('notice'));

        if (!$this->scoped->sameAs($this->notice->getProfile()) &&
                   !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
            // TRANS: Error message displayed trying to delete a notice that was not made by the current user.
            $this->clientError(_('Cannot delete this notice.'));
        }

        $this->formOpts['notice'] = $this->notice;
    }

    function getInstructions()
    {
        // TRANS: Instructions for deleting a notice.
        return _('You are about to permanently delete a notice. ' .
                 'Once this is done, it cannot be undone.');
    }

    function title()
    {
        // TRANS: Page title when deleting a notice.
        return _('Delete notice');
    }

    protected function doPost()
    {
        if ($this->arg('yes')) {
            if (Event::handle('StartDeleteOwnNotice', array($this->scoped->getUser(), $this->notice))) {
                $this->notice->deleteAs($this->scoped);
                Event::handle('EndDeleteOwnNotice', array($this->scoped->getUser(), $this->notice));
            }
        }

        common_redirect(common_get_returnto(), 303);
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Action class to delete a user
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Action
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('GNUSOCIAL')) { exit(1); }

/**
 * Delete a user
 *
 * @category Action
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 */
class DeleteuserAction extends ProfileFormAction
{
    var $user = null;

    function prepare(array $args=array())
    {
        if (!parent::prepare($args)) {
            return false;
        }

        assert($this->scoped instanceof Profile);

        if (!$this->scoped->hasRight(Right::DELETEUSER)) {
            // TRANS: Client error displayed when trying to delete a user without having the right to delete users.
            throw new AuthorizationException(_('You cannot delete users.'));
        }

        try {
            $this->user = $this->profile->getUser();
        } catch (NoSuchUserException $e) {
            // TRANS: Client error displayed when trying to delete a non-local user.
            throw new ClientException(_('You can only delete local users.'));
        }

        // Only administrators can delete other privileged users (such as others who have the right to silence).
        if ($this->profile->isPrivileged() && !$this->scoped->hasRole(Profile_role::ADMINISTRATOR)) {
            // TRANS: Client error displayed when trying to delete a user that has been granted moderation privileges
            throw new AuthorizationException(_('You cannot delete other privileged users.'));
        }

        return true;
    }

    /**
     * Handle request
     *
     * Shows a page with list of favorite notices
     *
     * @param array $args $_REQUEST args; handled in prepare()
     *
     * @return void
     */
    function handle($args)
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if ($this->arg('no')) {
                $this->returnToPrevious();
            } elseif ($this->arg('yes')) {
                $this->handlePost();
                $this->returnToPrevious();
            } else {
                $this->showPage();
            }
        }
    }

    function showContent() {
        $this->areYouSureForm();
        $block = new AccountProfileBlock($this, $this->profile);
        $block->show();
    }

    function title() {
        // TRANS: Title of delete user page.
        return _m('TITLE','Delete user');
    }

    function showNoticeForm() {
        // nop
    }

    /**
     * Confirm with user.
     *
     * Shows a confirmation form.
     *
     * @return void
     */
    function areYouSureForm()
    {
        $id = $this->profile->id;
        $this->elementStart('form', array('id' => 'deleteuser-' . $id,
                                           'method' => 'post',
                                           'class' => 'form_settings form_entity_block',
                                           'action' => common_local_url('deleteuser')));
        $this->elementStart('fieldset');
        $this->hidden('token', common_session_token());
        // TRANS: Fieldset legend on delete user page.
        $this->element('legend', _('Delete user'));
        if (Event::handle('StartDeleteUserForm', array($this, $this->user))) {
            $this->element('p', null,
                           // TRANS: Information text to request if a user is certain that the described action has to be performed.
                           _('Are you sure you want to delete this user? '.
                             'This will clear all data about the user from the '.
                             'database, without a backup.'));
            $this->element('input', array('id' => 'deleteuserto-' . $id,
                                          'name' => 'profileid',
                                          'type' => 'hidden',
                                          'value' => $id));
            foreach ($this->args as $k => $v) {
                if (substr($k, 0, 9) == 'returnto-') {
                    $this->hidden($k, $v);
                }
            }
            Event::handle('EndDeleteUserForm', array($this, $this->user));
        }
        $this->submit('form_action-no',
                      // TRANS: Button label on the delete user form.
                      _m('BUTTON','No'),
                      'submit form_action-primary',
                      'no',
                      // TRANS: Submit button title for 'No' when deleting a user.
                      _('Do not delete this user.'));
        $this->submit('form_action-yes',
                      // TRANS: Button label on the delete user form.
                      _m('BUTTON','Yes'),
                      'submit form_action-secondary',
                      'yes',
                      // TRANS: Submit button title for 'Yes' when deleting a user.
                      _('Delete this user.'));
        $this->elementEnd('fieldset');
        $this->elementEnd('form');
    }

    /**
     * Actually delete a user.
     *
     * @return void
     */
    function handlePost()
    {
        if (Event::handle('StartDeleteUser', array($this, $this->user))) {
            // Mark the account as deleted and shove low-level deletion tasks
            // to background queues. Removing a lot of posts can take a while...
            if (!$this->user->hasRole(Profile_role::DELETED)) {
                $this->user->grantRole(Profile_role::DELETED);
            }

            $qm = QueueManager::get();
            $qm->enqueue($this->user, 'deluser');

            Event::handle('EndDeleteUser', array($this, $this->user));
        }
    }
}


code:
<?php
/**
 * Documentation action.
 *
 * PHP version 5
 *
 * @category Action
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 *
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2008-2010, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('GNUSOCIAL')) { exit(1); }

/**
 * Documentation class.
 *
 * @category Action
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 */
class DocAction extends ManagedAction
{
    var $output   = null;
    var $filename = null;
    var $title    = null;

    protected function doPreparation()
    {
        $this->title  = $this->trimmed('title');
        if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
            $this->title = 'help';
        }
        $this->output = null;

        $this->loadDoc();
    }

    public function title()
    {
        return ucfirst($this->title);
    }

    /**
     * Display content.
     *
     * Shows the content of the document.
     *
     * @return void
     */
    function showContent()
    {
        $this->raw($this->output);
    }

    function showNoticeForm()
    {
        // no notice form
    }

    /**
     * These pages are read-only.
     *
     * @param array $args unused.
     *
     * @return boolean read-only flag (false)
     */
    function isReadOnly($args)
    {
        return true;
    }

    function loadDoc()
    {
        if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {

            $paths = DocFile::defaultPaths();

            $docfile = DocFile::forTitle($this->title, $paths);

            if (empty($docfile)) {
                // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
                // TRANS: %s is the non-existing document.
                throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
            }

            $this->output = $docfile->toHTML();

            Event::handle('EndLoadDoc', array($this->title, &$this->output));
        }
    }

    function showLocalNav()
    {
        $menu = new DocNav($this);
        $menu->show();
    }
}

class DocNav extends Menu
{
    function show()
    {
        if (Event::handle('StartDocNav', array($this))) {
            $stub = new HomeStubNav($this->action);
            $this->submenu(_m('MENU','Home'), $stub);

            $docs = new DocListNav($this->action);
            $this->submenu(_m('MENU','Docs'), $docs);

            Event::handle('EndDocNav', array($this));
        }
    }
}

class DocListNav extends Menu
{
    function getItems()
    {
        $items = array();

        if (Event::handle('StartDocsMenu', array(&$items))) {

            $items = array(array('doc',
                                 array('title' => 'help'),
                                 _m('MENU', 'Help'),
                                 _('Getting started'),
                                 'nav_doc_help'),
                           array('doc',
                                 array('title' => 'about'),
                                 _m('MENU', 'About'),
                                 _('About this site'),
                                 'nav_doc_about'),
                           array('doc',
                                 array('title' => 'faq'),
                                 _m('MENU', 'FAQ'),
                                 _('Frequently asked questions'),
                                 'nav_doc_faq'),
                           array('doc',
                                 array('title' => 'contact'),
                                 _m('MENU', 'Contact'),
                                 _('Contact info'),
                                 'nav_doc_contact'),
                           array('doc',
                                 array('title' => 'tags'),
                                 _m('MENU', 'Tags'),
                                 _('Using tags'),
                                 'nav_doc_tags'),
                           array('doc',
                                 array('title' => 'groups'),
                                 _m('MENU', 'Groups'),
                                 _('Using groups'),
                                 'nav_doc_groups'),
                           array('doc',
                                 array('title' => 'api'),
                                 _m('MENU', 'API'),
                                 _('RESTful API'),
                                 'nav_doc_api'));

            Event::handle('EndDocsMenu', array(&$items));
        }
        return $items;
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Edit an OAuth Application
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Applications
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @copyright 2008-2011 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Edit the details of an OAuth application
 *
 * This is the form for editing an application
 *
 * @category Application
 * @package  StatusNet
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class EditApplicationAction extends Action
{
    var $msg   = null;
    var $owner = null;
    var $app   = null;

    function title()
    {
        // TRANS: Title for "Edit application" form.
        return _('Edit application');
    }

    /**
     * Prepare to run
     */
    function prepare($args)
    {
        parent::prepare($args);

        if (!common_logged_in()) {
            // TRANS: Client error displayed trying to edit an application while not logged in.
            $this->clientError(_('You must be logged in to edit an application.'));
        }

        $id = (int)$this->arg('id');

        $this->app   = Oauth_application::getKV($id);
        $this->owner = User::getKV($this->app->owner);
        $cur         = common_current_user();

        if ($cur->id != $this->owner->id) {
            // TRANS: Client error displayed trying to edit an application while not being its owner.
            $this->clientError(_('You are not the owner of this application.'), 401);
        }

        if (!$this->app) {
            // TRANS: Client error displayed trying to edit an application that does not exist.
            $this->clientError(_('No such application.'));
        }

        return true;
    }

    /**
     * Handle the request
     *
     * On GET, show the form. On POST, try to save the app.
     *
     * @param array $args unused
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->handlePost($args);
        } else {
            $this->showForm();
        }
    }

    function handlePost($args)
    {
        // Workaround for PHP returning empty $_POST and $_FILES when POST
        // length > post_max_size in php.ini

        if (empty($_FILES)
            && empty($_POST)
            && ($_SERVER['CONTENT_LENGTH'] > 0)
            ) {
            // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
            // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
            $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
                      'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
                      intval($_SERVER['CONTENT_LENGTH']));
            $this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
            return;
        }

        // CSRF protection
        $token = $this->trimmed('token');
        if (!$token || $token != common_session_token()) {
            // TRANS: Client error displayed when the session token does not match or is not given.
            $this->clientError(_('There was a problem with your session token.'));
        }

        $cur = common_current_user();

        if ($this->arg('cancel')) {
            common_redirect(common_local_url('showapplication',
                                             array('id' => $this->app->id)), 303);
        } elseif ($this->arg('save')) {
            $this->trySave();
        } else {
            // TRANS: Client error displayed submitting invalid form data for edit application.
            $this->clientError(_('Unexpected form submission.'));
        }
    }

    function showForm($msg=null)
    {
        $this->msg = $msg;
        $this->showPage();
    }

    function showContent()
    {
        $form = new ApplicationEditForm($this, $this->app);
        $form->show();
    }

    function showPageNotice()
    {
        if (!empty($this->msg)) {
            $this->element('p', 'error', $this->msg);
        } else {
            $this->element('p', 'instructions',
                           // TRANS: Instructions for "Edit application" form.
                           _('Use this form to edit your application.'));
        }
    }

    function trySave()
    {
        $name         = $this->trimmed('name');
        $description  = $this->trimmed('description');
        $source_url   = $this->trimmed('source_url');
        $organization = $this->trimmed('organization');
        $homepage     = $this->trimmed('homepage');
        $callback_url = $this->trimmed('callback_url');
        $type         = $this->arg('app_type');
        $access_type  = $this->arg('default_access_type');

        if (empty($name)) {
            // TRANS: Validation error shown when not providing a name in the "Edit application" form.
            $this->showForm(_('Name is required.'));
            return;
        } elseif (mb_strlen($name) > 255) {
            // TRANS: Validation error shown when providing too long a name in the "Edit application" form.
            $this->showForm(_('Name is too long (maximum 255 characters).'));
            return;
        } else if ($this->nameExists($name)) {
            // TRANS: Validation error shown when providing a name for an application that already exists in the "Edit application" form.
            $this->showForm(_('Name already in use. Try another one.'));
            return;
        } elseif (empty($description)) {
            // TRANS: Validation error shown when not providing a description in the "Edit application" form.
            $this->showForm(_('Description is required.'));
            return;
        } elseif (Oauth_application::descriptionTooLong($description)) {
            $this->showForm(sprintf(
                // TRANS: Validation error shown when providing too long a description in the "Edit application" form.
                // TRANS: %d is the maximum number of allowed characters.
                _m('Description is too long (maximum %d character).',
                  'Description is too long (maximum %d characters).',
                  Oauth_application::maxDesc()),
                                    Oauth_application::maxDesc()));
            return;
        } elseif (mb_strlen($source_url) > 255) {
            // TRANS: Validation error shown when providing too long a source URL in the "Edit application" form.
            $this->showForm(_('Source URL is too long.'));
            return;
        } elseif ((mb_strlen($source_url) > 0)
                  && !common_valid_http_url($source_url)) {
            // TRANS: Validation error shown when providing an invalid source URL in the "Edit application" form.
            $this->showForm(_('Source URL is not valid.'));
            return;
        } elseif (empty($organization)) {
            // TRANS: Validation error shown when not providing an organisation in the "Edit application" form.
            $this->showForm(_('Organization is required.'));
            return;
        } elseif (mb_strlen($organization) > 255) {
            // TRANS: Validation error shown when providing too long an arganisation name in the "Edit application" form.
            $this->showForm(_('Organization is too long (maximum 255 characters).'));
            return;
        } elseif (empty($homepage)) {
            // TRANS: Form validation error show when an organisation name has not been provided in the edit application form.
            $this->showForm(_('Organization homepage is required.'));
            return;
        } elseif ((mb_strlen($homepage) > 0)
                && !common_valid_http_url($homepage)) {
            // TRANS: Validation error shown when providing an invalid homepage URL in the "Edit application" form.
            $this->showForm(_('Homepage is not a valid URL.'));
            return;
        } elseif (mb_strlen($callback_url) > 255) {
            // TRANS: Validation error shown when providing too long a callback URL in the "Edit application" form.
            $this->showForm(_('Callback is too long.'));
            return;
        } elseif (mb_strlen($callback_url) > 0
                && !common_valid_http_url($callback_url)) {
            // TRANS: Validation error shown when providing an invalid callback URL in the "Edit application" form.
            $this->showForm(_('Callback URL is not valid.'));
            return;
        }

        $cur = common_current_user();

        // Checked in prepare() above

        assert(!is_null($cur));
        assert(!is_null($this->app));

        $orig = clone($this->app);

        $this->app->name         = $name;
        $this->app->description  = $description;
        $this->app->source_url   = $source_url;
        $this->app->organization = $organization;
        $this->app->homepage     = $homepage;
        $this->app->callback_url = $callback_url;
        $this->app->type         = $type;

        common_debug("access_type = $access_type");

        if ($access_type == 'r') {
            $this->app->access_type = 1;
        } else {
            $this->app->access_type = 3;
        }

        $result = $this->app->update($orig);

        // Note: 0 means no rows changed, which can happen if the only
        // thing we changed was the icon, since it's not altered until
        // the next step.
        if ($result === false) {
            common_log_db_error($this->app, 'UPDATE', __FILE__);
            // TRANS: Server error occuring when an application could not be updated from the "Edit application" form.
            $this->serverError(_('Could not update application.'));
        }

        $this->app->uploadLogo();

        common_redirect(common_local_url('oauthappssettings'), 303);
    }

    /**
     * Does the app name already exist?
     *
     * Checks the DB to see someone has already registered an app
     * with the same name.
     *
     * @param string $name app name to check
     *
     * @return boolean true if the name already exists
     */
    function nameExists($name)
    {
        $newapp = Oauth_application::getKV('name', $name);
        if (empty($newapp)) {
            return false;
        } else {
            return $newapp->id != $this->app->id;
        }
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Edit an existing group
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Group
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
 * @author    Zach Copley <zach@status.net>
 * @copyright 2008-2011 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Add a new group
 *
 * This is the form for adding a new group
 *
 * @category Group
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class EditgroupAction extends GroupAction
{
    var $msg;

    function title()
    {
        // TRANS: Title for form to edit a group. %s is a group nickname.
        return sprintf(_('Edit %s group'), $this->group->nickname);
    }

    /**
     * Prepare to run
     */

    protected function prepare(array $args=array())
    {
        parent::prepare($args);

        if (!common_logged_in()) {
            // TRANS: Client error displayed trying to edit a group while not logged in.
            $this->clientError(_('You must be logged in to create a group.'));
        }

        $nickname_arg = $this->trimmed('nickname');
        $nickname = common_canonical_nickname($nickname_arg);

        // Permanent redirect on non-canonical nickname

        if ($nickname_arg != $nickname) {
            $args = array('nickname' => $nickname);
            common_redirect(common_local_url('editgroup', $args), 301);
        }

        if (!$nickname) {
            // TRANS: Client error displayed trying to edit a group while not proving a nickname for the group to edit.
            $this->clientError(_('No nickname.'), 404);
        }

        $groupid = $this->trimmed('groupid');

        if ($groupid) {
            $this->group = User_group::getKV('id', $groupid);
        } else {
            $local = Local_group::getKV('nickname', $nickname);
            if ($local) {
                $this->group = User_group::getKV('id', $local->group_id);
            }
        }

        if (!$this->group) {
            // TRANS: Client error displayed trying to edit a non-existing group.
            $this->clientError(_('No such group.'), 404);
        }

        $cur = common_current_user();

        if (!$cur->isAdmin($this->group)) {
            // TRANS: Client error displayed trying to edit a group while not being a group admin.
            $this->clientError(_('You must be an admin to edit the group.'), 403);
        }

        return true;
    }

    /**
     * Handle the request
     *
     * On GET, show the form. On POST, try to save the group.
     *
     * @return void
     */
    protected function handle()
    {
        parent::handle();
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->trySave();
        } else {
            $this->showForm();
        }
    }

    function showForm($msg=null)
    {
        $this->msg = $msg;
        $this->showPage();
    }

    function showContent()
    {
        $form = new GroupEditForm($this, $this->group);
        $form->show();
    }

    function showPageNotice()
    {
        if ($this->msg) {
            $this->element('p', 'error', $this->msg);
        } else {
            $this->element('p', 'instructions',
                           // TRANS: Form instructions for group edit form.
                           _('Use this form to edit the group.'));
        }
    }

    function showScripts()
    {
        parent::showScripts();
        $this->autofocus('fullname');
    }

    function trySave()
    {
        $cur = common_current_user();
        if (!$cur->isAdmin($this->group)) {
            // TRANS: Client error displayed trying to edit a group while not being a group admin.
            $this->clientError(_('You must be an admin to edit the group.'), 403);
        }

        if (Event::handle('StartGroupSaveForm', array($this))) {

            // $nickname will only be set if this changenick value is true.
            if (common_config('profile', 'changenick') == true) {
                try {
                    $nickname = Nickname::normalize($this->trimmed('newnickname'), true);
                } catch (NicknameTakenException $e) {
                    // Abort only if the nickname is occupied by _another_ group
                    if ($e->profile->id != $this->group->profile_id) {
                        $this->showForm($e->getMessage());
                        return;
                    }
                    $nickname = Nickname::normalize($this->trimmed('newnickname')); // without in-use check this time
                } catch (NicknameException $e) {
                    $this->showForm($e->getMessage());
                    return;
                }
            }

            $fullname    = $this->trimmed('fullname');
            $homepage    = $this->trimmed('homepage');
            $description = $this->trimmed('description');
            $location    = $this->trimmed('location');
            $aliasstring = $this->trimmed('aliases');
            $private     = $this->boolean('private');

            if ($private) {
                $force_scope = 1;
                $join_policy = User_group::JOIN_POLICY_MODERATE;
            } else {
                $force_scope = 0;
                $join_policy = User_group::JOIN_POLICY_OPEN;
            }

            if (!is_null($homepage) && (strlen($homepage) > 0) &&
                       !common_valid_http_url($homepage)) {
                // TRANS: Group edit form validation error.
                $this->showForm(_('Homepage is not a valid URL.'));
                return;
            } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                // TRANS: Group edit form validation error.
                $this->showForm(_('Full name is too long (maximum 255 characters).'));
                return;
            } else if (User_group::descriptionTooLong($description)) {
                $this->showForm(sprintf(
                                    // TRANS: Group edit form validation error.
                                    _m('Description is too long (maximum %d character).',
                                       'Description is too long (maximum %d characters).',
                                       User_group::maxDescription()),
                                    User_group::maxDescription()));
                return;
            } else if (!is_null($location) && mb_strlen($location) > 255) {
                // TRANS: Group edit form validation error.
                $this->showForm(_('Location is too long (maximum 255 characters).'));
                return;
            }

            if (!empty($aliasstring)) {
                $aliases = array_map(array('Nickname', 'normalize'),
                                     array_unique(preg_split('/[\s,]+/', $aliasstring)));
            } else {
                $aliases = array();
            }

            if (count($aliases) > common_config('group', 'maxaliases')) {
                // TRANS: Group edit form validation error.
                // TRANS: %d is the maximum number of allowed aliases.
                $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.',
                                           'Too many aliases! Maximum %d allowed.',
                                           common_config('group', 'maxaliases')),
                                        common_config('group', 'maxaliases')));
                return;
            }

            $this->group->query('BEGIN');

            $orig = clone($this->group);

            if (common_config('profile', 'changenick') == true && $this->group->nickname !== $nickname) {
                assert(Nickname::normalize($nickname)===$nickname);
                common_debug("Changing group nickname from '{$profile->nickname}' to '{$nickname}'.");
                $this->group->nickname = $nickname;
                $this->group->mainpage = common_local_url('showgroup', array('nickname' => $this->group->nickname));
            }
            $this->group->fullname    = $fullname;
            $this->group->homepage    = $homepage;
            $this->group->description = $description;
            $this->group->location    = $location;
            $this->group->join_policy = $join_policy;
            $this->group->force_scope = $force_scope;

            $result = $this->group->update($orig);

            if ($result === false) {
                common_log_db_error($this->group, 'UPDATE', __FILE__);
                // TRANS: Server error displayed when editing a group fails.
                $this->serverError(_('Could not update group.'));
            }

            $result = $this->group->setAliases($aliases);

            if (!$result) {
                // TRANS: Server error displayed when group aliases could not be added.
                $this->serverError(_('Could not create aliases.'));
            }

            $this->group->query('COMMIT');

            Event::handle('EndGroupSaveForm', array($this));
        }

        if ($this->group->nickname != $orig->nickname) {
            common_redirect(common_local_url('editgroup', array('nickname' => $this->group->nickname)), 303);
        } else {
            // TRANS: Group edit form success message.
            $this->showForm(_('Options saved.'));
        }
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Edit an existing group
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Group
 * @package   StatusNet
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Add a new group
 *
 * This is the form for adding a new group
 *
 * @category Group
 * @package  StatusNet
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */

class EditpeopletagAction extends Action
{
    var $msg, $confirm, $confirm_args=array();

    function title()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && $this->boolean('delete')) {
            // TRANS: Title for edit list page after deleting a tag.
            // TRANS: %s is a list.
            return sprintf(_('Delete %s list'), $this->peopletag->tag);
        }
        // TRANS: Title for edit list page.
        // TRANS: %s is a list.
        return sprintf(_('Edit list %s'), $this->peopletag->tag);
    }

    /**
     * Prepare to run
     */

    function prepare($args)
    {
        parent::prepare($args);

        if (!common_logged_in()) {
            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
            $this->clientError(_('Not logged in.'));
        }

        $id = $this->arg('id');
        if (common_config('singleuser', 'enabled')) {
            $tagger_arg = User::singleUserNickname();
        } else {
            $tagger_arg = $this->arg('tagger');
        }
        $tag_arg = $this->arg('tag');

        $tagger = common_canonical_nickname($tagger_arg);
        $tag = common_canonical_tag($tag_arg);

        $current = common_current_user();

        // Permanent redirect on non-canonical tag

        if ($tagger_arg != $tagger || $tag_arg != $tag) {
            $args = array('tagger' => $tagger, 'tag' => $tag);
            common_redirect(common_local_url('editpeopletag', $args), 301);
        }

        $user = null;
        if ($id) {
            $this->peopletag = Profile_list::getKV('id', $id);
            if (!empty($this->peopletag)) {
                $user = User::getKV('id', $this->peopletag->tagger);
            }
        } else {
            if (!$tagger) {
                // TRANS: Error message displayed when trying to perform an action that requires a tagging user or ID.
                $this->clientError(_('No tagger or ID.'), 404);
            }

            $user = User::getKV('nickname', $tagger);
            $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
        }

        if (!$this->peopletag) {
            // TRANS: Client error displayed when referring to a non-existing list.
            $this->clientError(_('No such list.'), 404);
        }

        if (!$user) {
            // This should not be happening
            // TRANS: Client error displayed when referring to non-local user.
            $this->clientError(_('Not a local user.'), 404);
        }

        if ($current->id != $user->id) {
            // TRANS: Client error displayed when reting to edit a tag that was not self-created.
            $this->clientError(_('You must be the creator of the tag to edit it.'), 404);
        }

        $this->tagger = $user->getProfile();

        return true;
    }

    /**
     * Handle the request
     *
     * On GET, show the form. On POST, try to save the group.
     *
     * @param array $args unused
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->trySave();
        } else {
            $this->showForm();
        }
    }

    function showConfirm($msg=null, $fwd=null)
    {
        $this->confirm = $msg;
        $this->confirm_args = $fwd;
        $this->showPage();
    }

    function showConfirmForm()
    {
        $this->elementStart('form', array('id' => 'form_peopletag_edit_confirm',
                                          'class' => 'form_settings',
                                          'method' => 'post',
                                          'action' => common_local_url('editpeopletag',
                                              array('tagger' => $this->tagger->nickname,
                                                    'tag' => $this->peopletag->tag))));
        $this->elementStart('fieldset');
        $this->hidden('token', common_session_token());
        $this->hidden('id', $this->arg('id'));

        foreach ($this->confirm_args as $key => $val) {
            $this->hidden($key, $val);
        }

        $this->submit('form_action-no',
                      _m('BUTTON','No'),
                      'submit form_action-primary',
                      'cancel');
        $this->submit('form_action-yes',
                      _m('BUTTON','Yes'),
                      'submit form_action-secondary',
                      'confirm');
        $this->elementEnd('fieldset');
        $this->elementEnd('form');
    }

    function showForm($msg=null)
    {
        $this->msg = $msg;
        $this->showPage();
    }

    function showObjectNav()
    {
        $nav = new PeopletagGroupNav($this, $this->peopletag);
        $nav->show();
    }

    function showContent()
    {
        if ($this->confirm) {
            $this->showConfirmForm();
            return;
        }

        $form = new PeopletagEditForm($this, $this->peopletag);
        $form->show();

        $form->showProfileList();
    }

    function showPageNotice()
    {
        if ($this->msg) {
            $this->element('p', 'error', $this->msg);
        } else if ($this->confirm) {
            $this->element('p', 'instructions', $this->confirm);
        } else {
            $this->element('p', 'instructions',
                           // TRANS: Form instruction for edit list form.
                           _('Use this form to edit the list.'));
        }
    }

    function showScripts()
    {
        parent::showScripts();
        $this->autofocus('tag');
    }

    function trySave()
    {
        $tag         = common_canonical_tag($this->trimmed('tag'));
        $description = $this->trimmed('description');
        $private     = $this->boolean('private');
        $delete      = $this->arg('delete');
        $confirm     = $this->arg('confirm');
        $cancel      = $this->arg('cancel');

        if ($delete && $cancel) {
            // TRANS: Form validation error displayed if the form data for deleting a tag was incorrect.
            $this->showForm(_('Delete aborted.'));
            return;
        }

        $set_private = $private && $this->peopletag->private != $private;

        if ($delete && !$confirm) {
            // TRANS: Text in confirmation dialog for deleting a tag.
            $this->showConfirm(_('Deleting this tag will permanantly remove ' .
                                 'all its subscription and membership records. ' .
                                 'Do you still want to continue?'), array('delete' => 1));
            return;
        } else if (common_valid_tag($tag)) {
            // TRANS: Form validation error displayed if a given tag is invalid.
            $this->showForm(_('Invalid tag.'));
            return;
        } else if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
            // TRANS: Form validation error displayed if a given tag is already present.
            // TRANS: %s is the already present tag.
            $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
            return;
        } else if (Profile_list::descriptionTooLong($description)) {
            $this->showForm(sprintf(
                    // TRANS: Client error shown when providing too long a description when editing a list.
                    // TRANS: %d is the maximum number of allowed characters.
                    _m('Description is too long (maximum %d character).',
                      'Description is too long (maximum %d characters).',
                      Profile_list::maxDescription()),
                    Profile_list::maxDescription()));
            return;
        } else if ($set_private && !$confirm && !$cancel) {
            $fwd = array('tag' => $tag,
                         'description' => $description,
                         'private' => (int) $private);

            // TRANS: Text in confirmation dialog for setting a tag from public to private.
            $this->showConfirm(_('Setting a public tag as private will ' .
                                 'permanently remove all the existing ' .
                                 'subscriptions to it. Do you still want to continue?'), $fwd);
            return;
        }

        // We tested $delete && !$confirm earlier so confirmation is required before getting here
        if ($delete) {
            // This might take quite a bit of time.
            $this->peopletag->delete();
            // send home.
            common_redirect(common_local_url('all', array('nickname' => $this->tagger->getNickname())), 303);
        }

        $this->peopletag->query('BEGIN');

        $orig = clone($this->peopletag);

        $this->peopletag->tag         = $tag;
        $this->peopletag->description = $description;
        if (!$set_private || $confirm) {
            $this->peopletag->private     = $private;
        }

        $result = $this->peopletag->update($orig);

        if (!$result) {
            common_log_db_error($this->group, 'UPDATE', __FILE__);
            // TRANS: Server error displayed when updating a list fails.
            $this->serverError(_('Could not update list.'));
        }

        $this->peopletag->query('COMMIT');

        if ($set_private && $confirm) {
            Profile_tag_subscription::cleanup($this->peopletag);
        }

        if ($tag != $orig->tag) {
            common_redirect(common_local_url('editpeopletag',
                                             array('tagger' => $this->tagger->nickname,
                                                   'tag'    => $tag)),
                            303);
        } else {
            // TRANS: Edit list form success message.
            $this->showForm(_('Options saved.'));
        }
    }

    function tagExists($tag)
    {
        $args = array('tagger' => $this->tagger->id, 'tag' => $tag);
        $ptag = Profile_list::pkeyGet($args);

        return !empty($ptag);
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Settings for email
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Settings
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @author    Zach Copley <zach@status.net>
 * @copyright 2008-2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('GNUSOCIAL')) { exit(1); }

/**
 * Settings for email
 *
 * @category Settings
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 *
 * @see      Widget
 */

class EmailsettingsAction extends SettingsAction
{
    /**
     * Title of the page
     *
     * @return string Title of the page
     */
    function title()
    {
        // TRANS: Title for e-mail settings.
        return _('Email settings');
    }

    /**
     * Instructions for use
     *
     * @return instructions for use
     */
    function getInstructions()
    {
        // XXX: For consistency of parameters in messages, this should be a
        //      regular parameters, replaced with sprintf().
        // TRANS: E-mail settings page instructions.
        // TRANS: %%site.name%% is the name of the site.
        return _('Manage how you get email from %%site.name%%.');
    }

    function showScripts()
    {
        parent::showScripts();
        $this->script('emailsettings.js');
        $this->autofocus('email');
    }

    /**
     * Content area of the page
     *
     * Shows a form for adding and removing email addresses and setting
     * email preferences.
     *
     * @return void
     */
    function showContent()
    {
        $user = $this->scoped->getUser();

        $this->elementStart('form', array('method' => 'post',
                                          'id' => 'form_settings_email',
                                          'class' => 'form_settings',
                                          'action' =>
                                          common_local_url('emailsettings')));
        $this->elementStart('fieldset');
        $this->elementStart('fieldset', array('id' => 'settings_email_address'));
        // TRANS: Form legend for e-mail settings form.
        $this->element('legend', null, _('Email address'));
        $this->hidden('token', common_session_token());

        if ($user->email) {
            $this->element('p', array('id' => 'form_confirmed'), $user->email);
            // TRANS: Form note in e-mail settings form.
            $this->element('p', array('class' => 'form_note'), _('Current confirmed email address.'));
            $this->hidden('email', $user->email);
            // TRANS: Button label to remove a confirmed e-mail address.
            $this->submit('remove', _m('BUTTON','Remove'));
        } else {
            try {
                $confirm = $this->getConfirmation();
                $this->element('p', array('id' => 'form_unconfirmed'), $confirm->address);
                $this->element('p', array('class' => 'form_note'),
                                        // TRANS: Form note in e-mail settings form.
                                        _('Awaiting confirmation on this address. '.
                                        'Check your inbox (and spam box!) for a message '.
                                        'with further instructions.'));
                $this->hidden('email', $confirm->address);
                // TRANS: Button label to cancel an e-mail address confirmation procedure.
                $this->submit('cancel', _m('BUTTON','Cancel'));
            } catch (NoResultException $e) {
                $this->elementStart('ul', 'form_data');
                $this->elementStart('li');
                // TRANS: Field label for e-mail address input in e-mail settings form.
                $this->input('email', _('Email address'),
                             $this->trimmed('email') ?: null,
                             // TRANS: Instructions for e-mail address input form. Do not translate
                             // TRANS: "example.org". It is one of the domain names reserved for
                             // TRANS: use in examples by http://www.rfc-editor.org/rfc/rfc2606.txt.
                             // TRANS: Any other domain may be owned by a legitimate person or
                             // TRANS: organization.
                             _('Email address, like "UserName@example.org"'));
                $this->elementEnd('li');
                $this->elementEnd('ul');
                // TRANS: Button label for adding an e-mail address in e-mail settings form.
                $this->submit('add', _m('BUTTON','Add'));
            }
        }
        $this->elementEnd('fieldset');

       if (common_config('emailpost', 'enabled') && $user->email) {
            $this->elementStart('fieldset', array('id' => 'settings_email_incoming'));
            // TRANS: Form legend for incoming e-mail settings form.
            $this->element('legend', null, _('Incoming email'));

            $this->elementStart('ul', 'form_data');
            $this->elementStart('li');
            $this->checkbox('emailpost',
                    // TRANS: Checkbox label in e-mail preferences form.
                    _('I want to post notices by email.'),
                    $user->emailpost);
            $this->elementEnd('li');
            $this->elementEnd('ul');

            // Our stylesheets make the form_data list items all floats, which
            // creates lots of problems with trying to wrap divs around things.
            // This should force a break before the next section, which needs
            // to be separate so we can disable the things in it when the
            // checkbox is off.
            $this->elementStart('div', array('style' => 'clear: both'));
            $this->elementEnd('div');

            $this->elementStart('div', array('id' => 'emailincoming'));

            if ($user->incomingemail) {
                $this->elementStart('p');
                $this->element('span', 'address', $user->incomingemail);
                // @todo XXX: Looks a little awkward in the UI.
                //      Something like "xxxx@identi.ca  Send email ..". Needs improvement.
                $this->element('span', 'input_instructions',
                               // TRANS: Form instructions for incoming e-mail form in e-mail settings.
                               _('Send email to this address to post new notices.'));
                $this->elementEnd('p');
                // TRANS: Button label for removing a set sender e-mail address to post notices from.
                $this->submit('removeincoming', _m('BUTTON','Remove'));
            }

            $this->elementStart('p');
            if ($user->incomingemail) {
                // TRANS: Instructions for incoming e-mail address input form, when an address has already been assigned.
                $msg = _('Make a new email address for posting to; '.
                         'cancels the old one.');
            } else {
                // TRANS: Instructions for incoming e-mail address input form.
                $msg = _('To send notices via email, we need to create a unique email address for you on this server:');
            }
            $this->element('span', 'input_instructions', $msg);
            $this->elementEnd('p');

            // TRANS: Button label for adding an e-mail address to send notices from.
            $this->submit('newincoming', _m('BUTTON','New'));

            $this->elementEnd('div'); // div#emailincoming

            $this->elementEnd('fieldset');
        }

        $this->elementStart('fieldset', array('id' => 'settings_email_preferences'));
        // TRANS: Form legend for e-mail preferences form.
        $this->element('legend', null, _('Email preferences'));

        $this->elementStart('ul', 'form_data');

        if (Event::handle('StartEmailFormData', array($this, $this->scoped))) {
            $this->elementStart('li');
            $this->checkbox('emailnotifysub',
                            // TRANS: Checkbox label in e-mail preferences form.
                            _('Send me notices of new subscriptions through email.'),
                            $user->emailnotifysub);
            $this->elementEnd('li');
            $this->elementStart('li');
            $this->checkbox('emailnotifymsg',
                            // TRANS: Checkbox label in e-mail preferences form.
                            _('Send me email when someone sends me a private message.'),
                            $user->emailnotifymsg);
            $this->elementEnd('li');
            $this->elementStart('li');
            $this->checkbox('emailnotifyattn',
                            // TRANS: Checkbox label in e-mail preferences form.
                            _('Send me email when someone sends me an "@-reply".'),
                            $user->emailnotifyattn);
            $this->elementEnd('li');
            $this->elementStart('li');
            $this->checkbox('emailnotifynudge',
                            // TRANS: Checkbox label in e-mail preferences form.
                            _('Allow friends to nudge me and send me an email.'),
                            $user->emailnotifynudge);
            $this->elementEnd('li');
            Event::handle('EndEmailFormData', array($this, $this->scoped));
        }
        $this->elementEnd('ul');
        // TRANS: Button label to save e-mail preferences.
        $this->submit('save', _m('BUTTON','Save'));
        $this->elementEnd('fieldset');
        $this->elementEnd('fieldset');
        $this->elementEnd('form');
    }

    /**
     * Gets any existing email address confirmations we're waiting for
     *
     * @return Confirm_address Email address confirmation for user, or null
     */
    function getConfirmation()
    {
        $confirm = new Confirm_address();

        $confirm->user_id      = $this->scoped->getID();
        $confirm->address_type = 'email';

        if ($confirm->find(true)) {
            return $confirm;
        }

        throw new NoResultException($confirm);
    }

    protected function doPost()
    {
        if ($this->arg('save')) {
            return $this->savePreferences();
        } else if ($this->arg('add')) {
            return $this->addAddress();
        } else if ($this->arg('cancel')) {
            return $this->cancelConfirmation();
        } else if ($this->arg('remove')) {
            return $this->removeAddress();
        } else if ($this->arg('removeincoming')) {
            return $this->removeIncoming();
        } else if ($this->arg('newincoming')) {
            return $this->newIncoming();
        }

        // TRANS: Message given submitting a form with an unknown action in e-mail settings.
        throw new ClientException(_('Unexpected form submission.'));
    }

    /**
     * Save email preferences
     *
     * @return void
     */
    function savePreferences()
    {
        if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
            $emailnotifysub   = $this->booleanintstring('emailnotifysub');
            $emailnotifymsg   = $this->booleanintstring('emailnotifymsg');
            $emailnotifynudge = $this->booleanintstring('emailnotifynudge');
            $emailnotifyattn  = $this->booleanintstring('emailnotifyattn');
            $emailpost        = $this->booleanintstring('emailpost');

            $user = $this->scoped->getUser();
            $user->query('BEGIN');
            $original = clone($user);

            $user->emailnotifysub   = $emailnotifysub;
            $user->emailnotifymsg   = $emailnotifymsg;
            $user->emailnotifynudge = $emailnotifynudge;
            $user->emailnotifyattn  = $emailnotifyattn;
            $user->emailpost        = $emailpost;

            $result = $user->update($original);

            if ($result === false) {
                common_log_db_error($user, 'UPDATE', __FILE__);
                $user->query('ROLLBACK');
                // TRANS: Server error thrown on database error updating e-mail preferences.
                throw new ServerException(_('Could not update user.'));
            }

            $user->query('COMMIT');

            Event::handle('EndEmailSaveForm', array($this, $this->scoped));
        }
        // TRANS: Confirmation message for successful e-mail preferences save.
        return _('Email preferences saved.');
    }

    /**
     * Add the address passed in by the user
     *
     * @return void
     */
    function addAddress()
    {
        $user = $this->scoped->getUser();

        $email = $this->trimmed('email');

        // Some validation

        if (empty($email)) {
            // TRANS: Message given saving e-mail address without having provided one.
            throw new ClientException(_('No email address.'));
        }

        $email = common_canonical_email($email);

        if (empty($email)) {
            // TRANS: Message given saving e-mail address that cannot be normalised.
            throw new ClientException(_('Cannot normalize that email address.'));
        }
        if (!Validate::email($email, common_config('email', 'check_domain'))) {
            // TRANS: Message given saving e-mail address that not valid.
            throw new ClientException(_('Not a valid email address.'));
        } else if ($user->email == $email) {
            // TRANS: Message given saving e-mail address that is already set.
            throw new ClientException(_('That is already your email address.'));
        } else if ($this->emailExists($email)) {
            // TRANS: Message given saving e-mail address that is already set for another user.
            throw new ClientException(_('That email address already belongs to another user.'));
        }

        if (Event::handle('StartAddEmailAddress', array($user, $email))) {

            $confirm = new Confirm_address();

            $confirm->address      = $email;
            $confirm->address_type = 'email';
            $confirm->user_id      = $user->getID();
            $confirm->code         = common_confirmation_code(64);

            $result = $confirm->insert();

            if ($result === false) {
                common_log_db_error($confirm, 'INSERT', __FILE__);
                // TRANS: Server error thrown on database error adding e-mail confirmation code.
                throw new ServerException(_('Could not insert confirmation code.'));
            }

            common_debug('Sending confirmation address for user '.$user->getID().' to email '.$email);
            mail_confirm_address($user, $confirm->code, $user->getNickname(), $email);

            Event::handle('EndAddEmailAddress', array($user, $email));
        }

        // TRANS: Message given saving valid e-mail address that is to be confirmed.
        return _('A confirmation code was sent to the email address you added. '.
                 'Check your inbox (and spam box!) for the code and instructions '.
                 'on how to use it.');
    }

    /**
     * Handle a request to cancel email confirmation
     *
     * @return void
     */
    function cancelConfirmation()
    {
        $email = $this->trimmed('email');

        try {
            $confirm = $this->getConfirmation();
            if ($confirm->address !== $email) {
                // TRANS: Message given canceling e-mail address confirmation for the wrong e-mail address.
                throw new ClientException(_('That is the wrong email address.'));
            }
        } catch (NoResultException $e) {
            // TRANS: Message given canceling e-mail address confirmation that is not pending.
            throw new AlreadyFulfilledException(_('No pending confirmation to cancel.'));
        }

        $result = $confirm->delete();

        if ($result === false) {
            common_log_db_error($confirm, 'DELETE', __FILE__);
            // TRANS: Server error thrown on database error canceling e-mail address confirmation.
            throw new ServerException(_('Could not delete email confirmation.'));
        }

        // TRANS: Message given after successfully canceling e-mail address confirmation.
        return _('Email confirmation cancelled.');
    }

    /**
     * Handle a request to remove an address from the user's account
     *
     * @return void
     */
    function removeAddress()
    {
        $user = common_current_user();

        $email = $this->trimmed('email');

        // Maybe an old tab open...?
        if ($user->email !== $email) {
            // TRANS: Message given trying to remove an e-mail address that is not
            // TRANS: registered for the active user.
            throw new ClientException(_('That is not your email address.'));
        }

        $original = clone($user);
        $user->email = null;
        // Throws exception on failure. Also performs it within a transaction.
        $user->updateWithKeys($original);

        // TRANS: Message given after successfully removing a registered e-mail address.
        return _('The email address was removed.');
    }

    /**
     * Handle a request to remove an incoming email address
     *
     * @return void
     */
    function removeIncoming()
    {
        $user = common_current_user();

        if (empty($user->incomingemail)) {
            // TRANS: Form validation error displayed when trying to remove an incoming e-mail address while no address has been set.
            throw new AlreadyFulfilledException(_('No incoming email address.'));
        }

        $orig = clone($user);
        $user->incomingemail = null;
        $user->emailpost = 0;
        // Throws exception on failure. Also performs it within a transaction.
        $user->updateWithKeys($orig);

        // TRANS: Message given after successfully removing an incoming e-mail address.
        return _('Incoming email address removed.');
    }

    /**
     * Generate a new incoming email address
     *
     * @return void
     */
    function newIncoming()
    {
        $user = common_current_user();
        $orig = clone($user);
        $user->incomingemail = mail_new_incoming_address();
        $user->emailpost = 1;
        // Throws exception on failure. Also performs it within a transaction.
        $user->updateWithKeys($orig);

        // TRANS: Message given after successfully adding an incoming e-mail address.
        return _('New incoming email address added.');
    }

    /**
     * Does another user already have this email address?
     *
     * Email addresses are unique for users.
     *
     * @param string $email Address to check
     *
     * @return boolean Whether the email already exists.
     */

    function emailExists($email)
    {
        $user = common_current_user();

        $other = User::getKV('email', $email);

        if (!$other instanceof User) {
            return false;
        }

        return $other->id != $user->id;
    }
}


code:
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * List of featured users
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Public
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2008-2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR.'/lib/profilelist.php';
require_once INSTALLDIR.'/lib/publicgroupnav.php';

/**
 * List of featured users
 *
 * @category Public
 * @package  StatusNet
 * @author   Zach Copley <zach@status.net>
 * @author   Evan Prodromou <evan@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class FeaturedAction extends Action
{
    var $page = null;

    function isReadOnly($args)
    {
        return true;
    }

    function prepare($args)
    {
        parent::prepare($args);
        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;

        return true;
    }

    function title()
    {
        if ($this->page == 1) {
            // TRANS: Page title for first page of featured users.
            return _('Featured users');
        } else {
            // TRANS: Page title for all but first page of featured users.
            // TRANS: %d is the page number being displayed.
            return sprintf(_('Featured users, page %d'), $this->page);
        }
    }

    function handle($args)
    {
        parent::handle($args);

        $this->showPage();
    }

    function showPageNotice()
    {
        $instr = $this->getInstructions();
        $output = common_markup_to_html($instr);
        $this->elementStart('div', 'instructions');
        $this->raw($output);
        $this->elementEnd('div');
    }

    function getInstructions()
    {
        // TRANS: Description on page displaying featured users.
        return sprintf(_('A selection of some great users on %s.'),
                       common_config('site', 'name'));
    }

    function showContent()
    {
        // XXX: Note I'm doing it this two-stage way because a raw query
        // with a JOIN was *not* working. --Zach

        $featured_nicks = common_config('nickname', 'featured');

        if (count($featured_nicks) > 0) {

            $quoted = array();

            foreach ($featured_nicks as $nick) {
                $quoted[] = "'$nick'";
            }

            $user = new User;
            $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
            $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
            $user->orderBy(common_database_tablename('user') .'.nickname ASC');

            $user->find();

            $profile_ids = array();

            while ($user->fetch()) {
                $profile_ids[] = $user->id;
            }

            $profile = new Profile;
            $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
            $profile->orderBy('nickname ASC');

            $cnt = $profile->find();

            if ($cnt > 0) {
                $featured = new ProfileList($profile, $this);
                $featured->show();
            }

            $profile->free();

            $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
                              $this->page, 'featured');
        }
    }
}