X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fspool.inc.php;h=de4e598b57657e2afb636739f48c7417695cb37e;hb=35d5fc0bfc2ff6cbb71d3dddf58cd0408042199d;hp=b2e04f618135f6cf911377f79a42607ac5d7e5e8;hpb=77eba74567ab9448b73b05d63a1a2a08a5ccd00d;p=banana.git diff --git a/banana/spool.inc.php b/banana/spool.inc.php index b2e04f6..de4e598 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -178,7 +178,7 @@ class BananaSpool $msgids = $banana->nntp->xhdr('Message-ID', $arg); $refs = $banana->nntp->xhdr('References', $arg); - if (is_array($this->ids)) { + if (is_array(@$this->ids)) { $this->ids = array_merge($this->ids, array_flip($msgids)); } else { $this->ids = array_flip($msgids); @@ -186,16 +186,11 @@ class BananaSpool foreach ($msgids as $id=>$msgid) { $msg = new BananaSpoolHead($dates[$id], $subjects[$id], $froms[$id]); - if (isset($ref[$id])) { - $refs[$id] = str_replace('><', '> <', $refs[$id]); - $msgrefs = preg_split("/[ \t]/", strtr($refs[$id], $this->ids)); - $parents = preg_grep('/^\d+$/', $msgrefs); - $msg->parent = array_pop($parents); - $msg->parent_direct = preg_match('/^\d+$/', array_pop($msgrefs)); - } else { - $msg->parent = null; - $msg->parent_direct = null; - } + $refs[$id] = str_replace('><', '> <', @$refs[$id]); + $msgrefs = preg_split("/[ \t]/", strtr($refs[$id], $this->ids)); + $parents = preg_grep('/^\d+$/', $msgrefs); + $msg->parent = array_pop($parents); + $msg->parent_direct = preg_match('/^\d+$/', array_pop($msgrefs)); if (isset($this->overview[$id])) { $msg->desc = $this->overview[$id]->desc; @@ -402,17 +397,26 @@ class BananaSpool { $res = ''; - $new = '
' - . makeImgLink(Array('group' => $this->group, - 'action' => 'new'), - 'post.gif', - _b_('Nouveau message')); - $new .= '
'; - if (is_null($_ref)) { - $res .= ''; - $res .= ''; - $res .= ''; + $next = $this->nextUnread(); + if (!is_null($next)) { + $next = '
' + . makeImgLink(Array('group' => $this->group, + 'artid' => $next), + 'next_unread.gif', + _b_('Message non-lu suivant'), null, null, null, 'u') + . '
'; + } + $new = '
' + . makeImgLink(Array('group' => $this->group, + 'action' => 'new'), + 'post.gif', + _b_('Nouveau message'), null, null, null, 'p') + . '
'; + + $res .= ''; + $res .= ''; + $res .= ''; } else { $res .= '
' . _b_('Date') . '' . $new . _b_('Sujet') . '' . _b_('Auteur') . '
' . $next . _b_('Date') . '' . _b_('Sujet') . '' . $new . _b_('Auteur') . '
' . _b_('Aperçu de ') . makeHREF(Array('group' => $this->group), @@ -566,6 +570,64 @@ class BananaSpool } return null; } + + /** Look for an unread message in the thread rooted by the message + * @param id INTEGER message number + */ + function _nextUnread($id) + { + if (!$this->overview[$id]->isread) { + return $id; + } + foreach ($this->overview[$id]->children as $child) { + $unread = $this->_nextUnread($child); + if (!is_null($unread)) { + return $unread; + } + } + return null; + } + + /** Find next unread message + * @param id INTEGER message number + */ + function nextUnread($id = null) + { + if (!is_null($id)) { + // Look in message children + foreach ($this->overview[$id]->children as $child) { + $next = $this->_nextUnread($child); + if (!is_null($next)) { + return $next; + } + } + } + + // Look in current thread + $cur = $id; + do { + $parent = is_null($cur) ? null : $this->overview[$cur]->parent; + $ok = is_null($cur) ? true : false; + if (!is_null($parent)) { + $array = &$this->overview[$parent]->children; + } else { + $array = &$this->roots; + } + foreach ($array as $child) { + if ($ok) { + $next = $this->_nextUnread($child); + if (!is_null($next)) { + return $next; + } + } + if ($child == $cur) { + $ok = true; + } + } + $cur = $parent; + } while(!is_null($cur)); + return null; + } } // vim:set et sw=4 sts=4 ts=4