]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/noticelistactorsitem.php
If there's no Happening, we can't use the RSVP.
[quix0rs-gnu-social.git] / lib / noticelistactorsitem.php
1 <?php
2 /**
3  * GNU Social - a federating social network
4  * Copyright (C) 2014, Free Software Foundation, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * Placeholder for showing faves...
24  */
25 abstract class NoticeListActorsItem extends NoticeListItem
26 {
27     /**
28      * @return array of profile IDs
29      */
30     abstract function getProfiles();
31
32     abstract function getListMessage($count, $you);
33
34     function show()
35     {
36         $links = array();
37         $you = false;
38         $cur = common_current_user();
39         foreach ($this->getProfiles() as $id) {
40             if ($cur && $cur->id == $id) {
41                 $you = true;
42                 // TRANS: Reference to the logged in user in favourite list.
43                 array_unshift($links, _m('FAVELIST', 'You'));
44             } else {
45                 $profile = Profile::getKV('id', $id);
46                 if ($profile instanceof Profile) {
47                     $links[] = sprintf('<a class="h-card" href="%s">%s</a>',
48                                        htmlspecialchars($profile->getUrl()),
49                                        htmlspecialchars($profile->getBestName()));
50                 }
51             }
52         }
53
54         if ($links) {
55             $count = count($links);
56             $msg = $this->getListMessage($count, $you);
57             $out = sprintf($msg, $this->magicList($links));
58
59             $this->showStart();
60             $this->out->raw($out);
61             $this->showEnd();
62             return $count;
63         } else {
64             return 0;
65         }
66     }
67
68     function magicList($items)
69     {
70         if (count($items) == 0) {
71             return '';
72         } else if (count($items) == 1) {
73             return $items[0];
74         } else {
75             $first = array_slice($items, 0, -1);
76             $last = array_slice($items, -1, 1);
77             // TRANS: Separator in list of user names like "Jim, Bob, Mary".
78             $separator = _(', ');
79             // TRANS: For building a list such as "Jim, Bob, Mary and 5 others like this".
80             // TRANS: %1$s is a list of users, separated by a separator (default: ", "), %2$s is the last user in the list.
81             return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode($separator, $first), implode($separator, $last));
82         }
83     }
84 }