$banana is the only global variable !
authorx2000habouzit <x2000habouzit>
Mon, 3 Jan 2005 11:12:51 +0000 (11:12 +0000)
committerx2000habouzit <x2000habouzit>
Mon, 3 Jan 2005 11:12:51 +0000 (11:12 +0000)
article.php
include/banana.inc.php.in
include/misc.inc.php
include/post.inc.php
install.d/format.inc.php
post.php
thread.php

index bca83a1..4a88f3d 100644 (file)
@@ -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);
 <h1><?php echo _b_('Message'); ?></h1>
 
 <?php
-if (isset($_GET['type']) && ($_GET['type']=='cancel') && (checkcancel($post->headers))) {
+if (isset($_GET['type']) && $_GET['type']=='cancel' && $banana->post->checkcancel()) {
 ?>
 <p class="<?php echo $css['error']?>">
   <?php echo _b_('Voulez-vous vraiment annuler ce message ?'); ?>
@@ -60,8 +59,8 @@ summary="<?php echo _b_('Contenu du message'); ?>">
   </tr>
 <?php
     foreach ($banana->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 "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($hdr)."</td>"
                     ."<td>$res</td></tr>\n";
@@ -75,7 +74,7 @@ summary="<?php echo _b_('Contenu du message'); ?>">
   </tr> 
   <tr>
     <td colspan="2">
-      <pre><?php echo formatbody($post->body); ?></pre>
+      <pre><?php echo formatbody($banana->post->body); ?></pre>
     </td>
   </tr>
   <tr>
index 4e25e7d..766830c 100644 (file)
@@ -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')) {
index abb15dd..4171988 100644 (file)
 
 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
  */
index c63fcc8..cfe5ef3 100644 (file)
@@ -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'].">");
+    }
+
 }
 
 ?>
index 1991bec..064b7ad 100644 (file)
@@ -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 '<div class="shortcuts">';
@@ -21,13 +21,13 @@ function displayshortcuts() {
     switch ($sname) {
         case 'thread.php' :
             echo '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
-            echo "[<a href=\"post.php?group=$group\">"._b_('Nouveau message')."</a>] ";
+            echo "[<a href=\"post.php?group={$banana->spool->group}\">"._b_('Nouveau message')."</a>] ";
             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 "[<a href=\"".$_SERVER['PHP_SELF']."?group=$group&amp;first="
+                        echo "[<a href=\"".$_SERVER['PHP_SELF']."?group={$banana->spool->group}&amp;first="
                             ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))
                             ."</a>] ";
                     }
@@ -36,15 +36,17 @@ function displayshortcuts() {
             break;
         case 'article.php' :
             echo '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
-            echo "[<a href=\"thread.php?group=$group\">$group</a>] ";
-            echo "[<a href=\"post.php?group=$group&amp;id=$id&amp;type=followup\">"._b_('RĂ©pondre')."</a>] ";
-            if (checkcancel($post->headers)) {
-                echo "[<a href=\"article.php?group=$group&amp;id=$id&amp;type=cancel\">"._b_('Annuler ce message')."</a>] ";
+            echo "[<a href=\"thread.php?group={$banana->spool->group}\">{$banana->spool->group}</a>] ";
+            echo "[<a href=\"post.php?group={$banana->spool->group}&amp;id={$banana->post->id}&amp;type=followup\">"
+                ._b_('RĂ©pondre')."</a>] ";
+            if ($banana->post->checkcancel()) {
+                echo "[<a href=\"article.php?group={$banana->spool->group}&amp;id={$banana->post->id}&amp;type=cancel\">"
+                    ._b_('Annuler ce message')."</a>] ";
             }
             break;
         case 'post.php' :
             echo '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
-            echo "[<a href=\"thread.php?group=$group\">$group</a>]";
+            echo "[<a href=\"thread.php?group={$banana->spool->group}\">{$banana->spool->group}</a>]";
             break;
     }
     echo '</div>';
index fc741e7..466b22d 100644 (file)
--- 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'];
     }
 }
 
index 0d52e6a..64b71dc 100644 (file)
@@ -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']))
 <h1><?php echo $group; ?></h1>
 <?php
 if (isset($text)) { echo $text; }
-displayshortcuts();
+displayshortcuts($first);
 
 ?>
 
@@ -128,7 +128,7 @@ $banana->spool->disp($first, $last);
 $banana->nntp->quit();
 echo "</table>";
 
-displayshortcuts();
+displayshortcuts($first);
 
 require_once("include/footer.inc.php");
 ?>