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;
}
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;
}
$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
*/
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;
}