summaryrefslogtreecommitdiff
path: root/plugins/Repeat/inboxnoticelist.php
blob: 809fbe8af965276d29043b8c140f4544edb69d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
79
80
81
82
83
84
85
<?php

class InboxNoticeList extends NoticeList
{
    var $owner = null;

    function __construct($notice, $owner, $out=null)
    {
        parent::__construct($notice, $out);
        $this->owner  = $owner;
    }

    function newListItem($notice)
    {
        return new InboxNoticeListItem($notice, $this->owner, $this->out);
    }
}

class InboxNoticeListItem extends NoticeListItem
{
    var $owner = null;
    var $ib    = null;

    function __construct($notice, $owner, $out=null)
    {
        parent::__construct($notice, $out);
        $this->owner = $owner;

        $this->ib = Notice_inbox::pkeyGet(array('user_id' => $owner->id,
                                                'notice_id' => $notice->id));
    }

    function showAuthor()
    {
        parent::showAuthor();
        if ($this->ib->source == NOTICE_INBOX_SOURCE_FORWARD) {
            $this->out->element('span', 'forward', _('Fwd'));
        }
    }

    function showEnd()
    {
        if ($this->ib->source == NOTICE_INBOX_SOURCE_FORWARD) {

            $forward = new Forward();

            // FIXME: scary join!

            $forward->query('SELECT profile_id '.
                            'FROM forward JOIN subscription ON forward.profile_id = subscription.subscribed '.
                            'WHERE subscription.subscriber = ' . $this->owner->id . ' '.
                            'AND forward.notice_id = ' . $this->notice->id . ' '.
                            'ORDER BY forward.created ');

            $n = 0;

            $firstForwarder = null;

            while ($forward->fetch()) {
                if (empty($firstForwarder)) {
                    $firstForwarder = Profile::staticGet('id', $forward->profile_id);
                }
                $n++;
            }

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

            $this->out->elementStart('span', 'forwards');

            $link = XMLStringer::estring('a', array('href' => $firstForwarder->profileurl),
                                         $firstForwarder->nickname);

            if ($n == 1) {
                $this->out->raw(sprintf(_('Forwarded by %s'), $link));
            } else {
                // XXX: use that cool ngettext thing
                $this->out->raw(sprintf(_('Forwarded by %s and %d other(s)'), $link, $n - 1));
            }

            $this->out->elementEnd('span');
        }
        parent::showEnd();
    }
}