threadednoticelistitem.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. if (!defined('GNUSOCIAL')) { exit(1); }
  3. /**
  4. * widget for displaying a single notice
  5. *
  6. * This widget has the core smarts for showing a single notice: what to display,
  7. * where, and under which circumstances. Its key method is show(); this is a recipe
  8. * that calls all the other show*() methods to build up a single notice. The
  9. * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
  10. * author info (since that's implicit by the data in the page).
  11. *
  12. * @category UI
  13. * @package StatusNet
  14. * @author Evan Prodromou <evan@status.net>
  15. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  16. * @link http://status.net/
  17. * @see NoticeList
  18. * @see ProfileNoticeListItem
  19. */
  20. class ThreadedNoticeListItem extends NoticeListItem
  21. {
  22. protected $userProfile = null;
  23. function __construct(Notice $notice, Action $out=null, $profile=null)
  24. {
  25. parent::__construct($notice, $out);
  26. $this->userProfile = $profile;
  27. }
  28. function initialItems()
  29. {
  30. return 3;
  31. }
  32. /**
  33. * finish the notice
  34. *
  35. * Close the last elements in the notice list item
  36. *
  37. * @return void
  38. */
  39. function showEnd()
  40. {
  41. $max = $this->initialItems();
  42. if (!$this->repeat instanceof Notice) {
  43. $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
  44. $notice = $stream->getNotices(0, $max + 2);
  45. $notices = array();
  46. $cnt = 0;
  47. $moreCutoff = null;
  48. while ($notice->fetch()) {
  49. if (Event::handle('StartAddNoticeReply', array($this, $this->notice, $notice))) {
  50. // Don't list repeats as separate notices in a conversation
  51. if (!empty($notice->repeat_of)) {
  52. continue;
  53. }
  54. if ($notice->id == $this->notice->id) {
  55. // Skip!
  56. continue;
  57. }
  58. if (!$notice->isVerb([ActivityVerb::POST])) {
  59. continue;
  60. }
  61. $cnt++;
  62. if ($cnt > $max) {
  63. // boo-yah
  64. $moreCutoff = clone($notice);
  65. break;
  66. }
  67. $notices[] = clone($notice); // *grumble* inefficient as hell
  68. Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice));
  69. }
  70. }
  71. if (Event::handle('StartShowThreadedNoticeTail', array($this, $this->notice, &$notices))) {
  72. $threadActive = count($notices) > 0; // has this thread had any activity?
  73. $this->out->elementStart('ul', 'notices threaded-replies xoxo');
  74. if (Event::handle('StartShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive))) {
  75. // Repeats and Faves/Likes are handled in plugins.
  76. Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
  77. }
  78. if (count($notices)>0) {
  79. if ($moreCutoff) {
  80. $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
  81. $item->show();
  82. }
  83. foreach (array_reverse($notices) as $notice) {
  84. if (Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice))) {
  85. $item = new ThreadedNoticeListSubItem($notice, $this->notice, $this->out);
  86. $item->show();
  87. Event::handle('EndShowThreadedNoticeSub', array($this, $this->notice, $notice));
  88. }
  89. }
  90. }
  91. Event::handle('EndShowThreadedNoticeTail', array($this, $this->notice, $notices));
  92. $this->out->elementEnd('ul');
  93. }
  94. }
  95. parent::showEnd();
  96. }
  97. }