articles = $articles; /* * We need to build a tree of the articles. We know they are in article * number order, we assume that this means that parents come before * children. There may end up being some posts that appear unattached * and we just assume they are replies to the root of the tree. */ foreach ($this->articles as $articleNumber => $details) { $messageId = $details['messageId']; if (!isset($this->root)) { $this->root = $messageId; } $this->articleNumbers[$messageId] = $articleNumber; if ($details['references']) { /* Parent is the last reference. */ if (preg_match('/.*(<.+?>)$/', $details['references'], $matches)) { $parent = $matches[1]; $this->tree[$parent][] = $messageId; if (!array_key_exists($parent, $this->articleNumbers)) { $this->extraRootChildren[] = $parent; } } } else { if ($this->root && $this->root != $messageId) { $this->extraRootChildren[] = $messageId; } } } } public function count() { return count($this->articleNumbers); } protected function printArticleAndChildren($messageId, $group, $charset, $depth = 0) { if (array_key_exists($messageId, $this->articleNumbers)) { $articleNumber = $this->articleNumbers[$messageId]; # for debugging that we've actually handled all articles #unset($this->articleNumbers[$messageId]); $details = $this->articles[$articleNumber]; echo " \n"; echo " $articleNumber\n"; echo " "; echo str_repeat("   ", $depth ?? 0); echo ""; echo format_subject($details['subject'], $charset); echo "\n"; echo " " . format_author($details['author'], $charset) . "\n"; echo " " . format_date($details['date']) . "\n"; echo " \n"; } // bail out if things are too deep if ($depth > 40) { error_log("Tree was too deep, didn't print children of {$messageId})"); return; } if (array_key_exists($messageId, $this->tree)) { foreach ($this->tree[$messageId] as $child) { $this->printArticleAndChildren($child, $group, $charset, $depth + 1); } } } public function printRows($group, $charset = 'utf8') { $this->printArticleAndChildren($this->root, $group, $charset); foreach ($this->extraRootChildren as $root) { $this->printArticleAndChildren($root, $group, $charset, 1); } } public function printFullThread( $group, $includingArticleNumber, $charset = null ) { echo "
"; } public function printThread( $group, $messageId = null, $activeArticleNumber = null, $depth = 0, $subject = "", $charset = 'utf8' ) { if ($depth > 40) { echo "
  • Too deep!
  • "; return; } # for debugging that we've actually handled all articles #unset($this->articleNumbers[$messageId]); echo '
  • '; if (array_key_exists($messageId, $this->articleNumbers)) { $articleNumber = $this->articleNumbers[$messageId]; $details = $this->articles[$articleNumber]; if ($articleNumber != $activeArticleNumber) { echo ""; } else { echo ""; } echo '', format_author($details['author'], $charset, nameOnly: true), '', '', '', ''; $newSubject = format_subject($details['subject'], $charset, trimRe: true); if ($messageId != $this->root && $newSubject != $subject) { echo ''; echo format_subject($details['subject'], $charset); echo ''; } if ($articleNumber != $activeArticleNumber) { echo ""; } else { echo ""; } } else { echo "Unknown Message"; $newSubject = $messageId; } if (array_key_exists($messageId, $this->tree)) { echo ''; } echo "
  • "; } }