We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

conversation.php 5.03 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2 3 4 5 6 7
<?php
/**
 * Display a conversation in the browser
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
10
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11
 * @link     http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
12
 *
13
 * StatusNet - the distributed open-source microblogging tool
14
 * Copyright (C) 2009, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 * 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/>.
 */

30
if (!defined('STATUSNET') && !defined('LACONICA')) {
Evan Prodromou's avatar
Evan Prodromou committed
31 32 33
    exit(1);
}

Evan Prodromou's avatar
Evan Prodromou committed
34 35 36
// XXX: not sure how to do paging yet,
// so set a 60-notice limit

37
require_once INSTALLDIR.'/lib/noticelist.php';
Evan Prodromou's avatar
Evan Prodromou committed
38

Evan Prodromou's avatar
Evan Prodromou committed
39 40 41 42
/**
 * Conversation tree in the browser
 *
 * @category Action
43
 * @package  StatusNet
44
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
45
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46
 * @link     http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
47 48 49
 */
class ConversationAction extends Action
{
50 51 52 53
    var $id          = null;
    var $page        = null;
    var $notices     = null;
    var $userProfile = null;
54 55

    const MAX_NOTICES = 500;
Evan Prodromou's avatar
Evan Prodromou committed
56 57 58 59 60 61 62 63 64 65 66 67

    /**
     * Initialization.
     *
     * @param array $args Web and URL arguments
     *
     * @return boolean false if id not passed in
     */
    function prepare($args)
    {
        parent::prepare($args);
        $this->id = $this->trimmed('id');
Evan Prodromou's avatar
Evan Prodromou committed
68
        if (empty($this->id)) {
Evan Prodromou's avatar
Evan Prodromou committed
69 70
            return false;
        }
71
        $this->id = $this->id+0;
Evan Prodromou's avatar
Evan Prodromou committed
72 73 74 75
        $this->page = $this->trimmed('page');
        if (empty($this->page)) {
            $this->page = 1;
        }
76 77 78 79

        $cur = common_current_user();

        if (empty($cur)) {
80
            $this->userProfile = null;
81
        } else {
82
            $this->userProfile = $cur->getProfile();
83 84
        }

85
        $stream = new ConversationNoticeStream($this->id, $this->userProfile);
86

87
        $this->notices = $stream->getNotices(0, self::MAX_NOTICES);
88

Evan Prodromou's avatar
Evan Prodromou committed
89 90 91
        return true;
    }

92 93 94 95 96 97 98
    /**
     * Handle the action
     *
     * @param array $args Web and URL arguments
     *
     * @return void
     */
Evan Prodromou's avatar
Evan Prodromou committed
99 100
    function handle($args)
    {
Evan Prodromou's avatar
Evan Prodromou committed
101
        parent::handle($args);
Evan Prodromou's avatar
Evan Prodromou committed
102 103 104
        $this->showPage();
    }

105 106 107 108 109
    /**
     * Returns the page title
     *
     * @return string page title
     */
Evan Prodromou's avatar
Evan Prodromou committed
110 111
    function title()
    {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
112 113
        // TRANS: Title for page with a conversion (multiple notices in context).
        return _('Conversation');
Evan Prodromou's avatar
Evan Prodromou committed
114 115
    }

116 117 118 119 120 121 122 123
    /**
     * Show content.
     *
     * Display a hierarchical unordered list in the content area.
     * Uses ConversationTree to do most of the heavy lifting.
     *
     * @return void
     */
Evan Prodromou's avatar
Evan Prodromou committed
124 125
    function showContent()
    {
126
        $user = common_current_user();
Evan Prodromou's avatar
Evan Prodromou committed
127

128 129 130 131 132 133 134
        if (!empty($user) && $user->conversationTree()) {
            $nl = new ConversationTree($this->notices, $this);
        } else {
            $nl = new FullThreadedNoticeList($this->notices, $this, $this->userProfile);
        }

        $cnt = $nl->show();
Evan Prodromou's avatar
Evan Prodromou committed
135
    }
136 137 138 139 140

    function isReadOnly()
    {
        return true;
    }
Evan Prodromou's avatar
Evan Prodromou committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    
    function getFeeds()
    {
    	
        return array(new Feed(Feed::JSON,
                              common_local_url('apiconversation',
                                               array(
                                                    'id' => $this->id,
                                                    'format' => 'as')),
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
                              _('Conversation feed (Activity Streams JSON)')),
                     new Feed(Feed::RSS2,
                              common_local_url('apiconversation',
                                               array(
                                                    'id' => $this->id,
                                                    'format' => 'rss')),
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
                              _('Conversation feed (RSS 2.0)')),
                     new Feed(Feed::ATOM,
                              common_local_url('apiconversation',
                                               array(
                                                    'id' => $this->id,
                                                    'format' => 'atom')),
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
                              _('Conversation feed (Activity Streams JSON)')));
    }
Evan Prodromou's avatar
Evan Prodromou committed
170
}
171