-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrssdb.php
41 lines (36 loc) · 1.03 KB
/
rssdb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class RSSDb
{
protected $hDatabase = null;
protected $minId = 0;
protected $bits = array(0=>1, 2, 4, 8, 16, 32, 64, 128);
public function __construct($dbFile, $minId = 0)
{
fclose(fopen($dbFile, 'a')); // create file if not exists
$this->hDatabase = fopen($dbFile, 'r+');
$this->minId = $minId;
}
public function __destruct()
{
fclose($this->hDatabase);
}
public function isPublished($id)
{
$id -= $this->minId;
if ($id < 0) return true;
$pos = intval($id/8);
fseek($this->hDatabase, $pos);
$status = ord(fgetc($this->hDatabase));
return (bool)($status & $this->bits[$id % 8]);
}
public function setPublished($id)
{
$id -= $this->minId;
if ($id < 0) return;
$pos = intval($id/8);
fseek($this->hDatabase, $pos);
$status = ord(fgetc($this->hDatabase));
fseek($this->hDatabase, $pos);
fwrite($this->hDatabase, chr($status | $this->bits[$id % 8]));
}
}