********************************************************************************/
if(!function_exists('_file_put_contents')) {
- function file_put_contents($filename, $data) {
+ function file_put_contents($filename, $data)
+ {
$fp = fopen($filename, 'w');
if(!$fp) {
trigger_error('file_put_contents cannot write in file '.$filename, E_USER_ERROR);
}
}
+function spoolCompare($a,$b) { return ($b->date>=$a->date); }
+
/** Class spoolhead
* class used in thread overviews
*/
-class SpoolHead
+class BananaSpoolHead
{
/** date (timestamp) */
var $date;
* @param $_descunread INTEGER descunread value (0 for a new post)
*/
- function SpoolHead($_date, $_subject, $_from, $_desc=1, $_read=true, $_descunread=0)
+ function BananaSpoolHead($_date, $_subject, $_from, $_desc=1, $_read=true, $_descunread=0)
{
$this->date = $_date;
$this->subject = $_subject;
define("BANANA_SPOOL_VERSION", '0.2');
-class spool
+class BananaSpool
{
var $version;
/** spool */
var $roots;
/** constructor
- * @param $_nntp RESOURCE NNTP socket filehandle
* @param $_group STRING group name
* @param $_display INTEGER 1 => all posts, 2 => only threads with new posts
* @param $_since INTEGER time stamp (used for read/unread)
*/
- function spool(&$_nntp, $_group, $_display=0, $_since="")
+ function BananaSpool($_group, $_display=0, $_since="")
{
- global $news;
+ global $banana;
$this->group = $_group;
- $groupinfo = $_nntp->group($_group);
+ $groupinfo = $banana->nntp->group($_group);
if (!$groupinfo) { return ($this = null); }
$this->_readFromFile();
$do_save = false;
- $first = max($groupinfo[2]-$news['maxspool'], $groupinfo[1]);
+ $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->version = BANANA_SPOOL_VERSION;
}
- if ($first<$last && $groupinfo[0]) {
+ if ($first<=$last && $groupinfo[0]) {
$do_save = true;
- $this->_updateSpool($_nntp, "$first-$last");
+ $this->_updateSpool("$first-$last");
}
if ($do_save) { $this->_saveToFile(); }
- $this->_updateUnread($_nntp, $_since, $_display);
+ $this->_updateUnread($_since, $_display);
}
function _readFromFile()
file_put_contents($file, serialize($this));
}
- function _updateSpool(&$_nntp, $arg)
+ function _updateSpool($arg)
{
- $dates = array_map(strtotime, $_nntp->xhdr("Date", $arg));
- $subjects = array_map(headerdecode, $_nntp->xhdr("Subject", $arg));
- $froms = array_map(headerdecode, $_nntp->xhdr("From", $arg));
- $msgids = $_nntp->xhdr("Message-ID", $arg);
- $refs = $_nntp->xhdr("References", $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);
if (is_array($this->ids)) {
$this->ids = array_merge($this->ids, array_flip($msgids));
}
foreach ($msgids as $id=>$msgid) {
- $msg = new spoolhead($dates[$id], $subjects[$id], $froms[$id]);
+ $msg = new BananaSpoolHead($dates[$id], $subjects[$id], $froms[$id]);
$refs[$id] = str_replace('><', '> <', $refs[$id]);
$msgrefs = preg_split("/[ \t]/", strtr($refs[$id], $this->ids));
$parents = preg_grep('/^\d+$/', $msgrefs);
if ($p = $msg->parent) {
if (empty($this->overview[$p])) {
- $this->overview[$p] = new spoolhead($dates[$p], $subjects[$p], $froms[$p], 1);
+ $this->overview[$p] = new BananaSpoolHead($dates[$p], $subjects[$p], $froms[$p], 1);
}
$this->overview[$p]->children[] = $id;
}
}
- function _updateUnread(&$nntp, $since, $mode) {
+ function _updateUnread($since, $mode)
+ {
+ global $banana;
if (empty($since)) { return; }
- if (is_array($newpostsids = $nntp->newnews($since, $this->group))) {
+ if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) {
$newpostsids = array_intersect($newpostsids, array_keys($this->ids));
foreach ($newpostsids as $mid) {
$this->overview[$this->ids[$mid]]->isread = false;
* @param $_head BOOLEAN true if first post in thread
*/
- function _disp_desc($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true) {
- global $css;
+ function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
+ {
$spfx_f = '<img src="img/k1.gif" height="21" width="9" alt="o" />';
$spfx_n = '<img src="img/k2.gif" height="21" width="9" alt="*" />';
$spfx_Tnd = '<img src="img/T-direct.gif" height="21" width="12" alt="+" />';
return;
}
+ $res = '';
+
if ($_index>=$_first) {
- $us = ($_index == $_ref);
$hc = empty($this->overview[$_id]->children);
- echo '<tr class="'.($_index%2?$css["pair"]:$css["impair"]).($this->overview[$_id]->isread?'':' new')."\">\n";
- echo "<td class=\"{$css['date']}\">".locale_header_date($this->overview[$_id]->date)." </td>\n";
- echo "<td class=\"{$css['subject']}\">"
- ."<div class=\"{$css['tree']}\">$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n)
+ $res .= '<tr class="'.($_index%2?'pair':'impair').($this->overview[$_id]->isread?'':' new')."\">\n";
+ $res .= "<td class='date'>".fancyDate($this->overview[$_id]->date)." </td>\n";
+ $res .= "<td class='subj'>"
+ ."<div class='tree'>$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n)
."</div>";
if ($_index == $_ref) {
- echo '<span class="isref">'.htmlentities($this->overview[$_id]->subject).'</span>';
+ $res .= '<span class="cur">'.htmlentities($this->overview[$_id]->subject).'</span>';
} else {
- echo "<a href='article.php?group={$this->group}&id=$_id'>".htmlentities($this->overview[$_id]->subject).'</a>';
+ $res .= "<a href='?group={$this->group}&artid=$_id'>".htmlentities($this->overview[$_id]->subject).'</a>';
}
- echo "</td>\n<td class=\"{$css['author']}\">".formatFrom($this->overview[$_id]->from)."</td>\n</tr>";
+ $res .= "</td>\n<td class='from'>".formatFrom($this->overview[$_id]->from)."</td>\n</tr>";
- if ($hc) { return; }
+ if ($hc) { return $res; }
}
$_index ++;
$children = $this->overview[$_id]->children;
while ($child = array_shift($children)) {
- if ($_index > $_last) { return; }
+ if ($_index > $_last) { return $res; }
if ($_index+$this->overview[$child]->desc >= $_first) {
if (sizeof($children)) {
- $this->_disp_desc($child, $_index, $_first, $_last, $_ref,
+ $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref,
$_pfx_end.($this->overview[$child]->parent_direct?$spfx_T:$spfx_Tnd),
$_pfx_end.$spfx_I, false);
} else {
- $this->_disp_desc($child, $_index, $_first, $_last, $_ref,
+ $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref,
$_pfx_end.($this->overview[$child]->parent_direct?$spfx_L:$spfx_Lnd),
$_pfx_end.$spfx_e, false);
}
}
$_index += $this->overview[$child]->desc;
}
+
+ return $res;
}
/** Displays overview
* @param $_ref STRING MSGNUM of current/selectionned post
*/
- function disp($_first=0, $_last=0, $_ref="") {
- global $css;
+ function to_html($_first=0, $_last=0, $_ref = null)
+ {
+ $res = '<table class="bicol banana_thread" cellpadding="0" cellspacing="0">';
+
+ if (is_null($_ref)) {
+ $res .= '<tr><th>'._b_('Date').'</th>';
+ $res .= '<th>'._b_('Sujet').'</th>';
+ $res .= '<th>'._b_('Auteur').'</th></tr>';
+ }
+
$index = 1;
if (sizeof($this->overview)) {
foreach ($this->roots as $id) {
- $this->_disp_desc($id, $index, $_first, $_last, $_ref);
+ $res .= $this->_to_html($id, $index, $_first, $_last, $_ref);
$index += $this->overview[$id]->desc ;
if ($index > $_last) { break; }
}
} else {
- echo "<tr class=\"{$css['pair']}\">\n";
- echo "\t<td colspan=\"3\">\n";
- echo "\t\tNo post in this newsgroup\n";
- echo "\t</td>\n";
- echo "</tr>\n";
+ $res .= '<tr><td colspan="3">'._b_('Aucun message dans ce forum').'</td></tr>';
}
+
+ return $res .= '</table>';
}
/** computes linear post index
* @return INTEGER linear index of post
*/
- function getndx($_id) {
+ function getndx($_id)
+ {
$ndx = 1;
$id_cur = $_id;
while (true) {