post is now in the lib too. have to work on the actions now.
[banana.git] / thread.php
index 026d8e9..488e047 100644 (file)
 * Copyright: See COPYING files that comes with this distribution
 ********************************************************************************/
 
-require("include/session.inc.php");
-require("include/encoding.inc.php");
-require("include/format.inc.php");
-require("include/config.inc.php");
-require("include/NetNNTP.inc.php");
-include("include/post.inc.php");
-require("include/spool.inc.php");
-require("include/password.inc.php");
-require("include/profile.inc.php");
-include("include/wrapper.inc.php");
-
-$profile=getprofile();
-require($profile['locale']);
-
-require("include/header.inc.php");
+require_once("include/banana.inc.php");
+require_once("include/header.inc.php");
 
 if (isset($_REQUEST['group'])) {
-  $group=htmlentities(strtolower($_REQUEST['group']));
+    $group = htmlentities(strtolower($_REQUEST['group']));
 } else {
-  $group=htmlentities(strtolower(strtok(str_replace(" ","",$_REQUEST['newsgroups']),",")));
+    $group = htmlentities(strtolower(strtok(str_replace(" ","",$_REQUEST['newsgroups']),",")));
 }
 
 if (isset($_REQUEST['id'])) {
-  $id=htmlentities(strtolower($_REQUEST['id']));
-}
-
-//$mynntp = new nntp($news['server'],120,1);
-$mynntp = new nntp($news['server']);
-if (!$mynntp) {
-  echo "<p class=\"error\">\n\t".$locale['error']['connect']."\n</p>";
-  require("include/footer.inc.php");
-  exit;
-}
-
-if ($news['user']!="anonymous") {
-  $result = $mynntp->authinfo($news["user"],$news["pass"]);
-  if (!$result) {
-    echo "<p class=\"error\">\n\t".$locale['error']['credentials']
-      ."\n</p>";
-    require("include/footer.inc.php");
-    exit;
-  }
-}
-$spool = new spool($mynntp,$group,$profile['display'],
-  $profile['lastnews']);
-if (!$spool) {
-  echo "<p class=\"error\">\n\t".$locale['error']['group']."\n</p>";
-  require("footer.inc.php");
-  exit;
+    $id=htmlentities(strtolower($_REQUEST['id']));
 }
-$max = 50;
-if (isset($_REQUEST['first']) && ($_REQUEST['first']>sizeof($spool->overview)))
-  $_REQUEST['first']=sizeof($spool->overview);
-$first = (isset($_REQUEST['first'])?
-  (floor($_REQUEST['first']/$max)*$max+1):1);
-$last  = (isset($_REQUEST['first'])?
-  (floor($_REQUEST['first']/$max+1)*$max):$max);
 
-if (isset($_REQUEST['action']) && (isset($_REQUEST['type']))) {
-  switch ($_REQUEST['type']) {  
-    case 'cancel':
-      $mid = array_search($id,$spool->ids);
-      $mynntp->group($group);
-      $post = new post($mynntp,$id);
-      
-      if (checkcancel($post->headers)) {
-        $message = 'From: '.$profile['name']."\n"
-          ."Newsgroups: $group\n"
-          ."Subject: cmsg $mid\n"
-          .$news['customhdr']
-          ."Control: cancel $mid\n"
-          ."\n"
-          ."Message canceled with Banana";
-        $result = $mynntp->post($message);
-        if ($result) {
-          $spool->delid($id);
-          $text="<p class=\"normal\">".$locale['post']['canceled']
-            ."</p>";
-        } else {
-          $text="<p class=\"error\">".$locale['post']['badcancel']
-            ."</p>";
-        }
-      } else {
-        $text="<p class=\"error\">\n\t".$locale['post']['rghtcancel']
-          ."\n</p>";
-      }
-      break;
-    case 'new':
-      $message = 'From: '.$profile['name']."\n"
-        ."Newsgroups: ".stripslashes(str_replace(" ","",
-          $_REQUEST['newsgroups']))."\n"
-        ."Subject: ".stripslashes($_REQUEST['subject'])."\n"
-        .($_REQUEST['followup']!=''?'Followup-To: '
-        .stripslashes($_REQUEST['followup'])."\n":"")
-        .$news['customhdr']
-        ."\n"
-        .wrap(stripslashes($_REQUEST['body']),"",$news['wrap']);
-      $result = $mynntp->post($message);
-      if ($result) {
-        $text="<p class=\"normal\">".$locale['post']['posted']."</p>";
-      } else {
-        $text="<p class=\"error\">".$locale['post']['badpost']."</p>";
-      }
-      break;
-    case 'followupok':
-      $rq=$mynntp->group($group);
-      $post = new post($mynntp,$id);
-      if ($post) {
-        $refs = $post->headers->references." ".$post->headers->msgid;
-      }
-    
-      $message = 'From: '.$profile['name']."\n"
-        ."Newsgroups: ".stripslashes($_REQUEST['newsgroups'])."\n"
-        ."Subject: ".stripslashes($_REQUEST['subject'])."\n"
-        .($_REQUEST['followup']!=''?'Followup-To: '
-        .stripslashes($_REQUEST['followup'])."\n":"")
-        ."References: $refs\n"
-        .$news['customhdr']
-        ."\n"
-        .wrap(stripslashes($_REQUEST['body']),"",$news['wrap']);
-      $result = $mynntp->post($message);
-      if ($result) {
-        $text="<p class=\"normal\">".$locale['post']['posted']."</p>";
-      } else {
-        $text="<p class=\"error\">".$locale['post']['badpost']."</p>";
-      }
-      break;
-  }
-  $spool = new spool($mynntp,$group,$profile['display'],
-    $profile['lastnews']);
-  if (!$spool) {
-    echo "<p class=\"error\">\n\t".$locale['error']['group']."\n</p>";
-    require("include/footer.inc.php");
-    exit;
-  }
-}
+echo $banana->action_showThread($group, $_REQUEST['first'] ? $_REQUEST['first'] : 1);
 
