require_once dirname(__FILE__) . '/banana.inc.php';
-define('BANANA_SPOOL_VERSION', '0.5.12');
+define('BANANA_SPOOL_VERSION', '0.5.13');
/** Class spoolhead
* class used in thread overviews
public function __construct($id, array &$message)
{
$this->id = $id;
- $this->msgid = $message['message-id'];
+ $this->msgid = @$message['message-id'];
$this->date = $message['date'];
- $this->subject = $message['subject'];
+ $this->subject = @$message['subject'];
$this->from = $message['from'];
$this->color = sprintf('#%06x', abs(crc32($this->from) % 0xffffff));
$this->desc = 1;
$spool->markAllAsRead();
}
$spool->updateUnread($since);
- //var_dump($spool);
return $spool;
}
- private static function spoolFilename($group)
+ public static function getPath($file = null)
{
- $file = Banana::$spool_root . '/' . Banana::$protocole->name() . '/';
- if (!is_dir($file)) {
- mkdir($file);
+ $path = Banana::$spool_root . '/' . Banana::$protocole->name() . '/' . Banana::$protocole->filename();
+ if (!is_dir($path)) {
+ if (file_exists($path)) {
+ @unlink($path);
+ }
+ mkdir($path, 0777, true);
}
- return $file . Banana::$protocole->filename();
+ return $path . '/' . $file;
+ }
+
+ private static function spoolFilename()
+ {
+ return BananaSpool::getPath('spool');
}
private static function &readFromFile($group)
{
$spool = null;
- $file = BananaSpool::spoolFilename($group);
+ $file = BananaSpool::spoolFilename();
if (!file_exists($file)) {
return $spool;
}
private function saveToFile()
{
- $file = BananaSpool::spoolFilename($this->group);
+ $file = BananaSpool::spoolFilename();
$this->roots = Array();
foreach($this->overview as &$msg) {
$msg =& $this->overview[$id];
$parents =& $this->getReferences($message);
while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
- $msg->parent =& array_pop($parents);
+ @$msg->parent =& array_pop($parents);
}
if (!is_null($msg->parent)) {
$parent->children[] =& $msg;
while (!is_null($parent)) {
$parent->desc += $msg->desc;
- $prev =& $p;
+ $prev =& $parent;
if ($parent !== $parent->parent) {
$parent =& $parent->parent;
} else {
$text = '<span style="' . $style . '" title="' . banana_entities($head->name . ', ' . $this->formatDate($head))
. '"><input type="radio" name="banana_tree" '
. (Banana::$msgshow_javascript ? 'onchange="window.location=\'' .
- banana_entities(Banana::$page->makeURL(array('group' => $this->group, 'artid' => $id))) . '\'"'
+ banana_entities(Banana::$page->makeURL(array('group' => $this->group, 'artid' => $head->id))) . '\'"'
: ' disabled="disabled"')
. ' /></span>';
$array = array($text);
/** build the spool tree associated with the given message
*/
public function &buildTree($id, $force = false) {
- $id = $this->root($id);
+ $root =& $this->root($id);
+ $id = $root->id;
if (!$force && isset($this->trees[$id])) {
return $this->trees[$id];
} else {
- $tree =& $this->_buildTree($this->overview[$id]);
+ $tree =& $this->_buildTree($root);
$tree = '<div class="tree"><div style="height:18px">'
. implode("</div>\n<div style=\"height:18px\">", $tree)
. '</div></div>';
/** Return root message of the given thread
* @param id INTEGER id of a message
*/
- public function root($id)
+ public function &root($id)
{
- while (true) {
- $id_parent = $this->overview[$id]->parent;
- if (is_null($id_parent)) break;
- $id = $id_parent;
+ $parent =& $this->overview[$id];
+ while (!is_null($parent->parent)) {
+ $parent =& $parent->parent;
}
- return $id;
+ return $parent;
}
/** Return the last post id with the given subject
*/
public function prevThread($id)
{
- $root = $this->root($id);
+ $root =& $this->root($id);
$last = null;
- foreach ($this->roots as $i) {
- if ($i == $root) {
+ foreach ($this->roots as &$i) {
+ if ($i === $root) {
return $last;
}
- $last = $i;
+ $last = $i->id;
}
return $last;
}
*/
public function nextThread($id)
{
- $root = $this->root($id);
+ $root =& $this->root($id);
$ok = false;
- foreach ($this->roots as $i) {
+ foreach ($this->roots as &$i) {
if ($ok) {
- return $i;
+ return $i->id;
}
- if ($i == $root) {
+ if ($i === $root) {
$ok = true;
}
}
*/
public function prevPost($id)
{
- $parent = $this->overview[$id]->parent;
+ $parent =& $this->overview[$id]->parent;
if (is_null($parent)) {
return null;
}
- $last = $parent;
- foreach ($this->overview[$parent]->children as $child) {
- if ($child == $id) {
+ $last = $parent->id;
+ foreach ($parent->children as &$child) {
+ if ($child->id == $id) {
return $last;
}
- $last = $child;
+ $last = $child->id;
}
return null;
}
*/
public function nextPost($id)
{
- if (count($this->overview[$id]->children) != 0) {
- return $this->overview[$id]->children[0];
+ $cur =& $this->overview[$id];
+ if (count($cur->children) != 0) {
+ return $cur->children[0]->id;
}
- $cur = $id;
+ $parent =& $cur;
while (true) {
- $parent = $this->overview[$cur]->parent;
+ $parent =& $cur->parent;
if (is_null($parent)) {
return null;
}
$ok = false;
- foreach ($this->overview[$parent]->children as $child) {
+ foreach ($parent->children as &$child) {
if ($ok) {
- return $child;
+ return $child->id;
}
- if ($child == $cur) {
+ if ($child === $cur) {
$ok = true;
}
}
- $cur = $parent;
+ $cur =& $parent;
}
return null;
}
/** Look for an unread message in the thread rooted by the message
* @param id INTEGER message number
*/
- private function _nextUnread($id)
+ private function _nextUnread(BananaSpoolHead &$cur)
{
- if (!$this->overview[$id]->isread) {
- return $id;
+ if (!$cur->isread) {
+ return $cur->id;
}
- foreach ($this->overview[$id]->children as $child) {
+ foreach ($cur->children as &$child) {
$unread = $this->_nextUnread($child);
if (!is_null($unread)) {
return $unread;
if (!is_null($id)) {
// Look in message children
- foreach ($this->overview[$id]->children as $child) {
+ foreach ($this->overview[$id]->children as &$child) {
$next = $this->_nextUnread($child);
if (!is_null($next)) {
return $next;
}
// Look in current thread
- $cur = $id;
+ if (is_null($id)) {
+ $cur = null;
+ } else {
+ $cur =& $this->overview[$id];
+ }
do {
- $parent = is_null($cur) ? null : $this->overview[$cur]->parent;
- $ok = is_null($cur) ? true : false;
+ if (is_null($cur)) {
+ $parent =& $cur;
+ $ok = true;
+ } else {
+ $parent =& $cur->parent;
+ $ok = false;
+ }
if (!is_null($parent)) {
- $array = &$this->overview[$parent]->children;
+ $array =& $parent->children;
} else {
- $array = &$this->roots;
+ $array =& $this->roots;
}
- foreach ($array as $child) {
+ foreach ($array as &$child) {
if ($ok) {
$next = $this->_nextUnread($child);
if (!is_null($next)) {
return $next;
}
}
- if ($child == $cur) {
+ if ($child === $cur) {
$ok = true;
}
}
- $cur = $parent;
+ $cur =& $parent;
} while(!is_null($cur));
return null;
}