Minor fixes in quote detection
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Thu, 11 Jan 2007 13:44:16 +0000 (13:44 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:14 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@152 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/message.func.inc.php
banana/page.inc.php

index 3313966..9095a9b 100644 (file)
@@ -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);
         }
index 7f33856..d60e4e9 100644 (file)
@@ -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;
     }
index 92d4509..8882b42 100644 (file)
@@ -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);