From b9ea5b300f115e6f9d592eb4f794273ec983f1f3 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Mon, 3 Jan 2005 11:12:51 +0000 Subject: [PATCH] $banana is the only global variable ! --- article.php | 13 ++++++------- include/banana.inc.php.in | 8 +++++++- include/misc.inc.php | 7 ------- include/post.inc.php | 14 +++++++++++--- install.d/format.inc.php | 20 +++++++++++--------- post.php | 10 +++++----- thread.php | 16 ++++++++-------- 7 files changed, 48 insertions(+), 40 deletions(-) diff --git a/article.php b/article.php index bca83a1..4a88f3d 100644 --- a/article.php +++ b/article.php @@ -19,9 +19,8 @@ if (isset($_REQUEST['id'])) { $banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); $banana->nntp->group($group); - -$post = new BananaPost($id); -if (!$post) { +$banana->newPost($id); +if (!$banana->post) { if ($banana->nntp->lasterrorcode == "423") { $banana->spool->delid($id); } @@ -34,7 +33,7 @@ $ndx = $banana->spool->getndx($id);

headers))) { +if (isset($_GET['type']) && $_GET['type']=='cancel' && $banana->post->checkcancel()) { ?>

@@ -60,8 +59,8 @@ summary=""> show_hdr as $hdr) { - if (isset($post->headers[$hdr])) { - $res = formatdisplayheader($hdr, $post->headers[$hdr]); + if (isset($banana->post->headers[$hdr])) { + $res = formatdisplayheader($hdr, $banana->post->headers[$hdr]); if ($res) echo "".header_translate($hdr)."" ."$res\n"; @@ -75,7 +74,7 @@ summary=""> -

body); ?>
+
post->body); ?>
diff --git a/include/banana.inc.php.in b/include/banana.inc.php.in index 4e25e7d..766830c 100644 --- a/include/banana.inc.php.in +++ b/include/banana.inc.php.in @@ -11,7 +11,6 @@ require_once("include/misc.inc.php"); require_once("include/groups.inc.php"); require_once("include/format.inc.php"); require_once("include/error.inc.php"); -require_once("include/post.inc.php"); class Banana { @@ -38,6 +37,7 @@ class Banana var $nntp; var $spool; + var $post; function Banana() { @@ -55,6 +55,12 @@ class Banana if (!$this->spool) { error('nntpspool'); } } + function newPost($id) + { + require_once("include/post.inc.php"); + $this->post = new BananaPost($id); + } + function _setupProfile() { if (function_exists('hook_getprofile')) { diff --git a/include/misc.inc.php b/include/misc.inc.php index abb15dd..4171988 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -13,13 +13,6 @@ function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } -function checkcancel($_headers) { - if (function_exists('hook_checkcancel')) { - return hook_checkcancel($_headers); - } - return ($_headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); -} - /******************************************************************************** * HEADER STUFF */ diff --git a/include/post.inc.php b/include/post.inc.php index c63fcc8..cfe5ef3 100644 --- a/include/post.inc.php +++ b/include/post.inc.php @@ -12,7 +12,7 @@ class BananaPost { - var $nb; + var $id; /** headers */ var $headers; /** body */ @@ -26,7 +26,7 @@ class BananaPost function BananaPost($_id) { global $banana; - $this->nb = $_id; + $this->id = $_id; $this->_header(); $this->body = join("\n", $banana->nntp->body($_id)); @@ -47,7 +47,7 @@ class BananaPost function _header() { global $banana; - $hdrs = $banana->nntp->head($this->nb); + $hdrs = $banana->nntp->head($this->id); if (!$hdrs) { $this = null; return false; @@ -79,6 +79,14 @@ class BananaPost $this->name = preg_replace('/<[^ ]*>/', '', $this->name); $this->name = trim($this->name); } + + function checkcancel() { + if (function_exists('hook_checkcancel')) { + return hook_checkcancel($this->headers); + } + return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); + } + } ?> diff --git a/install.d/format.inc.php b/install.d/format.inc.php index 1991bec..064b7ad 100644 --- a/install.d/format.inc.php +++ b/install.d/format.inc.php @@ -11,8 +11,8 @@ /** contextual links * @return STRING HTML output */ -function displayshortcuts() { - global $banana,$first,$group,$post,$id; +function displayshortcuts($first = -1) { + global $banana; $sname = basename($_SERVER['SCRIPT_NAME']); echo '
'; @@ -21,13 +21,13 @@ function displayshortcuts() { switch ($sname) { case 'thread.php' : echo '['._b_('Liste des forums').'] '; - echo "["._b_('Nouveau message')."] "; + echo "[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))."] "; } else { - echo "[spool->group}&first=" ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)) ."] "; } @@ -36,15 +36,17 @@ function displayshortcuts() { break; case 'article.php' : echo '['._b_('Liste des forums').'] '; - echo "[$group] "; - echo "["._b_('RĂ©pondre')."] "; - if (checkcancel($post->headers)) { - echo "["._b_('Annuler ce message')."] "; + echo "[spool->group}\">{$banana->spool->group}] "; + echo "[spool->group}&id={$banana->post->id}&type=followup\">" + ._b_('RĂ©pondre')."] "; + if ($banana->post->checkcancel()) { + echo "[spool->group}&id={$banana->post->id}&type=cancel\">" + ._b_('Annuler ce message')."] "; } break; case 'post.php' : echo '['._b_('Liste des forums').'] '; - echo "[$group]"; + echo "[spool->group}\">{$banana->spool->group}]"; break; } echo '
'; diff --git a/post.php b/post.php index fc741e7..466b22d 100644 --- a/post.php +++ b/post.php @@ -23,12 +23,12 @@ if (isset($group)) { if (isset($group) && isset($id) && isset($_REQUEST['type']) && ($_REQUEST['type']=='followup')) { $rq = $banana->nntp->group($group); - $post = new BananaPost($id); + $banana->newPost($id); $body = ''; - if ($post) { - $subject = (preg_match("/^re\s*:\s*/i", $post->headers['subject']) ? '' : 'Re: ').$post->headers['subject']; - $body = $post->name." wrote :\n".wrap($post->body, "> "); - $target = isset($post->headers['followup-to']) ? $post->headers['followup-to'] : $post->headers['newsgroups']; + if ($banana->post) { + $subject = (preg_match("/^re\s*:\s*/i", $banana->post->headers['subject']) ? '' : 'Re: ').$banana->post->headers['subject']; + $body = $banana->post->name." wrote :\n".wrap($banana->post->body, "> "); + $target = isset($banana->post->headers['followup-to']) ? $banana->post->headers['followup-to'] : $banana->post->headers['newsgroups']; } } diff --git a/thread.php b/thread.php index 0d52e6a..64b71dc 100644 --- a/thread.php +++ b/thread.php @@ -35,9 +35,9 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) case 'cancel': $banana->nntp->group($group); $mid = array_search($id, $banana->spool->ids); - $post = new BananaPost($id); + $banana->newPost($id); - if (checkcancel($post->headers)) { + if ($banana->post && $banana->post->checkcancel()) { $message = 'From: '.$banana->profile['name']."\n" ."Newsgroups: $group\n" ."Subject: cmsg $mid\n" @@ -75,10 +75,10 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) case 'followupok': $rq=$banana->nntp->group($group); - $post = new BananaPost($id); - if ($post) { - $refs = (isset($post->headers['references'])? - $post->headers['references']." ":"").$post->headers['message-id']; + $banana->newPost($id); + if ($banana->post) { + $refs = (isset($banana->post->headers['references'])? + $banana->post->headers['references']." ":"").$banana->post->headers['message-id']; } $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",$_REQUEST['body']); @@ -107,7 +107,7 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type']))

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