From 65d96b1fce71f9373df12b627b28af9f9e6446f5 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Tue, 4 Jan 2005 16:43:49 +0000 Subject: [PATCH] prepare banana to be a library --- article.php | 64 +--------------------- css/style.css | 137 ++++++------------------------------------------ include/NetNNTP.inc.php | 9 ++-- include/groups.inc.php | 63 ++++++++++++++++++---- include/misc.inc.php | 39 +++++++++----- include/post.inc.php | 28 +++++++++- include/spool.inc.php | 51 ++++++++++-------- index.php | 104 +----------------------------------- thread.php | 35 +------------ 9 files changed, 158 insertions(+), 372 deletions(-) diff --git a/article.php b/article.php index ff4c8dd..ed10a48 100644 --- a/article.php +++ b/article.php @@ -17,21 +17,8 @@ if (isset($_REQUEST['id'])) { $id = htmlentities(strtolower($_REQUEST['id'])); } -$banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); -$banana->newPost($id); -if (!$banana->post) { - if ($banana->nntp->lasterrorcode == "423") { - $banana->spool->delid($id); - } - error("nntpart"); -} - -$ndx = $banana->spool->getndx($id); - -?> -

+echo $banana->action_showArticle($group, $id); -post->checkcancel()) { ?>

@@ -46,54 +33,5 @@ if (isset($_GET['type']) && $_GET['type']=='cancel' && $banana->post->checkcance - - - - - -show_hdr as $hdr) { - if (isset($banana->post->headers[$hdr])) { - $res = formatdisplayheader($hdr, $banana->post->headers[$hdr]); - if ($res) - echo "" - ."\n"; - } - } -?> - - - - - - - - - - - - -
- -
".header_translate($hdr)."$res
- -
-
post->body); ?>
-
- -
- -spool->disp($ndx-$banana->tbefore,$ndx+$banana->tafter,$ndx); -?> -
-
- diff --git a/css/style.css b/css/style.css index 19caebe..0b698c9 100644 --- a/css/style.css +++ b/css/style.css @@ -6,133 +6,30 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -body { - color: black; - background-color: white; - width: 800px; - margin-left: auto; - margin-right: auto; -} +div.banana_scuts { text-align: left; padding: 0.5em 0em; } -a:link { color: blue; background: inherit; } -a:visited { color: blue; background: inherit; } -a:hover { color: blue; background: inherit; text-decoration: underline; } +/** GROUP LIST **/ -h1 { - font-size: 200%; - text-align: center; - padding-bottom: 1em; -} +table.banana_group td.new { text-align: center; } +table.banana_group td.all { text-align: center; } +table.banana_group td.grp { text-align: left; } +table.banana_group td.dsc { text-align: left; } -div.bloc { - width: 100%; -} +/** THREAD VIEW **/ -p.footer { - border-top: 1px #DDDDDD solid; -} +table.banana_thread td { white-space: nowrap; height: 100%; vertical-align: middle; } -div.shortcuts { - text-align: left; - padding-bottom: 1em; - padding-top: 1em; -} +table.banana_thread tr.new { font-weight: bold; } -div.tree { - float: left; - padding-right: 0.3em; -} +table.banana_thread td.date { text-align: center; } +table.banana_thread td.subj { text-align: left; overflow: hidden; } +table.banana_thread td.from { text-align: left; } -span.isref { - font-style: italic; -} +table.banana_thread div.tree { float: left; padding-right: 0.3em; } +table.banana_thread span.cur { font-style: italic; font-size: 90%; } -table.bicol { - background-color: #eeeeee; - color: inherit; - border: 1px solid #336699; - border-collapse: collapse; - width: 100%; -} +/** MESSAGE VIEW **/ -table.bicol tr.impair {} - -table.bicol tr.pair { - background-color: #eeeed0; - color: inherit; -} - -table.bicol th { - background-color: #336699; - color: #FFFFFF; - font-weight: bold; - text-align: center; - vertical-align: middle; -} - -table.bicol td { - color: #000000; - background-color: inherit; - padding-left: 0.4em; - padding-right: 0.4em; -} - -table.bicol td.nopadd { - padding-left: 0em; - padding-right: 0em; -} - -table.bicol td.total,td.unread,td.date { - text-align: center; - padding-left: 0.1em; - padding-right: 0.1em; -} - -table.bicol td.subject,td.group,td.from,td.description { - text-align: left; -} - -table.bicol td.bicoltitre,span.bicoltitre { - color: #000000; - background-color: inherit; - font-weight: bold; -} - -table.bicol td.bouton { - text-align: right; -} - -table.overview { - background-color: #eeeeee; - color: inherit; - width: 100%; -} - -table.overview tr.impair {} - -table.overview tr.pair { - background-color: #eeeed0; - color: inherit; -} - -table.overview th { - background-color: #336699; - color: #FFFFFF; - font-weight: bold; - text-align: center; - vertical-align: middle; -} - -table.overview td { - color: #000000; - background-color: inherit; - padding-left: 0.4em; - padding-right: 0.4em; -} - -table.overview td.subject,td.group,td.from,td.description { - text-align: left; -} - -table.overview .new { font-weight: bold; } +table.banana_msg td.thrd { padding: 0px; } +table.banana_msg table { border: 0px; padding: 0px; margin: 0px; width: 100%; } diff --git a/include/NetNNTP.inc.php b/include/NetNNTP.inc.php index 2e8cf0f..c5c62de 100644 --- a/include/NetNNTP.inc.php +++ b/include/NetNNTP.inc.php @@ -58,7 +58,7 @@ class nntp function gline() { - return trim(fgets($this->ns, 1200)); + return rtrim(fgets($this->ns, 1200)); } /** puts a line on server @@ -316,6 +316,7 @@ class nntp $this->pline("LIST\r\n"); if (substr($this->gline(), 0, 1)!="2") return false; $result = $this->gline(); + $array = Array(); while ($result != ".") { preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs); $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4])); @@ -367,10 +368,8 @@ class nntp if (substr($this->gline(), 0, 1)!="2") { return false; } - $result = $this->gline(); - while ($result != ".") { - $array[] = $result; - $result = $this->gline(); + while (($result = $this->gline()) != ".") { + $array[] = $result; } return $array; } diff --git a/include/groups.inc.php b/include/groups.inc.php index f7ab98f..b86e9f0 100644 --- a/include/groups.inc.php +++ b/include/groups.inc.php @@ -10,24 +10,33 @@ /** class for group lists */ +define ( 'BANANA_GROUP_ALL', 0 ); +define ( 'BANANA_GROUP_SUB', 1 ); +define ( 'BANANA_GROUP_NEW', 2 ); + class BananaGroups { /** group list */ - var $overview; + var $overview = Array(); /** last update */ var $date; + var $type; + /** constructor */ - function BananaGroups($_type=0) { + function BananaGroups($_type = BANANA_GROUP_SUB) { global $banana; - $desc = $banana->nntp->xgtitle(); - if ($_type==1) { + + $this->type = $_type; + $desc = $banana->nntp->xgtitle(); + + if ($_type == BANANA_GROUP_NEW) { $list = $banana->nntp->newgroups($banana->profile['lastnews']); } else { $list = $banana->nntp->liste(); - if ($_type == 0) { - $Mylist = Array(); + if ($_type == BANANA_GROUP_SUB) { + $mylist = Array(); foreach ($banana->profile['subscribe'] as $g) { if (isset($list[$g])) { $mylist[$g] = $list[$g]; @@ -36,15 +45,16 @@ class BananaGroups { $list = $mylist; } } - if (empty($list)) { - $this->overview=array(); - return false; - } foreach ($list as $g=>$l) { $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-'; $this->overview[$g][1] = $l[0]; } + ksort($this->overview); + + if (empty($this->overview) && $_type == BANANA_GROUP_SUB) { + $this = new BananaGroups(BANANA_GROUP_ALL); + } } /** updates overview @@ -65,6 +75,39 @@ class BananaGroups { } return true; } + + function to_html() + { + global $banana; + if (empty($this->overview)) { + return; + } + + $html = ''."\n"; + $html .= ''."\n"; + + $b = true; + foreach ($this->overview as $g => $d) { + $b = !$b; + $ginfo = $banana->nntp->group($g); + $new = count($banana->nntp->newnews($banana->profile['lastnews'],$g)); + + $html .= ''."\n"; + $html .= ""; + if ($this->type == BANANA_GROUP_SUB) { + $html .= ''; + } + $html .= ""; + } + + $html .= '
'._b_('Total').''; + if ($this->type == BANANA_GROUP_SUB) { + $html .= _b_('Nouveaux').''; + } + $html .= _b_('Nom').''._b_('Description').'
{$ginfo[0]}'.($new ? $new : '-').'$g{$d[0]}
'; + + return $html; + } } ?> diff --git a/include/misc.inc.php b/include/misc.inc.php index 88bb39e..b20fce5 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -11,6 +11,15 @@ * MISC */ +function mtime() +{ + global $time; + list($usec, $sec) = explode(" ", microtime()); + $time[] = ((float)$usec + (float)$sec); +} + +mtime(); + function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } /******************************************************************************** @@ -141,24 +150,24 @@ function displayshortcuts($first = -1) { global $banana, $css; $sname = basename($_SERVER['SCRIPT_NAME']); - echo "

"; + $res = '
'; if (function_exists('hook_displayshortcuts')) { - hook_displayshortcuts($sname, $first); + $res .= hook_displayshortcuts($sname, $first); } else { - echo '['._b_('Déconnexion').'] '; + $res .= '['._b_('Déconnexion').'] '; } switch ($sname) { case 'thread.php' : - echo '['._b_('Liste des forums').'] '; - echo "[spool->group}\">"._b_('Nouveau message')."] "; + $res .= '['._b_('Liste des forums').'] '; + $res .= "[spool->group}\">"._b_('Nouveau message')."] "; if (sizeof($banana->spool->overview)>$banana->tmax) { for ($ndx=1; $ndx<=sizeof($banana->spool->overview); $ndx += $banana->tmax) { if ($first==$ndx) { - echo "[$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))."] "; + $res .= "[$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))."] "; } else { - echo "[spool->group}&first=" + $res .= "[spool->group}&first=" ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)) ."] "; } @@ -166,21 +175,23 @@ function displayshortcuts($first = -1) { } break; case 'article.php' : - echo '['._b_('Liste des forums').'] '; - echo "[spool->group}\">{$banana->spool->group}] "; - echo "[spool->group}&id={$banana->post->id}&type=followup\">" + $res .= '['._b_('Liste des forums').'] '; + $res .= "[spool->group}\">{$banana->spool->group}] "; + $res .= "[spool->group}&id={$banana->post->id}&type=followup\">" ._b_('Répondre')."] "; if ($banana->post->checkcancel()) { - echo "[spool->group}&id={$banana->post->id}&type=cancel\">" + $res .= "[spool->group}&id={$banana->post->id}&type=cancel\">" ._b_('Annuler ce message')."] "; } break; case 'post.php' : - echo '['._b_('Liste des forums').'] '; - echo "[spool->group}\">{$banana->spool->group}]"; + $res .= '['._b_('Liste des forums').'] '; + $res .= "[spool->group}\">{$banana->spool->group}]"; break; } - echo '
'; + $res .= '
'; + + return $res; } /******************************************************************************** diff --git a/include/post.inc.php b/include/post.inc.php index cfe5ef3..b855a3b 100644 --- a/include/post.inc.php +++ b/include/post.inc.php @@ -80,13 +80,39 @@ class BananaPost $this->name = trim($this->name); } - function checkcancel() { + function checkcancel() + { if (function_exists('hook_checkcancel')) { return hook_checkcancel($this->headers); } return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); } + function to_html() + { + global $banana; + + $res = ''; + $res .= ''; + + foreach ($banana->show_hdr as $hdr) { + if (isset($this->headers[$hdr])) { + $res2 = formatdisplayheader($hdr, $this->headers[$hdr]); + if ($res2) { + $res .= '\n"; + } + } + } + + $res .= ''; + $res .= ''; + + $res .= ''; + $ndx = $banana->spool->getndx($this->id); + $res .= ''; + + return $res.'
'._b_('En-têtes').'
'.header_translate($hdr)."$res2
'._b_('Corps').'
'.formatbody($this->body).'
'._b_('apercu').'
'.$banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx).'
'; + } } ?> diff --git a/include/spool.inc.php b/include/spool.inc.php index fdea6bf..f8e6788 100644 --- a/include/spool.inc.php +++ b/include/spool.inc.php @@ -286,9 +286,8 @@ class BananaSpool * @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) + function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true) { - global $css; $spfx_f = 'o'; $spfx_n = '*'; $spfx_Tnd = '+'; @@ -304,43 +303,46 @@ class BananaSpool return; } + $res = ''; + if ($_index>=$_first) { - $us = ($_index == $_ref); $hc = empty($this->overview[$_id]->children); - echo 'overview[$_id]->isread?'':' new')."\">\n"; - echo "".fancyDate($this->overview[$_id]->date)." \n"; - echo "" - ."
$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n) + $res .= '\n"; + $res .= "".fancyDate($this->overview[$_id]->date)." \n"; + $res .= "" + ."
$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n) ."
"; if ($_index == $_ref) { - echo ''.htmlentities($this->overview[$_id]->subject).''; + $res .= ''.htmlentities($this->overview[$_id]->subject).''; } else { - echo "".htmlentities($this->overview[$_id]->subject).''; + $res .= "".htmlentities($this->overview[$_id]->subject).''; } - echo "\n".formatFrom($this->overview[$_id]->from)."\n"; + $res .= "\n".formatFrom($this->overview[$_id]->from)."\n"; - 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 @@ -349,23 +351,28 @@ class BananaSpool * @param $_ref STRING MSGNUM of current/selectionned post */ - function disp($_first=0, $_last=0, $_ref="") + function to_html($_first=0, $_last=0, $_ref = null) { - global $css; + $res = ''; + + if (is_null($_ref)) { + $res .= ''; + $res .= ''; + $res .= ''; + } + $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 "\n"; - echo "\t\n"; - echo "\n"; + $res .= ''; } + + return $res .= '
'._b_('Date').''._b_('Sujet').''._b_('Auteur').'
\n"; - echo "\t\tNo post in this newsgroup\n"; - echo "\t
'._b_('Aucun message dans ce forum').'
'; } /** computes linear post index diff --git a/index.php b/index.php index 973e4db..0864b0a 100644 --- a/index.php +++ b/index.php @@ -10,109 +10,7 @@ require_once("include/banana.inc.php"); require_once("include/header.inc.php"); -$groups = new BananaGroups(0); -if (!count($groups->overview)) { - $groups = new BananaGroups(2); -} else { - $newgroups = new BananaGroups(1); -} +echo $banana->action_listGroups(); -?> - -

