-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhits-counter.php
38 lines (34 loc) · 1.11 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
<?php
/**
* Hits counter.
*
* Simple hits/visits counter. Hits are displayed in the footer once the admin is logged in.
* Hits will not be incremented if admin is logged in.
*
* @author Yassine Addi <yassineaddi.dev@gmail.com> // edit by robiso
* @version 2.4 // edit by robiso
*/
if (defined('VERSION') && !defined('version')) {
define('version', VERSION);
}
wCMS::addListener('menu', 'incrementHits');
wCMS::addListener('footer', 'displayHits');
function incrementHits ($args) {
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) {
if ( ! wCMS::$loggedIn) return $args;
$hits = file_exists(__DIR__ . '/hits.txt') ? (int) file_get_contents(__DIR__ . '/hits.txt') : 0;
$args[0] .= ' • Hits: ' . $hits;
return $args;
}