Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * PHP Counter mit Reloadsperre, Textdatenbank und Graphic-Libary (without Error Images) |
||
5 | * (C)Copyright 2010 - 2019 Daniel Marschall |
||
6 | * Revision: 2019-02-18 |
||
7 | */ |
||
8 | |||
9 | class VtsCounter { |
||
10 | private $pdo = null; |
||
11 | |||
12 | function __construct($pdo) { |
||
13 | $this->pdo = $pdo; |
||
14 | } |
||
15 | |||
16 | public function clearReloadSperre($minutes) { |
||
17 | if ($minutes < 1) return; |
||
18 | $statement = $this->pdo->prepare("DELETE FROM counter_reloadsperre WHERE tsLastVisit < (UTC_TIMESTAMP() - INTERVAL $minutes MINUTE)"); |
||
19 | pdox_execute($statement); |
||
20 | |||
21 | # Alte Counter / Fake Counter / SQL Injection Tests löschen |
||
22 | $statement = $this->pdo->prepare("DELETE FROM counter_visitors WHERE tsLastVisit < (UTC_TIMESTAMP() - INTERVAL 1 YEAR)"); |
||
23 | pdox_execute($statement); |
||
24 | } |
||
25 | |||
26 | public function getIDfromIDStr($idstr) { |
||
27 | $statement = $this->pdo->prepare("SELECT id FROM counter_visitors WHERE idstr = ?"); |
||
28 | pdox_execute($statement, array($idstr)); |
||
29 | $numrows = $statement->rowCount(); |
||
30 | $id = -1; |
||
31 | if ($numrows == 0) { |
||
32 | $statement = $this->pdo->prepare("INSERT INTO counter_visitors (idstr, tsCreated) VALUES (?, UTC_TIMESTAMP())"); |
||
33 | pdox_execute($statement, array($idstr)); |
||
34 | $id = $this->pdo->lastInsertId(); |
||
35 | } else { |
||
36 | assert($numrows == 1); |
||
37 | $row = $statement->fetch(); |
||
38 | $id = $row['id']; |
||
39 | } |
||
40 | assert($id > 0); |
||
41 | return $id; |
||
42 | } |
||
43 | |||
44 | public function visitCount($counter_id, $ip) { |
||
45 | $statement = $this->pdo->prepare("SELECT * FROM counter_reloadsperre WHERE fk_counter = ? AND ip = ?"); |
||
46 | pdox_execute($statement, array($counter_id, $ip)); |
||
47 | $numrows = $statement->rowCount(); |
||
48 | if ($numrows == 0) { |
||
49 | $statement = $this->pdo->prepare("INSERT INTO counter_reloadsperre (fk_counter, ip, tsLastVisit) VALUES (?, ?, UTC_TIMESTAMP())"); |
||
50 | pdox_execute($statement, array($counter_id, $ip)); |
||
51 | |||
52 | $statement = $this->pdo->prepare("UPDATE counter_visitors SET counter = counter + 1, tsLastVisit = UTC_TIMESTAMP() WHERE id = ?"); |
||
53 | pdox_execute($statement, array($counter_id)); |
||
54 | } else { |
||
55 | assert($numrows == 1); |
||
56 | $row = $statement->fetch(); |
||
57 | $sperre_id = $row['id']; |
||
58 | $statement = $this->pdo->prepare("UPDATE counter_reloadsperre SET tsLastVisit = UTC_TIMESTAMP() WHERE id = ?"); |
||
59 | pdox_execute($statement, array($sperre_id)); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | public function getCounterInfo($counter_id) { |
||
64 | $statement = $this->pdo->prepare("SELECT counter, tsCreated FROM counter_visitors WHERE id = ?"); |
||
65 | pdox_execute($statement, array($counter_id)); |
||
66 | $numrows = $statement->rowCount(); |
||
67 | assert($numrows == 1); |
||
68 | $row = $statement->fetch(); |
||
69 | $out = new VtsCounterInfo(); |
||
70 | $out->visitors = $row['counter']; |
||
71 | $out->created = $row['tsCreated']; |
||
72 | return $out; |
||
73 | } |
||
74 | |||
75 | } |