1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_userlastlogged_info() 9{ 10 return [ 11 'name' => tra('Last Login information'), 12 'documentation' => tra('PluginUserLastLogged'), 13 'description' => tra('Show the last login information for a given or current user'), 14 'iconname' => 'user', 15 'introduced' => 13, 16 'params' => [ 17 'user' => [ 18 'required' => false, 19 'name' => tra('Username'), 20 'description' => tra('Username to display last login information for. Current user information shown 21 if left blank.'), 22 'since' => '13.0', 23 'filter' => 'username', 24 ], 25 'date_format' => [ 26 'required' => false, 27 'name' => tra('DateFormat'), 28 'description' => tra('Date format setting. Short_datetime used by default'), 29 'since' => '16.0', 30 'filter' => 'dateformat', 31 ], 32 ], 33 ]; 34} 35 36function wikiplugin_userlastlogged($data, $params) 37{ 38 global $user; 39 $userlib = TikiLib::lib('user'); 40 $tikilib = TikiLib::lib('tiki'); 41 42 if (! empty($params['user'])) { 43 $info = $userlib->get_user_info($params['user']); 44 } else { 45 $info = $userlib->get_user_info($user); 46 } 47 48 if (! empty($params['date_format'])) { 49 $functionName = "get_" . $params['date_format']; 50 if (method_exists($tikilib, $functionName)) { 51 return $tikilib->$functionName($info['lastLogin']); 52 } elseif ($params['date_format'] == 'timestamp') { 53 return $info['lastLogin']; 54 } else { 55 return $tikilib->get_short_datetime($info['lastLogin']); 56 } 57 } else { 58 return $tikilib->get_short_datetime($info['lastLogin']); 59 } 60} 61