noticelistactorsitem.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if (!defined('GNUSOCIAL')) { exit(1); }
  20. /**
  21. * Placeholder for showing faves...
  22. */
  23. abstract class NoticeListActorsItem extends NoticeListItem
  24. {
  25. /**
  26. * @return array of profile IDs
  27. */
  28. abstract function getProfiles();
  29. abstract function getListMessage($count, $you);
  30. function show()
  31. {
  32. $links = array();
  33. $you = false;
  34. $cur = common_current_user();
  35. foreach ($this->getProfiles() as $id) {
  36. if ($cur && $cur->id == $id) {
  37. $you = true;
  38. // TRANS: Reference to the logged in user in favourite list.
  39. array_unshift($links, _m('FAVELIST', 'You'));
  40. } else {
  41. $profile = Profile::getKV('id', $id);
  42. if ($profile instanceof Profile) {
  43. $links[] = sprintf('<a class="h-card" href="%s">%s</a>',
  44. htmlspecialchars($profile->getUrl()),
  45. htmlspecialchars($profile->getBestName()));
  46. }
  47. }
  48. }
  49. if ($links) {
  50. $count = count($links);
  51. $msg = $this->getListMessage($count, $you);
  52. $out = sprintf($msg, $this->magicList($links));
  53. $this->showStart();
  54. $this->out->raw($out);
  55. $this->showEnd();
  56. return $count;
  57. } else {
  58. return 0;
  59. }
  60. }
  61. function magicList($items)
  62. {
  63. if (count($items) == 0) {
  64. return '';
  65. } else if (count($items) == 1) {
  66. return $items[0];
  67. } else {
  68. $first = array_slice($items, 0, -1);
  69. $last = array_slice($items, -1, 1);
  70. // TRANS: Separator in list of user names like "Jim, Bob, Mary".
  71. $separator = _(', ');
  72. // TRANS: For building a list such as "Jim, Bob, Mary and 5 others like this".
  73. // TRANS: %1$s is a list of users, separated by a separator (default: ", "), %2$s is the last user in the list.
  74. return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode($separator, $first), implode($separator, $last));
  75. }
  76. }
  77. }