- -

- -overview)) error("nntpgroups"); - -displayshortcuts(); -?> - -" cellspacing="0" cellpadding="2"> - - - - - - -overview as $g => $d) { - $pair = !$pair; - $groupinfo = $banana->nntp->group($g); - $newarts = $banana->nntp->newnews($banana->profile['lastnews'],$g); -?> - " > - - - - - - -
- - - - - - - -
"> - - "> - - "> - $g";?> - "> - -
-overview) and count($banana->profile['subscribe'])) { -?> -

- -

-" cellspacing="0" cellpadding="2"> - - - - - -overview as $g => $d) { - $pair = !$pair; - $groupinfo = $banana->nntp->group($g); -?> - " > - - - - - -
- - - - - -
"> - - "> - $g";?> - "> - -
-nntp->quit(); require_once("include/footer.inc.php"); ?> diff --git a/thread.php b/thread.php index dbae2ef..488e047 100644 --- a/thread.php +++ b/thread.php @@ -20,13 +20,7 @@ if (isset($_REQUEST['id'])) { $id=htmlentities(strtolower($_REQUEST['id'])); } -$banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); -$max = $banana->tmax; -if (isset($_REQUEST['first']) && ($_REQUEST['first']>sizeof($banana->spool->overview))) { - $_REQUEST['first'] = sizeof($banana->spool->overview); -} -$first = (isset($_REQUEST['first']) ? (floor($_REQUEST['first']/$max)*$max+1) : 1); -$last = (isset($_REQUEST['first']) ? (floor($_REQUEST['first']/$max+1)*$max) : $max); +echo $banana->action_showThread($group, $_REQUEST['first'] ? $_REQUEST['first'] : 1); if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) && (isset($_SESSION['bananapostok'])) && ($_SESSION['bananapostok'])) @@ -101,32 +95,5 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) $banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); } -?> -

- - - - - - - - -spool->disp($first, $last); -$banana->nntp->quit(); -echo "
- - - - - -
"; - -displayshortcuts($first); - require_once("include/footer.inc.php"); ?> -- 2.1.4