messageform.php 5.64 KB
Newer Older
1 2
<?php
/**
3
 * StatusNet, the distributed open-source microblogging tool
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Form for posting a direct message
 *
 * 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  Form
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
26
 * @copyright 2009 StatusNet, Inc.
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28
 * @link      http://status.net/
29 30
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
32 33 34 35 36 37 38 39 40
    exit(1);
}

require_once INSTALLDIR.'/lib/form.php';

/**
 * Form for posting a direct message
 *
 * @category Form
41
 * @package  StatusNet
42 43
 * @author   Evan Prodromou <evan@status.net>
 * @author   Sarven Capadisli <csarven@status.net>
44
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45
 * @link     http://status.net/
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
 *
 * @see      HTMLOutputter
 */
class MessageForm extends Form
{
    /**
     * User to send a direct message to
     */
    var $to = null;

    /**
     * Pre-filled content of the form
     */
    var $content = null;

    /**
     * Constructor
     *
     * @param HTMLOutputter $out     output channel
     * @param User          $to      user to send a message to
     * @param string        $content content to pre-fill
     */
    function __construct($out=null, $to=null, $content=null)
    {
        parent::__construct($out);

        $this->to      = $to;
        $this->content = $content;
    }

    /**
     * ID of the form
     *
79
     * @return string ID of the form
80 81
     */
    function id()
82 83 84 85 86 87 88 89 90 91
    {
        return 'form_notice-direct';
    }

   /**
     * Class of the form
     *
     * @return string class of the form
     */
    function formClass()
92
    {
93
        return 'form_notice ajax-notice';
94 95 96 97 98 99 100 101 102 103 104 105
    }

    /**
     * Action of the form
     *
     * @return string URL of the action
     */
    function action()
    {
        return common_local_url('newmessage');
    }

sarven's avatar
sarven committed
106 107 108 109 110 111 112
    /**
     * Legend of the Form
     *
     * @return void
     */
    function formLegend()
    {
113
        // TRANS: Form legend for direct notice.
sarven's avatar
sarven committed
114 115 116
        $this->out->element('legend', null, _('Send a direct notice'));
    }

117 118 119 120 121 122 123 124 125 126 127 128
    /**
     * Data elements
     *
     * @return void
     */
    function formData()
    {
        $user = common_current_user();

        $mutual_users = $user->mutuallySubscribedUsers();

        $mutual = array();
129 130 131
        // TRANS: Label entry in drop-down selection box in direct-message inbox/outbox.
        // TRANS: This is the default entry in the drop-down box, doubling as instructions
        // TRANS: and a brake against accidental submissions with the first user in the list.
132
        $mutual[0] = _('Select recipient:');
133 134 135 136 137 138 139 140 141 142

        while ($mutual_users->fetch()) {
            if ($mutual_users->id != $user->id) {
                $mutual[$mutual_users->id] = $mutual_users->nickname;
            }
        }

        $mutual_users->free();
        unset($mutual_users);

143
        if (count($mutual) == 1) {
144
            // TRANS: Entry in drop-down selection box in direct-message inbox/outbox when no one is available to message.
145 146 147
            $mutual[0] = _('No mutual subscribers.');
        }

148
        // TRANS: Dropdown label in direct notice form.
149
        $this->out->dropdown('to', _('To'), $mutual, null, false,
150
                             ($this->to) ? $this->to->id : null);
151

152
        $this->out->element('textarea', array('class' => 'notice_data-text',
sarven's avatar
sarven committed
153 154
                                              'cols' => 35,
                                              'rows' => 4,
155 156
                                              'name' => 'content'),
                            ($this->content) ? $this->content : '');
157

158 159 160
        $contentLimit = Message::maxContent();

        if ($contentLimit > 0) {
161
            $this->out->element('span',
162
                                array('class' => 'count'),
163 164
                                $contentLimit);
        }
165 166 167 168 169 170 171 172 173
    }

    /**
     * Action elements
     *
     * @return void
     */
    function formActions()
    {
sarven's avatar
sarven committed
174 175
        $this->out->element('input', array('id' => 'notice_action-submit',
                                           'class' => 'submit',
176 177
                                           'name' => 'message_send',
                                           'type' => 'submit',
178
                                           // TRANS: Button text for sending a direct notice.
179
                                           'value' => _m('Send button for sending notice', 'Send')));
180
    }
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198


    /**
     * Show the form
     *
     * Uses a recipe to output the form.
     *
     * @return void
     * @see Widget::show()
     */

    function show()
    {
        $this->elementStart('div', 'input_forms');
        $this->elementStart(
            'div',
            array(
                'id'    => 'input_form_direct',
199
                'class' => 'input_form current nonav'
200 201 202 203 204 205 206 207 208
            )
        );

        parent::show();

        $this->elementEnd('div');
        $this->elementEnd('div');

    }
sarven's avatar
sarven committed
209
}