123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ConversationTree extends NoticeList
- {
- var $tree = null;
- var $table = null;
-
- function show()
- {
- $cnt = $this->_buildTree();
- $this->out->elementStart('div', array('id' =>'notices_primary'));
-
- $this->out->element('h2', null, _('Notices'));
- $this->out->elementStart('ol', array('class' => 'notices xoxo old-school'));
- if (array_key_exists('root', $this->tree)) {
- $rootid = $this->tree['root'][0];
- $this->showNoticePlus($rootid);
- }
- $this->out->elementEnd('ol');
- $this->out->elementEnd('div');
- return $cnt;
- }
- function _buildTree()
- {
- $cnt = 0;
- $this->tree = array();
- $this->table = array();
- while ($this->notice->fetch()) {
- $cnt++;
- $id = $this->notice->id;
- $notice = clone($this->notice);
- $this->table[$id] = $notice;
- if (is_null($notice->reply_to)) {
- $this->tree['root'] = array($notice->id);
- } else if (array_key_exists($notice->reply_to, $this->tree)) {
- $this->tree[$notice->reply_to][] = $notice->id;
- } else {
- $this->tree[$notice->reply_to] = array($notice->id);
- }
- }
- return $cnt;
- }
-
- function showNoticePlus($id)
- {
- $notice = $this->table[$id];
- $this->out->elementStart('li', array('class' => 'h-entry notice',
- 'id' => 'notice-' . $id));
- $item = $this->newListItem($notice);
- $item->show();
- if (array_key_exists($id, $this->tree)) {
- $children = $this->tree[$id];
- $this->out->elementStart('ol', array('class' => 'notices threaded-replies xoxo'));
- sort($children);
- foreach ($children as $child) {
- $this->showNoticePlus($child);
- }
- $this->out->elementEnd('ol');
- }
- $this->out->elementEnd('li');
- }
-
- function newListItem(Notice $notice)
- {
- return new ConversationTreeItem($notice, $this->out);
- }
- }
|