+if (isset($_REQUEST['action']) && (isset($_REQUEST['type']))
+        && (isset($_SESSION['bananapostok'])) && ($_SESSION['bananapostok']))
+{
+    switch ($_REQUEST['type']) {  
+        case 'cancel':
+            $mid  = array_search($id, $banana->spool->ids);
+            $banana->newPost($id);
 
-?>
-<div class="title">
-  <?php echo $locale['thread']['group_b'].$group
-    .$locale['thread']['group_a'];?>
-</div>
-<?php
-if (isset($text)) {
-    echo $text;
-}
-displayshortcuts();
+            if ($banana->post && $banana->post->checkcancel()) {
+                $message = 'From: '.$banana->profile['name']."\n"
+                    ."Newsgroups: $group\n"
+                    ."Subject: cmsg $mid\n"
+                    .$banana->custom
+                    ."Control: cancel $mid\n"
+                    ."\n"
+                    ."Message canceled with Banana";
+                if ($banana->nntp->post($message)) {
+                    $banana->spool->delid($id);
+                    $text = "<p class=\"normal\">"._b_('Message annulé')."</p>";
+                } else {
+                    $text = "<p class=\"error\">"._b_('Impossible d\'annuler le message')."</p>";
+                }
+            } else {
+                $text = "<p class=\"error\">\n\t"._b_('Vous n\'avez pas les permissions pour annuler ce message')."\n</p>";
+            }
+            break;
 
-?>
+        case 'new':
+            $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",$_REQUEST['body']);
+            $message = 'From: '.$banana->profile['name']."\n"
+                ."Newsgroups: ".str_replace(" ","", $_REQUEST['newsgroups'])."\n"
+                ."Subject: ".$_REQUEST['subject']."\n"
+                .(isset($banana->profile['org'])?"Organization: ".$banana->profile['org']."\n":"")
+                .($_REQUEST['followup']!=''?'Followup-To: '.$_REQUEST['followup']."\n":"")
+                .$banana->custom
+                ."\n"
+                .wrap($body, "", $banana->wrap);
+            if ($banana->nntp->post($message)) {
+                $text = "<p class=\"normal\">"._b_('Message posté')."</p>";
+            } else {
+                $text = "<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
+            }
+            break;
 
-<table class="bicol" cellpadding="0" cellspacing="0" border="0" 
-  summary="<?php echo $locale['thread']['summary'];?>">
-  <tr>
-    <th class="date">
-      <?php echo $locale['thread']['date'];?>
-    </th>
-    <th class="subject">
-      <?php echo $locale['thread']['subject'];?>
-    </th>
-    <th class="from">
-      <?php echo $locale['thread']['author'];?>
-    </th>
-  </tr>
-<?php
-$spool->disp($first,$last);
-$mynntp->quit();
-echo "</table>";
+        case 'followupok':
+            $banana->newPost($id);
+            if ($banana->post) {
+                $refs = (isset($banana->post->headers['references'])?
+                $banana->post->headers['references']." ":"").$banana->post->headers['message-id'];
+            }
 
-displayshortcuts();
+            $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",$_REQUEST['body']);
+            $message = 'From: '.$banana->profile['name']."\n"
+                ."Newsgroups: ".$_REQUEST['newsgroups']."\n"
+                ."Subject: ".$_REQUEST['subject']."\n"
+                .(isset($banana->profile['org'])?"Organization: ".$banana->profile['org']."\n":"")
+                .($_REQUEST['followup']!=''?'Followup-To: '.$_REQUEST['followup']."\n":"")
+                ."References: $refs\n"
+                .$banana->custom
+                .$banana->profile['customhdr']
+                ."\n"
+                .wrap($body, "", $banana->wrap);
+            if ($banana->nntp->post($message)) {
+                $text = "<p class=\"normal\">"._b_('Message posté')."</p>";
+            } else {
+                $text = "<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
+            }
+            break;
+    }
+    $_SESSION['bananapostok']=false;
+    $banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']);
+}
 
-require("include/footer.inc.php");
+require_once("include/footer.inc.php");
 ?>