Last active
January 21, 2018 13:10
-
-
Save Kaivosukeltaja/62e0cb98e8db16474e557d829975c659 to your computer and use it in GitHub Desktop.
Mikseri.net profile page visitor counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* == PAGECOUNTER == */ | |
/* == Pitää lukua päivittäisistä vierailijamääristä == */ | |
$pagecounter_cache_key = 'pagecounter_' . $user_id . '_' . date('Y-m-d'); | |
$pagecounter = $cache->get($pagecounter_cache_key); | |
if (!is_array($pagecounter)) | |
{ | |
$pagecounter = array(); | |
$res = $db->query("SELECT date, count from pagecounter WHERE WEEK(date) = WEEK(CURDATE()) AND user_id = ?", array($user_id)); | |
if ($res->numRows() > 0) | |
{ | |
foreach($res as $item) | |
{ | |
$pagecounter[$item['date']] = $item['count']; | |
} | |
} | |
if(!isset($pagecounter[date('Y-m-d')])) | |
{ | |
$db->query("INSERT INTO pagecounter SET date = curdate(), user_id = ?", array($user_id)); | |
$pagecounter[date('Y-m-d')] = 0; | |
} | |
} | |
if ($user_id != $myid or rand(1, 10) == 1) | |
{ | |
$pagecounter[date('Y-m-d')]++; | |
$db->query("UPDATE pagecounter SET count = ? WHERE date = CURDATE() AND user_id = ? LIMIT 1", array($pagecounter[date('Y-m-d')], $user_id)); | |
} | |
$cache->set($pagecounter_cache_key, $pagecounter, 3600); | |
$smarty->assign('pagecounter', $pagecounter); | |
/* | |
mysql> describe pagecounter; | |
+---------+------------------+------+-----+------------+-------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+---------+------------------+------+-----+------------+-------+ | |
| date | date | NO | MUL | 0000-00-00 | | | |
| user_id | int(10) unsigned | NO | | 0 | | | |
| count | int(10) unsigned | NO | MUL | 0 | | | |
+---------+------------------+------+-----+------------+-------+ | |
3 rows in set (0.01 sec) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{if $userdata.id == $thisuser.id} | |
<br /> | |
Profiilia katsottu tällä viikolla {$pagecounter|@array_sum} <span class="light">(näkyy vain itselle)</span> | |
{/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment