123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ThreadedNoticeList extends NoticeList
- {
- protected $userProfile;
- function __construct(Notice $notice, Action $out=null, $profile=-1)
- {
- parent::__construct($notice, $out);
- if (is_int($profile) && $profile == -1) {
- $profile = Profile::current();
- }
- $this->userProfile = $profile;
- }
-
- function show()
- {
- $this->out->elementStart('div', array('id' =>'notices_primary'));
-
- $this->out->element('h2', null, _m('HEADER','Notices'));
- $this->out->elementStart('ol', array('class' => 'notices threaded-notices xoxo'));
- $notices = $this->notice->fetchAll();
- $total = count($notices);
- $notices = array_slice($notices, 0, NOTICES_PER_PAGE);
-
- $allnotices = self::_allNotices($notices);
- self::prefill($allnotices);
-
- $conversations = array();
-
- foreach ($notices as $notice) {
-
-
- if ($notice->repeat_of) {
- $orig = Notice::getKV('id', $notice->repeat_of);
- if ($orig instanceof Notice) {
- $notice = $orig;
- }
- }
- $convo = $notice->conversation;
- if (!empty($conversations[$convo])) {
-
- continue;
- }
- $conversations[$convo] = true;
-
- $root = $notice->conversationRoot($this->userProfile);
- if ($root instanceof Notice) {
- $notice = $root;
- }
- try {
- $item = $this->newListItem($notice);
- $item->show();
- } catch (Exception $e) {
-
- common_log(LOG_ERR, $e->getMessage());
- continue;
- }
- }
- $this->out->elementEnd('ol');
- $this->out->elementEnd('div');
- return $total;
- }
- function _allNotices($notices)
- {
- $convId = array();
- foreach ($notices as $notice) {
- $convId[] = $notice->conversation;
- }
- $convId = array_unique($convId);
- $allMap = Notice::listGet('conversation', $convId);
- $allArray = array();
- foreach ($allMap as $convId => $convNotices) {
- $allArray = array_merge($allArray, $convNotices);
- }
- return $allArray;
- }
-
- function newListItem(Notice $notice)
- {
- return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile);
- }
- }
|