From: x2003bruneau Date: Tue, 23 Oct 2007 22:04:19 +0000 (+0000) Subject: Integration of the tree in the spool view X-Git-Tag: 1.8~30 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=66e812365e1cf26675f001408518059367fd4317;hp=1a85c7a672b790232ee7f0b27b8a6a05945d6570;p=banana.git Integration of the tree in the spool view Signed-off-by: Florent Bruneau git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@281 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index 3ca5da6..2b43207 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -33,8 +33,8 @@ class Banana static public $spool_root = '/var/spool/banana'; static public $spool_max = 3000; static public $spool_tbefore = 5; - static public $spool_tafter = 5; - static public $spool_tmax = 50; + static public $spool_tcontext= 10; + static public $spool_tmax = 10; static public $spool_boxlist = true; ### Message processing ### diff --git a/banana/message.inc.php b/banana/message.inc.php index ff08fd3..51999cb 100644 --- a/banana/message.inc.php +++ b/banana/message.inc.php @@ -119,7 +119,7 @@ final class BananaMessage extends BananaMimePart public function getSender() { $from = $this->headers['from']; - $name = trim(preg_replace('/<[^ ]*>/', '', $from)); + $name = trim(strip_tags($from)); if (empty($name)) { return $from; } @@ -165,7 +165,7 @@ final class BananaMessage extends BananaMimePart } if (preg_match("/^([^ ]+@[^ ]+) \((.*)\)$/", $text, $regs)) { $result = $mailto . $regs[1] . $subject . '">' . banana_htmlentities($regs[2]) . ''; - } + } if (preg_match("/^\"?([^<>\"]+)\"? +<(.+@.+)>$/", $text, $regs)) { $nom = preg_replace("/^'(.*)'$/", '\1', $regs[1]); $nom = stripslashes($nom); @@ -180,7 +180,7 @@ final class BananaMessage extends BananaMimePart $name = null; if (preg_match("/^([^ ]+@[^ ]+) \((.*)\)$/", $text, $regs)) { $name = $regs[2]; - } + } if (preg_match("/^\"?([^<>\"]+)\"? +<(.+@.+)>$/", $text, $regs)) { $name = preg_replace("/^'(.*)'$/", '\1', $regs[1]); $name = stripslashes($name); diff --git a/banana/spool.inc.php b/banana/spool.inc.php index 6ce1751..28e8a35 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/banana.inc.php'; -define('BANANA_SPOOL_VERSION', '0.5.1'); +define('BANANA_SPOOL_VERSION', '0.5.7'); /** Class spoolhead * class used in thread overviews @@ -22,6 +22,7 @@ class BananaSpoolHead public $subject; /** author */ public $from; + public $name; public $color; /** reference of parent */ public $parent = null; @@ -56,6 +57,20 @@ class BananaSpoolHead $this->desc = 1; $this->isread = true; $this->descunread = 0; + if (preg_match("/^([^ ]+@[^ ]+) \((.*)\)$/", $this->from, $regs)) { + $this->name = $regs[2]; + } + if (preg_match("/^\"?([^<>\"]+)\"? +<(.+@.+)>$/", $this->from, $regs)) { + $this->name = preg_replace("/^'(.*)'$/", '\1', $regs[1]); + $this->name = stripslashes($this->name); + } + if ($this->name) { + $this->name = preg_replace("/\\\(\(|\))/","\\1", $this->name); + } else if (preg_match("/([^< ]+)@([^> ]+)/", $this->from, $regs)) { + $this->name = $regs[1]; + } else { + $this->name = 'Anonymous'; + } } } @@ -73,6 +88,9 @@ class BananaSpool public $ids; /** thread starts */ public $roots; + /** thread trees (one tree per root node) */ + public $trees = array(); + /** protocole specific data */ public $storage = array(); @@ -219,6 +237,7 @@ class BananaSpool if (!is_array($this->overview)) { $this->overview = array(); } + $updateTrees = array(); foreach ($messages as $id=>&$message) { if (!isset($this->overview[$id])) { $this->overview[$id] = new BananaSpoolHead($message); @@ -234,17 +253,23 @@ class BananaSpool $this->overview[$p] = new BananaSpoolHead($messages[$p]); } $this->overview[$p]->children[] = $id; - while (!is_null($p)) { $this->overview[$p]->desc += $msg->desc; + $prev = $p; if ($p != $this->overview[$p]->parent) { $p = $this->overview[$p]->parent; } else { $p = null; } + if (is_null($p)) { + $updateTrees[$prev] = true; + } } } } + foreach ($updateTrees as $root=>$t) { + $this->trees[$root] = $this->buildTree($root, true); + } Banana::$protocole->updateSpool($messages); return true; } @@ -385,6 +410,7 @@ class BananaSpool } unset($overview); unset($this->overview[$_id]); + unset($this->trees[$_id]); $msgid = array_search($_id, $this->ids); if ($msgid !== false) { unset($this->ids[$msgid]); @@ -400,7 +426,7 @@ class BananaSpool } } - private function formatDate($stamp) + public function formatDate($stamp) { $today = intval(time() / (24*3600)); $dday = intval($stamp / (24*3600)); @@ -419,6 +445,47 @@ class BananaSpool return strftime($format, $stamp); } + public function formatSubject($id, $subject) + { + $subject = banana_html_entity_decode($subject); + $popup = $subject; + if (function_exists('hook_formatDisplayHeader')) { + list($subject, $link) = hook_formatDisplayHeader('subject', $subject, true); + } else { + $subject = banana_catchFormats(banana_entities(stripslashes($subject))); + $link = null; + } + if (empty($subject)) { + $subject = _b_('(pas de sujet)'); + } + if ($id != Banana::$artid) { + $subject = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $id, + 'text' => $subject, 'popup' => $popup)); + } + return $subject . $link; + } + + public function formatFrom($from) + { + $from = banana_html_entity_decode($from); + return BananaMessage::formatFrom($from); + } + + public function start() + { + if (Banana::$first) { + return Banana::$first; + } else { + $first = array_search(Banana::$artid, $this->roots); + return max(0, $first - Banana::$spool_tbefore); + } + } + + public function context() + { + return Banana::$first ? Banana::$spool_tmax : Banana::$spool_tcontext; + } + /** displays children tree of a post * @param $_id INTEGER MSGNUM of post * @param $_index INTEGER linear number of post in the tree @@ -558,10 +625,11 @@ class BananaSpool } $style = 'background-color:' . $head->color . '; text-decoration: none'; $prof = 1; - $text = '' . + $text = '' . 'makeURL(array('group' => $this->group, 'artid' => $id))) . '\'"' + : ' disabled="disabled"') .' />' . ''; $array = array($text); @@ -584,6 +652,7 @@ class BananaSpool $array[] = $t_e . ($msg->isread ? $r_l : $u_l) . $line; } } + unset($tree); if ($tpr > $prof) { $prof = $tpr + 1; } @@ -593,15 +662,19 @@ class BananaSpool /** build the spool tree associated with the given message */ - public function buildTree($id) { + public function buildTree($id, $force = false) { $pos = $id; $overview =& $this->overview[$id]; while (!is_null($overview->parent)) { $pos = $overview->parent; $overview =& $this->overview[$pos]; } - list($prof, $tree) = $this->_buildTree($pos, $overview, $id); - return implode("\n", $tree); + if (!$force && isset($this->trees[$pos])) { + return $this->trees[$pos]; + } else { + list(, $tree) = $this->_buildTree($pos, $overview, $force ? -1 : $id); + return '
' . implode("
\n
", $tree) . '
'; + } } /** computes linear post index diff --git a/banana/templates/banana-message.inc.tpl b/banana/templates/banana-message.inc.tpl index 94d7fa7..0712532 100644 --- a/banana/templates/banana-message.inc.tpl +++ b/banana/templates/banana-message.inc.tpl @@ -1,22 +1,18 @@ -
-{$spool->buildTree($artid)|smarty:nodefaults}
-
- + {if $spool && ($nextPost || $prevPost)} + + + + + + + {/if}
{if !$noactions}
{if $message->canSend()} @@ -102,6 +98,16 @@ {$body|banana_utf8entities|smarty:nodefaults}
+ {"Naviguer dans la discussion..."|b} +
{$spool->buildTree($artid)|smarty:nodefaults}
{* vim:set et sw=2 sts=2 ts=2 enc=utf-8: *} diff --git a/banana/templates/banana-thread.inc.tpl b/banana/templates/banana-thread.inc.tpl index 7fce61b..3729385 100644 --- a/banana/templates/banana-thread.inc.tpl +++ b/banana/templates/banana-thread.inc.tpl @@ -1,8 +1,8 @@ {capture name=pages} {if $withtitle}
-{if $spool->overview|@count gt $msgbypage} -{section name=pages loop=$spool->overview step=$msgbypage} +{if $spool->roots|@count gt $msgbypage} +{section name=pages loop=$spool->roots step=$msgbypage} {if $first ge $smarty.section.pages.index && $first lt $smarty.section.pages.index_next} {$smarty.section.pages.iteration} {else} @@ -19,9 +19,10 @@ {if $withtitle} - {if $spool->nextUnread()} + {assign var=nextUnread value=$spool->nextUnread()} + {if $nextUnread} {/if} {"Date"|b} @@ -37,13 +38,25 @@ {"Auteur"|b} {else} - - {"Aperçu de "|b}{link group=$group text=$group} - + {"En discussion sur "|b}{link group=$group text=$group}... {/if} - {if $spool->overview|@count} - {if $artid}{$spool->toHtml($artid, true)|smarty:nodefaults}{else}{$spool->toHtml($first)|smarty:nodefaults}{/if} + {if $spool->roots|@count} + {section name=threads loop=$spool->roots step=1 start=$spool->start() max=$spool->context()} + {assign var=id value=$spool->roots[$smarty.section.threads.index]} + {assign var=overview value=$spool->overview[$id]} + {cycle assign=class values="impair,pair"} + + {$spool->formatDate($overview->date)} + {$spool->formatSubject($id, $overview->subject)|smarty:nodefaults} + {$spool->formatFrom($overview->from)|smarty:nodefaults} + + {if !$artid && $spool->nextPost($id)} + + {$spool->buildTree($id)|smarty:nodefaults} + + {/if} + {/section} {else} diff --git a/css/style.css b/css/style.css index 98f6b67..660eeb9 100644 --- a/css/style.css +++ b/css/style.css @@ -72,8 +72,8 @@ background-color: #fff; } -.banana pre.thread_tree { - overflow: scroll; +.banana td.thread_tree, .banana div.thread_tree { + overflow: auto; } .banana .thread_tree input {