From b18124bebfd8ec3a84aea62a990b34ed1bd6db2d Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Thu, 11 Jan 2007 13:44:16 +0000 Subject: [PATCH] Minor fixes in quote detection git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@152 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/banana.inc.php.in | 2 +- banana/message.func.inc.php | 26 +++++++++++++++----------- banana/page.inc.php | 28 ++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index 3313966..9095a9b 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -291,7 +291,7 @@ class Banana { Banana::$page->setPage('message'); $istext = $partid == 'text' || $partid == 'source' - || preg_match("/[-a-z0-9_]+\/[-a-z0-9_]+/", $partid); + || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid); if ($istext) { $this->loadSpool($group); } diff --git a/banana/message.func.inc.php b/banana/message.func.inc.php index 7f33856..d60e4e9 100644 --- a/banana/message.func.inc.php +++ b/banana/message.func.inc.php @@ -39,13 +39,9 @@ function banana_removeQuotes($line, &$quote_level, $strict = true) function banana_quote($line, $level, $mark = '>') { $lines = explode("\n", $line); + $quote = str_repeat($mark, $level); foreach ($lines as &$line) { - if ($level > 0 && substr($line, 0, strlen($mark)) != $mark) { - $line = ' ' . $line; - } - for ($i = 0 ; $i < $level ; $i++) { - $line = $mark . $line; - } + $line = $quote . $line; } return implode("\n", $lines); } @@ -59,11 +55,17 @@ function banana_unflowed($text) $line = banana_removeQuotes($line, $level); while (banana_isFlowed($line)) { $lvl = 0; - if (is_null($nl = array_shift($lines))) { + if (empty($lines)) { break; } + $nl = $lines[0]; $nl = banana_removeQuotes($nl, $lvl); - $line .= $nl; + if ($lvl == $level) { + $line .= $nl; + array_shift($lines); + } else { + break; + } } $text .= banana_quote($line, $level) . "\n"; } @@ -197,10 +199,12 @@ function banana_wrap($text, $base_level = 0, $strict = true) while (!is_null($line = array_shift($lines))) { $lvl = 0; $line = banana_removeQuotes($line, $lvl, $strict); - if($lvl != $level && !empty($buffer)) { - $text .= banana_wordwrap(implode("\n", $buffer), $level + $base_level) . "\n"; + if($lvl != $level) { + if (!empty($buffer)) { + $text .= banana_wordwrap(implode("\n", $buffer), $level + $base_level) . "\n"; + $buffer = array(); + } $level = $lvl; - $buffer = array(); } $buffer[] = $line; } diff --git a/banana/page.inc.php b/banana/page.inc.php index 92d4509..8882b42 100644 --- a/banana/page.inc.php +++ b/banana/page.inc.php @@ -77,10 +77,11 @@ class BananaPage extends Smarty $this->pages[$name] = array('text' => $text, 'template' => $template); return true; } - - /** Generate XHTML code + + /** Preparte the page generation + * @return template to use */ - public function run() + protected function prepare() { $this->registerPage('subscribe', _b_('Abonnements'), null); $this->registerPage('forums', _b_('Les forums'), null); @@ -102,6 +103,16 @@ class BananaPage extends Smarty unset($this->actions[$key]); } } + + return 'banana-base.tpl'; + } + + /** Generate XHTML code + */ + public function run() + { + $tpl = $this->prepare(); + $this->assign('group', Banana::$group); $this->assign('artid', Banana::$artid); $this->assign('part', Banana::$part); @@ -111,19 +122,20 @@ class BananaPage extends Smarty $this->assign('spool', Banana::$spool); $this->assign('protocole', Banana::$protocole); + $this->register_function('url', array($this, 'makeUrl')); + $this->register_function('link', array($this, 'makeLink')); + $this->register_function('imglink', array($this, 'makeImgLink')); + $this->register_function('img', array($this, 'makeImg')); + $this->assign('errors', $this->error); $this->assign('page', $this->page); $this->assign('pages', $this->pages); $this->assign('actions', $this->actions); - $this->register_function('url', array($this, 'makeUrl')); - $this->register_function('link', array($this, 'makeLink')); - $this->register_function('imglink', array($this, 'makeImgLink')); - $this->register_function('img', array($this, 'makeImg')); if (!Banana::$debug_smarty) { $error_level = error_reporting(0); } - $text = $this->fetch('banana-base.tpl'); + $text = $this->fetch($tpl); $text = banana_utf8entities($text); if (!Banana::$debug_smarty) { error_reporting($error_level); -- 2.1.4