UTF-8...
[banana.git] / banana / spool.inc.php
CommitLineData
78cd27b3 1<?php
2/********************************************************************************
3* include/spool.inc.php : spool subroutines
4* -----------------------
5*
6* This file is part of the banana distribution
7* Copyright: See COPYING files that comes with this distribution
8********************************************************************************/
9
ab02e8a9 10require_once dirname(__FILE__) . '/banana.inc.php';
78cd27b3 11
ab02e8a9 12define('BANANA_SPOOL_VERSION', '0.3');
78cd27b3 13
14/** Class spoolhead
15 * class used in thread overviews
16 */
17class BananaSpoolHead
18{
19 /** date (timestamp) */
ab02e8a9 20 public $date;
78cd27b3 21 /** subject */
ab02e8a9 22 public $subject;
78cd27b3 23 /** author */
ab02e8a9 24 public $from;
78cd27b3 25 /** reference of parent */
ab02e8a9 26 public $parent = null;
78cd27b3 27 /** paren is direct */
ab02e8a9 28 public $parent_direct;
78cd27b3 29 /** array of children */
ab02e8a9 30 public $children = Array();
78cd27b3 31 /** true if post is read */
ab02e8a9 32 public $isread;
78cd27b3 33 /** number of posts deeper in this branch of tree */
ab02e8a9 34 public $desc;
78cd27b3 35 /** same as desc, but counts only unread posts */
ab02e8a9 36 public $descunread;
37
38 /** storage data */
39 public $storage = array();
78cd27b3 40
41 /** constructor
42 * @param $_date INTEGER timestamp of post
43 * @param $_subject STRING subject of post
44 * @param $_from STRING author of post
45 * @param $_desc INTEGER desc value (1 for a new post)
46 * @param $_read BOOLEAN true if read
47 * @param $_descunread INTEGER descunread value (0 for a new post)
48 */
ab02e8a9 49 public function __construct(array &$message)
78cd27b3 50 {
ab02e8a9 51 $this->date = $message['date'];
d7718cc5 52 $this->subject = $message['subject'];
ab02e8a9 53 $this->from = $message['from'];
54 $this->desc = 1;
55 $this->isread = true;
56 $this->descunread = 0;
78cd27b3 57 }
58}
59
78cd27b3 60
61class BananaSpool
62{
ab02e8a9 63 private $version;
7972645b 64 private $mode;
ab02e8a9 65
78cd27b3 66 /** group name */
ab02e8a9 67 public $group;
68 /** spool */
69 public $overview;
78cd27b3 70 /** array msgid => msgnum */
ab02e8a9 71 public $ids;
78cd27b3 72 /** thread starts */
ab02e8a9 73 public $roots;
74
78cd27b3 75
76 /** constructor
77 * @param $_group STRING group name
78 * @param $_display INTEGER 1 => all posts, 2 => only threads with new posts
79 * @param $_since INTEGER time stamp (used for read/unread)
80 */
ab02e8a9 81 protected function __construct($group)
78cd27b3 82 {
ab02e8a9 83 $this->version = BANANA_SPOOL_VERSION;
7972645b 84 $this->mode = Banana::SPOOL_ALL;
ab02e8a9 85 $this->group = $group;
86 }
9d18c838 87
4d20320e 88 public static function getSpool($group, $since = 0, $clean = false)
ab02e8a9 89 {
90 if (!is_null(Banana::$spool) && Banana::$spool->group == $group) {
4d20320e 91 $spool =& Banana::$spool;
78cd27b3 92 } else {
ab02e8a9 93 $spool = BananaSpool::readFromFile($group);
94 }
95 if (is_null($spool)) {
96 $spool = new BananaSpool($group);
78cd27b3 97 }
ab02e8a9 98 Banana::$spool =& $spool;
99 $spool->build();
4d20320e 100 if ($clean) {
101 $spool->markAllAsRead();
102 }
ab02e8a9 103 $spool->updateUnread($since);
104 return $spool;
105 }
78cd27b3 106
ab02e8a9 107 private static function spoolFilename($group)
108 {
df5a7969 109 $file = Banana::$spool_root . '/' . Banana::$protocole->name() . '/';
ab02e8a9 110 if (!is_dir($file)) {
111 mkdir($file);
78cd27b3 112 }
7972645b 113 return $file . Banana::$protocole->filename();
78cd27b3 114 }
115
ab02e8a9 116 private static function readFromFile($group)
78cd27b3 117 {
ab02e8a9 118 $file = BananaSpool::spoolFilename($group);
119 if (!file_exists($file)) {
120 return null;
78cd27b3 121 }
ab02e8a9 122 $spool = unserialize(file_get_contents($file));
7972645b 123 if ($spool->version != BANANA_SPOOL_VERSION || $spool->mode != Banana::SPOOL_ALL) {
ab02e8a9 124 return null;
125 }
126 return $spool;
127 }
128
129 private function compare($a, $b)
130 {
131 return ($b->date >= $a->date);
78cd27b3 132 }
133
ab02e8a9 134 private function saveToFile()
78cd27b3 135 {
ab02e8a9 136 $file = BananaSpool::spoolFilename($this->group);
137 uasort($this->overview, array($this, 'compare'));
78cd27b3 138
139 $this->roots = Array();
140 foreach($this->overview as $id=>$msg) {
141 if (is_null($msg->parent)) {
142 $this->roots[] = $id;
143 }
144 }
01972ace 145
7972645b 146 if ($this->mode == Banana::SPOOL_ALL) {
147 file_put_contents($file, serialize($this));
148 }
78cd27b3 149 }
150
ab02e8a9 151 private function build()
152 {
153 $threshold = 0;
154
155 // Compute the range of indexes
156 list($msgnum, $first, $last) = Banana::$protocole->getIndexes();
157 if ($last < $first) {
158 $threshold = $firt + $msgnum - $last;
159 $threshold = (int)(log($threshold)/log(2));
160 $threshold = (2 ^ ($threshold + 1)) - 1;
161 }
7972645b 162 if (Banana::$spool_max && Banana::$spool_max < $msgnum) {
163 $first = $last - Banana::$spool_max;
ab02e8a9 164 if ($first < 0) {
165 $first += $threshold;
166 }
167 }
168 $clean = $this->clean($first, $last, $msgnum);
169 $update = $this->update($first, $last, $msgnum);
170
171 if ($clean || $update) {
172 $this->saveToFile();
173 }
174 }
175
176 private function clean(&$first, &$last, $msgnum)
78cd27b3 177 {
ab02e8a9 178 $do_save = false;
179 if (is_array($this->overview)) {
180 $mids = array_keys($this->overview);
181 foreach ($mids as $id) {
182 if (($first <= $last && ($id < $first || $id > $last))
7972645b 183 || ($first > $last && $id < $first && $id > $last)) {
ab02e8a9 184 $this->delid($id, false);
185 $do_save = true;
186 }
187 }
188 if (!empty($this->overview)) {
189 $first = max(array_keys($this->overview))+1;
190 }
191 }
192 return $do_save;
78cd27b3 193 }
194
ab02e8a9 195 private function update(&$first, &$last, $msgnum)
78cd27b3 196 {
ded3974d 197 if ($first > $last || !$msgnum) {
ab02e8a9 198 return false;
78cd27b3 199 }
200
ab02e8a9 201 $messages =& Banana::$protocole->getMessageHeaders($first, $last,
202 array('Date', 'Subject', 'From', 'Message-ID', 'References', 'In-Reply-To'));
78cd27b3 203
ab02e8a9 204 if (!is_array($this->ids)) {
205 $this->ids = array();
206 }
207 foreach ($messages as $id=>&$message) {
208 $this->ids[$message['message-id']] = $id;
209 }
210
a20df265 211 if (!is_array($this->overview)) {
212 $this->overview = array();
213 }
ab02e8a9 214 foreach ($messages as $id=>&$message) {
215 if (!isset($this->overview[$id])) {
216 $this->overview[$id] = new BananaSpoolHead($message);
78cd27b3 217 }
ab02e8a9 218 $msg =& $this->overview[$id];
219 $msgrefs = BananaMessage::formatReferences($message);
220 $parents = preg_grep('/^\d+$/', $msgrefs);
221 $msg->parent = array_pop($parents);
222 $msg->parent_direct = preg_match('/^\d+$/', array_pop($msgrefs));
78cd27b3 223
ab02e8a9 224 if (!is_null($p = $msg->parent)) {
78cd27b3 225 if (empty($this->overview[$p])) {
ab02e8a9 226 $this->overview[$p] = new BananaSpoolHead($messages[$p]);
78cd27b3 227 }
228 $this->overview[$p]->children[] = $id;
229
ab02e8a9 230 while (!is_null($p)) {
78cd27b3 231 $this->overview[$p]->desc += $msg->desc;
ab02e8a9 232 if ($p != $this->overview[$p]->parent) {
233 $p = $this->overview[$p]->parent;
234 } else {
235 $p = null;
236 }
78cd27b3 237 }
238 }
239 }
ab02e8a9 240 Banana::$protocole->updateSpool($messages);
241 return true;
78cd27b3 242 }
243
ab02e8a9 244 private function updateUnread($since)
78cd27b3 245 {
ab02e8a9 246 if (empty($since)) {
247 return;
248 }
249
250 $newpostsids = Banana::$protocole->getNewIndexes($since);
4d20320e 251
ab02e8a9 252 if (empty($newpostsids)) {
253 return;
254 }
255
256 if (!is_array($this->ids)) {
257 $this->ids = array();
258 }
259 $newpostsids = array_intersect($newpostsids, array_keys($this->ids));
260 foreach ($newpostsids as $mid) {
261 $id = $this->ids[$mid];
262 if ($this->overview[$id]->isread) {
263 $this->overview[$id]->isread = false;
ab02e8a9 264 while (isset($id)) {
265 $this->overview[$id]->descunread ++;
266 $id = $this->overview[$id]->parent;
78cd27b3 267 }
268 }
ab02e8a9 269 }
270 }
78cd27b3 271
ab02e8a9 272 public function setMode($mode)
273 {
7972645b 274 $this->mode = $mode;
ab02e8a9 275 switch ($mode) {
276 case Banana::SPOOL_UNREAD:
277 foreach ($this->roots as $k=>$i) {
278 if ($this->overview[$i]->descunread == 0) {
279 $this->killdesc($i);
280 unset($this->roots[$k]);
78cd27b3 281 }
282 }
ab02e8a9 283 break;
78cd27b3 284 }
285 }
286
7972645b 287 /** Mark the given id as read
288 * @param id MSGNUM of post
289 */
290 public function markAsRead($id)
291 {
292 if (!$this->overview[$id]->isread) {
293 $this->overview[$id]->isread = true;
294 while (isset($id)) {
295 $this->overview[$id]->descunread--;
296 $id = $this->overview[$id]->parent;
297 }
298 }
299 }
300
301 /** Mark all unread messages as read
302 */
303 public function markAllAsRead(array &$array = null)
304 {
305 if (is_null($array)) {
306 $array =& $this->roots;
307 }
6b46a997 308 if (!is_array($this->roots)) {
309 return;
310 }
7972645b 311 foreach ($array as $id) {
312 if (!$this->overview[$id]->isread) {
313 $this->markAsRead($id);
314 }
315 if ($this->overview[$id]->descunread) {
316 $this->markAllAsRead($this->overview[$id]->children);
317 }
318 }
319 }
320
78cd27b3 321 /** kill post and childrens
322 * @param $_id MSGNUM of post
323 */
ab02e8a9 324 private function killdesc($_id)
78cd27b3 325 {
326 if (sizeof($this->overview[$_id]->children)) {
327 foreach ($this->overview[$_id]->children as $c) {
328 $this->killdesc($c);
329 }
330 }
331 unset($this->overview[$_id]);
332 if (($msgid = array_search($_id, $this->ids)) !== false) {
333 unset($this->ids[$msgid]);
334 }
335 }
336
337 /** delete a post from overview
338 * @param $_id MSGNUM of post
339 */
ab02e8a9 340 public function delid($_id, $write = true)
78cd27b3 341 {
342 if (isset($this->overview[$_id])) {
343 if (sizeof($this->overview[$_id]->parent)) {
344 $this->overview[$this->overview[$_id]->parent]->children =
345 array_diff($this->overview[$this->overview[$_id]->parent]->children, array($_id));
346 if (sizeof($this->overview[$_id]->children)) {
347 $this->overview[$this->overview[$_id]->parent]->children =
348 array_merge($this->overview[$this->overview[$_id]->parent]->children, $this->overview[$_id]->children);
349 foreach ($this->overview[$_id]->children as $c) {
350 $this->overview[$c]->parent = $this->overview[$_id]->parent;
351 $this->overview[$c]->parent_direct = false;
352 }
353 }
354 $p = $this->overview[$_id]->parent;
355 while ($p) {
356 $this->overview[$p]->desc--;
357 $p = $this->overview[$p]->parent;
358 }
359 } elseif (sizeof($this->overview[$_id]->children)) {
360 foreach ($this->overview[$_id]->children as $c) {
361 $this->overview[$c]->parent = null;
362 }
363 }
364 unset($this->overview[$_id]);
365 $msgid = array_search($_id, $this->ids);
b2434350 366 if ($msgid !== false) {
78cd27b3 367 unset($this->ids[$msgid]);
368 }
b2434350 369 $msgid = array_search($_id, $this->roots);
370 if ($msgid !== false) {
371 unset($this->roots[$msgid]);
372 }
78cd27b3 373
ab02e8a9 374 if ($write) {
e0f557df 375 $this->markAllAsRead();
ab02e8a9 376 $this->saveToFile();
377 }
78cd27b3 378 }
379 }
380
ab02e8a9 381 private function formatDate($stamp)
382 {
383 $today = intval(time() / (24*3600));
384 $dday = intval($stamp / (24*3600));
385
386 if ($today == $dday) {
387 $format = "%H:%M";
388 } elseif ($today == 1 + $dday) {
389 $format = _b_('hier')." %H:%M";
390 } elseif ($today < 7 + $dday) {
391 $format = '%a %H:%M';
392 } else {
393 $format = '%a %e %b';
394 }
c4eee982 395 return strftime($format, $stamp);
ab02e8a9 396 }
397
78cd27b3 398 /** displays children tree of a post
399 * @param $_id INTEGER MSGNUM of post
400 * @param $_index INTEGER linear number of post in the tree
401 * @param $_first INTEGER linear number of first post displayed
402 * @param $_last INTEGER linear number of last post displayed
403 * @param $_ref STRING MSGNUM of current post
404 * @param $_pfx_node STRING prefix used for current node
405 * @param $_pfx_end STRING prefix used for children of current node
406 * @param $_head BOOLEAN true if first post in thread
e2347ffc 407 *
d7718cc5 408 * If you want to analyse subject, you can define the function hook_formatDisplayHeader
78cd27b3 409 */
ab02e8a9 410 private function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
78cd27b3 411 {
ab02e8a9 412 static $spfx_f, $spfx_n, $spfx_Tnd, $spfx_Lnd, $spfx_snd, $spfx_T, $spfx_L, $spfx_s, $spfx_e, $spfx_I;
413 if (!isset($spfx_f)) {
414 $spfx_f = Banana::$page->makeImg(Array('img' => 'k1', 'alt' => 'o', 'height' => 21, 'width' => 9));
415 $spfx_n = Banana::$page->makeImg(Array('img' => 'k2', 'alt' => '*', 'height' => 21, 'width' => 9));
416 $spfx_Tnd = Banana::$page->makeImg(Array('img' => 'T-direct', 'alt' => '+', 'height' => 21, 'width' => 12));
417 $spfx_Lnd = Banana::$page->makeImg(Array('img' => 'L-direct', 'alt' => '`', 'height' => 21, 'width' => 12));
418 $spfx_snd = Banana::$page->makeImg(Array('img' => 's-direct', 'alt' => '-', 'height' => 21, 'width' => 5));
419 $spfx_T = Banana::$page->makeImg(Array('img' => 'T', 'alt' => '+', 'height' => 21, 'width' => 12));
420 $spfx_L = Banana::$page->makeImg(Array('img' => 'L', 'alt' => '`', 'height' => 21, 'width' => 12));
421 $spfx_s = Banana::$page->makeImg(Array('img' => 's', 'alt' => '-', 'height' => 21, 'width' => 5));
422 $spfx_e = Banana::$page->makeImg(Array('img' => 'e', 'alt' => '&nbsp;', 'height' => 21, 'width' => 12));
423 $spfx_I = Banana::$page->makeImg(Array('img' => 'I', 'alt' => '|', 'height' => 21, 'width' => 12));
78cd27b3 424 }
425
ab02e8a9 426 $overview =& $this->overview[$_id];
427 if ($_index + $overview->desc < $_first || $_index > $_last) {
428 return '';
429 }
78cd27b3 430
ab02e8a9 431 $res = '';
432 if ($_index >= $_first) {
433 $hc = empty($overview->children);
434
435 $res .= '<tr class="' . ($_index%2 ? 'pair' : 'impair') . ($overview->isread ? '' : ' new') . "\">\n";
436 $res .= '<td class="date">' . $this->formatDate($overview->date) . " </td>\n";
774bb72c 437 $res .= '<td class="subj' . ($_index == $_ref ? ' cur' : '') . '"><div class="tree">'
438 . $_pfx_node .($hc ? ($_head ? $spfx_f : ($overview->parent_direct ? $spfx_s : $spfx_snd)) : $spfx_n)
439 . '</div>';
ab02e8a9 440 $subject = $overview->subject;
d7718cc5 441 if (function_exists('hook_formatDisplayHeader')) {
442 list($subject, $link) = hook_formatDisplayHeader('subject', $subject, true);
443 } else {
dc5684a2 444 $subject = banana_catchFormats(banana_htmlentities(stripslashes($subject)));
d7718cc5 445 $link = null;
446 }
ab02e8a9 447 if (empty($subject)) {
71d6c865 448 $subject = _b_('(pas de sujet)');
449 }
ab02e8a9 450 if ($_index != $_ref) {
451 $subject = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $_id,
452 'text' => $subject, 'popup' => $subject));
78cd27b3 453 }
ab02e8a9 454 $res .= '&nbsp;' . $subject . $link;
455 $res .= "</td>\n<td class='from'>" . BananaMessage::formatFrom($overview->from) . "</td>\n</tr>";
78cd27b3 456
ab02e8a9 457 if ($hc) {
458 return $res;
459 }
78cd27b3 460 }
461
462 $_index ++;
ab02e8a9 463 $children = $overview->children;
78cd27b3 464 while ($child = array_shift($children)) {
ab02e8a9 465 $overview =& $this->overview[$child];
466 if ($_index > $_last) {
467 return $res;
468 }
469 if ($_index + $overview->desc >= $_first) {
78cd27b3 470 if (sizeof($children)) {
471 $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref,
ab02e8a9 472 $_pfx_end . ($overview->parent_direct ? $spfx_T : $spfx_Tnd),
473 $_pfx_end . $spfx_I, false);
78cd27b3 474 } else {
475 $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref,
ab02e8a9 476 $_pfx_end . ($overview->parent_direct ? $spfx_L : $spfx_Lnd),
477 $_pfx_end . $spfx_e, false);
78cd27b3 478 }
479 }
ab02e8a9 480 $_index += $overview->desc;
78cd27b3 481 }
482
483 return $res;
484 }
485
486 /** Displays overview
487 * @param $_first INTEGER MSGNUM of first post
488 * @param $_last INTEGER MSGNUM of last post
489 * @param $_ref STRING MSGNUM of current/selectionned post
490 */
ab02e8a9 491 public function toHtml($first = 0, $overview = false)
78cd27b3 492 {
ab02e8a9 493 $res = '';
494
495 if (!$overview) {
496 $_first = $first;
7972645b 497 $_last = $first + Banana::$spool_tmax - 1;
ab02e8a9 498 $_ref = null;
2ba32e89 499 } else {
ab02e8a9 500 $_ref = $this->getNdx($first);
7972645b 501 $_last = $_ref + Banana::$spool_tafter;
502 $_first = $_ref - Banana::$spool_tbefore;
ab02e8a9 503 if ($_first < 0) {
504 $_last -= $_first;
505 }
78cd27b3 506 }
78cd27b3 507 $index = 1;
ab02e8a9 508 foreach ($this->roots as $id) {
509 $res .= $this->_to_html($id, $index, $_first, $_last, $_ref);
510 $index += $this->overview[$id]->desc ;
511 if ($index > $_last) {
512 break;
78cd27b3 513 }
e230b41a 514 }
ab02e8a9 515 return $res;
78cd27b3 516 }
517
518 /** computes linear post index
519 * @param $_id INTEGER MSGNUM of post
520 * @return INTEGER linear index of post
521 */
ab02e8a9 522 public function getNdX($_id)
78cd27b3 523 {
524 $ndx = 1;
525 $id_cur = $_id;
526 while (true) {
527 $id_parent = $this->overview[$id_cur]->parent;
528 if (is_null($id_parent)) break;
529 $pos = array_search($id_cur, $this->overview[$id_parent]->children);
530
531 for ($i = 0; $i < $pos ; $i++) {
532 $ndx += $this->overview[$this->overview[$id_parent]->children[$i]]->desc;
533 }
774bb72c 534 $ndx++; //noeud père
78cd27b3 535
536 $id_cur = $id_parent;
537 }
538
539 foreach ($this->roots as $i) {
540 if ($i==$id_cur) {
541 break;
542 }
543 $ndx += $this->overview[$i]->desc;
544 }
545 return $ndx;
546 }
2ba32e89 547
548 /** Return root message of the given thread
549 * @param id INTEGER id of a message
550 */
ab02e8a9 551 public function root($id)
552 {
2ba32e89 553 $id_cur = $id;
554 while (true) {
555 $id_parent = $this->overview[$id_cur]->parent;
556 if (is_null($id_parent)) break;
557 $id_cur = $id_parent;
558 }
559 return $id_cur;
560 }
561
562 /** Returns previous thread root index
563 * @param id INTEGER message number
564 */
ab02e8a9 565 public function prevThread($id)
2ba32e89 566 {
567 $root = $this->root($id);
568 $last = null;
569 foreach ($this->roots as $i) {
570 if ($i == $root) {
571 return $last;
572 }
573 $last = $i;
574 }
575 return $last;
576 }
577
578 /** Returns next thread root index
579 * @param id INTEGER message number
580 */
ab02e8a9 581 public function nextThread($id)
2ba32e89 582 {
583 $root = $this->root($id);
584 $ok = false;
585 foreach ($this->roots as $i) {
586 if ($ok) {
587 return $i;
588 }
589 if ($i == $root) {
590 $ok = true;
591 }
592 }
593 return null;
594 }
595
596 /** Return prev post in the thread
597 * @param id INTEGER message number
598 */
ab02e8a9 599 public function prevPost($id)
2ba32e89 600 {
601 $parent = $this->overview[$id]->parent;
602 if (is_null($parent)) {
603 return null;
604 }
605 $last = $parent;
606 foreach ($this->overview[$parent]->children as $child) {
607 if ($child == $id) {
608 return $last;
609 }
610 $last = $child;
611 }
612 return null;
613 }
614
615 /** Return next post in the thread
616 * @param id INTEGER message number
617 */
ab02e8a9 618 public function nextPost($id)
2ba32e89 619 {
620 if (count($this->overview[$id]->children) != 0) {
621 return $this->overview[$id]->children[0];
622 }
623
624 $cur = $id;
625 while (true) {
626 $parent = $this->overview[$cur]->parent;
627 if (is_null($parent)) {
628 return null;
629 }
630 $ok = false;
631 foreach ($this->overview[$parent]->children as $child) {
632 if ($ok) {
633 return $child;
634 }
635 if ($child == $cur) {
636 $ok = true;
637 }
638 }
639 $cur = $parent;
640 }
641 return null;
642 }
dc12019c 643
644 /** Look for an unread message in the thread rooted by the message
645 * @param id INTEGER message number
646 */
ab02e8a9 647 private function _nextUnread($id)
dc12019c 648 {
649 if (!$this->overview[$id]->isread) {
650 return $id;
651 }
652 foreach ($this->overview[$id]->children as $child) {
6aa1f5e4 653 $unread = $this->_nextUnread($child);
654 if (!is_null($unread)) {
655 return $unread;
656 }
dc12019c 657 }
658 return null;
659 }
660
661 /** Find next unread message
662 * @param id INTEGER message number
663 */
ab02e8a9 664 public function nextUnread($id = null)
dc12019c 665 {
27db62eb 666 if (!is_null($id)) {
667 // Look in message children
668 foreach ($this->overview[$id]->children as $child) {
669 $next = $this->_nextUnread($child);
670 if (!is_null($next)) {
671 return $next;
672 }
dc12019c 673 }
674 }
675
676 // Look in current thread
677 $cur = $id;
27db62eb 678 do {
679 $parent = is_null($cur) ? null : $this->overview[$cur]->parent;
680 $ok = is_null($cur) ? true : false;
a02dd64a 681 if (!is_null($parent)) {
dc12019c 682 $array = &$this->overview[$parent]->children;
683 } else {
684 $array = &$this->roots;
685 }
686 foreach ($array as $child) {
687 if ($ok) {
688 $next = $this->_nextUnread($child);
689 if (!is_null($next)) {
690 return $next;
691 }
692 }
693 if ($child == $cur) {
694 $ok = true;
695 }
696 }
697 $cur = $parent;
27db62eb 698 } while(!is_null($cur));
dc12019c 699 return null;
700 }
78cd27b3 701}
702
d8d416c4 703// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
78cd27b3 704?>