12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- abstract class NoticeListActorsItem extends NoticeListItem
- {
-
- abstract function getProfiles();
- abstract function getListMessage($count, $you);
- function show()
- {
- $links = array();
- $you = false;
- $cur = common_current_user();
- foreach ($this->getProfiles() as $id) {
- if ($cur && $cur->id == $id) {
- $you = true;
-
- array_unshift($links, _m('FAVELIST', 'You'));
- } else {
- $profile = Profile::getKV('id', $id);
- if ($profile instanceof Profile) {
- $links[] = sprintf('<a class="h-card" href="%s">%s</a>',
- htmlspecialchars($profile->getUrl()),
- htmlspecialchars($profile->getBestName()));
- }
- }
- }
- if ($links) {
- $count = count($links);
- $msg = $this->getListMessage($count, $you);
- $out = sprintf($msg, $this->magicList($links));
- $this->showStart();
- $this->out->raw($out);
- $this->showEnd();
- return $count;
- } else {
- return 0;
- }
- }
- function magicList($items)
- {
- if (count($items) == 0) {
- return '';
- } else if (count($items) == 1) {
- return $items[0];
- } else {
- $first = array_slice($items, 0, -1);
- $last = array_slice($items, -1, 1);
-
- $separator = _(', ');
-
-
- return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode($separator, $first), implode($separator, $last));
- }
- }
- }
|