public function __construct(array &$message)
{
$this->date = $message['date'];
- $this->subject = stripslashes($message['subject']);
+ $this->subject = $message['subject'];
$this->from = $message['from'];
$this->desc = 1;
$this->isread = true;
class BananaSpool
{
private $version;
+ private $mode;
/** group name */
public $group;
protected function __construct($group)
{
$this->version = BANANA_SPOOL_VERSION;
+ $this->mode = Banana::SPOOL_ALL;
$this->group = $group;
}
- public static function getSpool($group, $since = 0)
+ public static function getSpool($group, $since = 0, $clean = false)
{
if (!is_null(Banana::$spool) && Banana::$spool->group == $group) {
- $spool = Banana::$spool;
+ $spool =& Banana::$spool;
} else {
$spool = BananaSpool::readFromFile($group);
}
}
Banana::$spool =& $spool;
$spool->build();
+ if ($clean) {
+ $spool->markAllAsRead();
+ }
$spool->updateUnread($since);
return $spool;
}
if (!is_dir($file)) {
mkdir($file);
}
- $url = parse_url(Banana::$host);
- if (isset($url['host'])) {
- $file .= $url['host'] . '_';
- }
- if (isset($url['port'])) {
- $file .= $url['port'] . '_';
- }
- $file .= $group;
- return $file;
+ return $file . Banana::$protocole->filename();
}
private static function readFromFile($group)
return null;
}
$spool = unserialize(file_get_contents($file));
- if ($spool->version != BANANA_SPOOL_VERSION) {
+ if ($spool->version != BANANA_SPOOL_VERSION || $spool->mode != Banana::SPOOL_ALL) {
return null;
}
return $spool;
}
}
- file_put_contents($file, serialize($this));
+ if ($this->mode == Banana::SPOOL_ALL) {
+ file_put_contents($file, serialize($this));
+ }
}
private function build()
$threshold = (int)(log($threshold)/log(2));
$threshold = (2 ^ ($threshold + 1)) - 1;
}
- if (Banana::$maxspool && Banana::$maxspool < $msgnum) {
- $first = $last - Banana::$maxspool;
+ if (Banana::$spool_max && Banana::$spool_max < $msgnum) {
+ $first = $last - Banana::$spool_max;
if ($first < 0) {
$first += $threshold;
}
$mids = array_keys($this->overview);
foreach ($mids as $id) {
if (($first <= $last && ($id < $first || $id > $last))
- || ($first > $last && $id < $first && $id > $last))
- {
+ || ($first > $last && $id < $first && $id > $last)) {
$this->delid($id, false);
$do_save = true;
}
private function update(&$first, &$last, $msgnum)
{
- if ($first >= $last || !$msgnum) {
+ if ($first > $last || !$msgnum) {
return false;
}
}
$newpostsids = Banana::$protocole->getNewIndexes($since);
-
+
if (empty($newpostsids)) {
return;
}
$id = $this->ids[$mid];
if ($this->overview[$id]->isread) {
$this->overview[$id]->isread = false;
- $this->overview[$id]->descunread = 1;
while (isset($id)) {
$this->overview[$id]->descunread ++;
$id = $this->overview[$id]->parent;
public function setMode($mode)
{
+ $this->mode = $mode;
switch ($mode) {
case Banana::SPOOL_UNREAD:
foreach ($this->roots as $k=>$i) {
}
}
+ /** Mark the given id as read
+ * @param id MSGNUM of post
+ */
+ public function markAsRead($id)
+ {
+ if (!$this->overview[$id]->isread) {
+ $this->overview[$id]->isread = true;
+ while (isset($id)) {
+ $this->overview[$id]->descunread--;
+ $id = $this->overview[$id]->parent;
+ }
+ }
+ }
+
+ /** Mark all unread messages as read
+ */
+ public function markAllAsRead(array &$array = null)
+ {
+ if (is_null($array)) {
+ $array =& $this->roots;
+ }
+ foreach ($array as $id) {
+ if (!$this->overview[$id]->isread) {
+ $this->markAsRead($id);
+ }
+ if ($this->overview[$id]->descunread) {
+ $this->markAllAsRead($this->overview[$id]->children);
+ }
+ }
+ }
+
/** kill post and childrens
* @param $_id MSGNUM of post
*/
* @param $_pfx_end STRING prefix used for children of current node
* @param $_head BOOLEAN true if first post in thread
*
- * If you want to analyse subject, you can define the function hook_getSubject(&$subject) which
- * take the subject as a reference parameter, transform this subject to be displaid in the spool
- * view and return a string. This string will be put after the subject.
+ * If you want to analyse subject, you can define the function hook_formatDisplayHeader
*/
private function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
{
$res .= '<td class="subj' . ($_index == $_ref ? ' cur' : '') . '">'
. $_pfx_node .($hc ? ($_head ? $spfx_f : ($overview->parent_direct ? $spfx_s : $spfx_snd)) : $spfx_n);
$subject = $overview->subject;
+ if (function_exists('hook_formatDisplayHeader')) {
+ list($subject, $link) = hook_formatDisplayHeader('subject', $subject, true);
+ } else {
+ $subject = banana_catchFormats(banana_htmlentities(stripslashes($subject)));
+ $link = null;
+ }
if (empty($subject)) {
$subject = _b_('(pas de sujet)');
}
- $link = null;
- if (function_exists('hook_getSubject')) {
- $link = hook_getSubject($subject);
- }
- $subject = banana_catchFormats($subject);
if ($_index != $_ref) {
$subject = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $_id,
'text' => $subject, 'popup' => $subject));
if (!$overview) {
$_first = $first;
- $_last = $first + Banana::$tmax - 1;
+ $_last = $first + Banana::$spool_tmax - 1;
$_ref = null;
} else {
$_ref = $this->getNdx($first);
- $_last = $_ref + Banana::$tafter;
- $_first = $_ref - Banana::$tbefore;
+ $_last = $_ref + Banana::$spool_tafter;
+ $_first = $_ref - Banana::$spool_tbefore;
if ($_first < 0) {
$_last -= $_first;
}
for ($i = 0; $i < $pos ; $i++) {
$ndx += $this->overview[$this->overview[$id_parent]->children[$i]]->desc;
}
- $ndx++; //noeud père
+ $ndx++; //noeud père
$id_cur = $id_parent;
}
}
}
-// vim:set et sw=4 sts=4 ts=4
+// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
?>