-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhits-counter.php
47 lines (41 loc) · 1.19 KB
/
hits-counter.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
42
43
44
45
46
47
<?php
/**
* Hits counter plugin.
*
* Simple hits/visits counter. Hits are displayed in the footer only to the admin.
* Hits are not incremented if admin is logged in.
*
* @author Yassine Addi <yassineaddi.dev@gmail.com>
* Forked by Robert Isoski
*/
global $Wcms;
if (defined('VERSION')) {
$Wcms->addListener('menu', 'incrementHits');
$Wcms->addListener('footer', 'displayHits');
}
function incrementHits ($args) {
global $Wcms;
if ($Wcms->loggedIn) {
return $args;
}
$hits = file_exists(__DIR__ . '/hits.txt') ? (int) file_get_contents(__DIR__ . '/hits.txt') : 0;
if ( ! isset($_SESSION['_wcms_hits_counter'])) {
$_SESSION['_wcms_hits_counter'] = time();
$hits++;
}
if ((time()-$_SESSION['_wcms_hits_counter'])>600) {
$hits++;
}
$_SESSION['_wcms_hits_counter'] = time();
file_put_contents(__DIR__ . '/hits.txt', $hits);
return $args;
}
function displayHits ($args) {
global $Wcms;
if ( ! $Wcms->loggedIn) {
return $args;
}
$hits = file_exists(__DIR__ . '/hits.txt') ? (int) file_get_contents(__DIR__ . '/hits.txt') : 0;
$args[0] .= ' Website visits: ' . $hits;
return $args;
}