X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=banana%2Fspool.inc.php;h=c938a24b1c25e69f5edcde228759d5077cdc9b7f;hb=d634c13c4ec3b1761622cf3ad558ffe89ba81a0b;hp=9e078f24dd12d64b10c9806d3ceeaa8498e9d8a3;hpb=9090c67309e46afcb82a2f260ce9d3ecd306e38f;p=banana.git diff --git a/banana/spool.inc.php b/banana/spool.inc.php index 9e078f2..c938a24 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -7,7 +7,7 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -if(!function_exists('_file_put_contents')) { +if(!function_exists('file_put_contents')) { function file_put_contents($filename, $data) { $fp = fopen($filename, 'w'); @@ -83,6 +83,8 @@ class BananaSpool var $ids; /** thread starts */ var $roots; + /** test validity */ + var $valid = true; /** constructor * @param $_group STRING group name @@ -94,19 +96,30 @@ class BananaSpool global $banana; $this->group = $_group; $groupinfo = $banana->nntp->group($_group); - if (!$groupinfo) { return ($this = null); } + if (!$groupinfo) { + $this->valid = false; + return null; + } $this->_readFromFile(); $do_save = false; - $first = $banana->maxspool ? max($groupinfo[2]-$banana->maxspool, $groupinfo[1]) : $groupinfo[1]; - $last = $groupinfo[2]; - if ($this->version == BANANA_SPOOL_VERSION) { - for ($id = min(array_keys($this->overview)); $id<$first; $id++) { - $this->delid($id, false); - $do_save = true; + $first = $banana->maxspool ? max($groupinfo[2] - $banana->maxspool, $groupinfo[1]) : $groupinfo[1]; + $last = $groupinfo[2]; + + if ($this->version == BANANA_SPOOL_VERSION && is_array($this->overview)) { + $mids = array_keys($this->overview); + foreach ($mids as $id) { + if (($first <= $last && ($id < $first || $id > $last)) + || ($first > $last && $id < $first && $id > $last)) + { + $this->delid($id, false); + $do_save = true; + } + } + if (!empty($this->overview)) { + $first = max(array_keys($this->overview))+1; } - $first = max(array_keys($this->overview))+1; } else { unset($this->overview, $this->ids); $this->version = BANANA_SPOOL_VERSION; @@ -126,7 +139,10 @@ class BananaSpool { $file = $this->_spoolfile(); if (file_exists($file)) { - $this = unserialize(file_get_contents($file)); + $temp = unserialize(file_get_contents($file)); + foreach (get_object_vars($temp) as $key=>$val) { + $this->$key = $val; + } } } @@ -141,7 +157,7 @@ class BananaSpool $this->roots[] = $id; } } - + file_put_contents($file, serialize($this)); } @@ -156,13 +172,13 @@ class BananaSpool function _updateSpool($arg) { global $banana; - $dates = array_map(strtotime, $banana->nntp->xhdr("Date", $arg)); - $subjects = array_map(headerdecode, $banana->nntp->xhdr("Subject", $arg)); - $froms = array_map(headerdecode, $banana->nntp->xhdr("From", $arg)); - $msgids = $banana->nntp->xhdr("Message-ID", $arg); - $refs = $banana->nntp->xhdr("References", $arg); + $dates = array_map('strtotime', $banana->nntp->xhdr('Date', $arg)); + $subjects = array_map('headerdecode', $banana->nntp->xhdr('Subject', $arg)); + $froms = array_map('headerdecode', $banana->nntp->xhdr('From', $arg)); + $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); @@ -170,7 +186,7 @@ class BananaSpool foreach ($msgids as $id=>$msgid) { $msg = new BananaSpoolHead($dates[$id], $subjects[$id], $froms[$id]); - $refs[$id] = str_replace('><', '> <', $refs[$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); @@ -202,6 +218,7 @@ class BananaSpool if (empty($since)) { return; } if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) { + if (!is_array($this->ids)) { $this->ids = array(); } $newpostsids = array_intersect($newpostsids, array_keys($this->ids)); foreach ($newpostsids as $mid) { $this->overview[$this->ids[$mid]]->isread = false; @@ -292,20 +309,24 @@ class BananaSpool * @param $_pfx_node STRING prefix used for current node * @param $_pfx_end STRING prefix used for children of current node * @param $_head BOOLEAN true if first post in thread + * + * If you want to analyse subject, you can define the function hook_getSubject(&$subject) which + * take the subject as a reference parameter, transform this subject to be displaid in the spool + * view and return a string. This string will be put after the subject. */ function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true) { - $spfx_f = 'o'; - $spfx_n = '*'; - $spfx_Tnd = '+'; - $spfx_Lnd = '`'; - $spfx_snd = '-'; - $spfx_T = '+'; - $spfx_L = '`'; - $spfx_s = '-'; - $spfx_e = ' '; - $spfx_I = '|'; + $spfx_f = makeImg('k1.gif', 'o', 21, 9); + $spfx_n = makeImg('k2.gif', '*', 21, 9); + $spfx_Tnd = makeImg('T-direct.gif', '+', 21, 12); + $spfx_Lnd = makeImg('L-direct.gif', '`', 21, 12); + $spfx_snd = makeImg('s-direct.gif', '-', 21, 5); + $spfx_T = makeImg('T.gif', '+', 21, 12); + $spfx_L = makeImg('L.gif', '`', 21, 12); + $spfx_s = makeImg('s.gif', '-', 21, 5); + $spfx_e = makeImg('e.gif', ' ', 21, 12); + $spfx_I = makeImg('I.gif', '|', 21, 12); if ($_index + $this->overview[$_id]->desc < $_first || $_index > $_last) { return; @@ -321,10 +342,23 @@ class BananaSpool $res .= "" ."
$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n) ."
"; + $subject = $this->overview[$_id]->subject; + if (strlen($subject) == 0) { + $subject = _b_('(pas de sujet)'); + } + $link = null; + if (function_exists('hook_getSubject')) { + $link = hook_getSubject($subject); + } + $subject = formatPlainText(htmlentities($subject)); if ($_index == $_ref) { - $res .= ''.htmlentities($this->overview[$_id]->subject).''; + $res .= '' . $subject . $link . ''; } else { - $res .= "".htmlentities($this->overview[$_id]->subject).''; + $res .= makeHREF(Array('group' => $this->group, + 'artid' => $_id), + $subject, + $subject) + . $link; } $res .= "\n".formatFrom($this->overview[$_id]->from)."\n"; @@ -363,10 +397,22 @@ class BananaSpool { $res = ''; + $new = '
' + . makeImgLink(Array('group' => $this->group, + 'action' => 'new'), + 'post.gif', + _b_('Nouveau message')); + $new .= '
'; + if (is_null($_ref)) { - $res .= ''; - $res .= ''; - $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + } else { + $res .= ''; } $index = 1; @@ -380,6 +426,12 @@ class BananaSpool $res .= ''; } + global $banana; + if (is_object($banana->groups)) { + $res .= ''; + } return $res .= '
'._b_('Date').''._b_('Sujet').''._b_('Auteur').'
' . _b_('Date') . '' . $new . _b_('Sujet') . '' . _b_('Auteur') . '
' . _b_('Aperçu de ') + . makeHREF(Array('group' => $this->group), + $this->group) + . '
'._b_('Aucun message dans ce forum').'
' + . $banana->groups->to_html() + . '
'; } @@ -413,6 +465,156 @@ class BananaSpool } return $ndx; } + + /** Return root message of the given thread + * @param id INTEGER id of a message + */ + function root($id) + { + $id_cur = $id; + while (true) { + $id_parent = $this->overview[$id_cur]->parent; + if (is_null($id_parent)) break; + $id_cur = $id_parent; + } + return $id_cur; + } + + /** Returns previous thread root index + * @param id INTEGER message number + */ + function prevThread($id) + { + $root = $this->root($id); + $last = null; + foreach ($this->roots as $i) { + if ($i == $root) { + return $last; + } + $last = $i; + } + return $last; + } + + /** Returns next thread root index + * @param id INTEGER message number + */ + function nextThread($id) + { + $root = $this->root($id); + $ok = false; + foreach ($this->roots as $i) { + if ($ok) { + return $i; + } + if ($i == $root) { + $ok = true; + } + } + return null; + } + + /** Return prev post in the thread + * @param id INTEGER message number + */ + function prevPost($id) + { + $parent = $this->overview[$id]->parent; + if (is_null($parent)) { + return null; + } + $last = $parent; + foreach ($this->overview[$parent]->children as $child) { + if ($child == $id) { + return $last; + } + $last = $child; + } + return null; + } + + /** Return next post in the thread + * @param id INTEGER message number + */ + function nextPost($id) + { + if (count($this->overview[$id]->children) != 0) { + return $this->overview[$id]->children[0]; + } + + $cur = $id; + while (true) { + $parent = $this->overview[$cur]->parent; + if (is_null($parent)) { + return null; + } + $ok = false; + foreach ($this->overview[$parent]->children as $child) { + if ($ok) { + return $child; + } + if ($child == $cur) { + $ok = true; + } + } + $cur = $parent; + } + 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) { + return $this->_nextUnread($child); + } + return null; + } + + /** Find next unread message + * @param id INTEGER message number + */ + function nextUnread($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; + while (true) { + $parent = $this->overview[$cur]->parent; + $ok = 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; + } + return null; + } } +// vim:set et sw=4 sts=4 ts=4 ?>