1<?php 2/** 3 * Last Seen plugin — activity tracker. 4 * 5 * Records the timestamp of each authenticated request so the admin component 6 * can show when every registered user was last active. 7 */ 8 9class action_plugin_lastseen extends DokuWiki_Action_Plugin 10{ 11 public function register(Doku_Event_Handler $controller) 12 { 13 // DOKUWIKI_STARTED fires on essentially every request, after 14 // authentication has resolved. By this point REMOTE_USER is set for 15 // any logged-in user — whether they just submitted the login form or 16 // arrived with a persistent ("remember me") cookie. Hooking here 17 // therefore records last *activity*, the superset of last *login*. 18 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'recordActivity'); 19 } 20 21 /** 22 * @param Doku_Event $event unused (DOKUWIKI_STARTED carries no data) 23 */ 24 public function recordActivity(Doku_Event $event) 25 { 26 global $INPUT; 27 28 $user = $INPUT->server->str('REMOTE_USER'); 29 if ($user === '') { 30 return; // anonymous request — nothing to record 31 } 32 33 /** @var helper_plugin_lastseen $hlp */ 34 $hlp = plugin_load('helper', 'lastseen'); 35 if ($hlp === null) { 36 return; 37 } 38 39 // record() is internally throttled — for most requests this is a 40 // cheap read-and-return with no disk write. 41 $hlp->record($user); 42 } 43} 44