From: x2003bruneau Date: Wed, 7 Mar 2007 16:14:44 +0000 (+0000) Subject: New function Banana::post() X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=2d0315d8948398e57d125d1e8b6c9f35869c32cd;p=banana.git New function Banana::post() git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@222 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index ca17a13..d33c8ea 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -298,6 +298,27 @@ class Banana return Banana::$page->run(); } + /** Build and post a new message + * @return postid (or -1 if the message has not been found) + */ + public function post($dest, $reply, $subject, $body) + { + $hdrs = Banana::$protocole->requestedHeaders(); + $headers = Banana::$profile['headers']; + $headers[$hdrs['dest']] = $dest; + if ($reply) { + $headers[$hdrs['reply']] = $reply; + } + $headers['Subject'] = $subject; + $msg = BananaMessage::newMessage($headers, $body); + if (Banana::$protocole->send($msg)) { + Banana::$group = ($reply ? $reply : $dest); + $this->loadSpool(Banana::$group); + return Banana::$spool->getPostId($subject); + } + return -1; + } + /** Return the CSS code to include in the headers */ public function css() @@ -466,6 +487,9 @@ class Banana $hdr_values = array(); foreach ($hdrs as $header) { $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header]; + if ($headers != 'Subject') { + $hdr_values[$header] = str_replace(', ', ',', $hdr_values[$header]); + } } if ($artid) { $old =& $this->loadMessage($group, $artid); @@ -486,7 +510,8 @@ class Banana } if (!is_null($msg)) { if (Banana::$protocole->send($msg)) { - Banana::$page->redirect(array('group' => $group, 'artid' => $artid)); + $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']); + Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid)); } Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '
' . Banana::$protocole->lastError()); diff --git a/banana/message.func.inc.php b/banana/message.func.inc.php index de29b94..863ed3a 100644 --- a/banana/message.func.inc.php +++ b/banana/message.func.inc.php @@ -72,7 +72,7 @@ function banana_unflowed($text) return $text; } -function banana_wordwrap($text, $quote_level) +function banana_wordwrap($text, $quote_level = 0) { if ($quote_level > 0) { $length = Banana::$msgshow_wrap - $quote_level - 1; diff --git a/banana/spool.inc.php b/banana/spool.inc.php index b3c0bfc..39f30fa 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -245,7 +245,7 @@ class BananaSpool return true; } - private function updateUnread($since) + public function updateUnread($since) { if (empty($since)) { return; @@ -573,6 +573,33 @@ class BananaSpool return $id_cur; } + /** Return the last post id with the given subject + * @param subject + */ + public function getPostId($subject) + { + $subject = trim($subject); + $id = max(array_keys($this->overview)); + while (isset($this->overview[$id])) { + $test = $this->overview[$id]->subject; + if (function_exists('hook_formatDisplayHeader')) { + $val = hook_formatDisplayHeader('subject', $test, true); + if (is_array($val)) { + $test = $val[0]; + } else { + $test = $val; + } + } + $test = trim($test); + echo $test . " - " . $subject . "\n"; + if ($test == $subject) { + return $id; + } + $id--; + } + return -1; + } + /** Returns previous thread root index * @param id INTEGER message number */