summaryrefslogtreecommitdiff
path: root/smartyplugins/function.displayname.php
blob: fa10a2ed2b06be523af47f36b6da758d8cae963a (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Bitweaver\Plugins;

use Bitweaver\BitBase;
use Bitweaver\Users\RoleUser;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**** smarty_function_displayName
	* This is a smarty function which will allow different values to be
	* output to identify users (real_name, user, user_id) as opposed todo
	* only allowing the 'login' to be output.
	* hash=fooHash is a short cut to specifying each parameter by hand
	* usage: {displayname user= user_id= real_name= link_title=}
*/
function smarty_function_displayname( $pParams, &$gBitSmarty ) {
	global $gBitUser;
	if( !empty( $pParams['hash'] ) ) {
		if( is_array( $pParams['hash'] ) ) {
			$hash = array_merge( $pParams, $pParams['hash'] );
			unset( $hash['hash'] );
			// if the hash only has a user_id, we need to look up the user
			if( BitBase::verifyId( $hash['user_id'] ) && empty( $hash['user'] ) && empty( $hash['email'] ) && empty( $hash['login'] )) {
				$lookupHash['user_id'] = $hash['user_id'];
			}
		} else {
			// We were probably just passed the 'login' due to legacy code which has yet to be converted
			if( strpos( '@', $pParams['hash'] ) ) {
				$lookupHash['email'] = $pParams['hash'];
			} elseif( is_numeric( $pParams['hash'] ) ) {
				$lookupHash['user_id'] = $pParams['hash'];
			} else {
				$lookupHash['login'] = $pParams['hash'];
			}
		}
	} elseif( !empty( $pParams['user_id'] ) ) {
		$lookupHash['user_id'] = $pParams['user_id'];
	} elseif( !empty( $pParams['email'] ) ) {
		$lookupHash['email'] = $pParams['email'];
	} elseif( !empty( $pParams['login'] ) ) {
		$lookupHash['login'] = $pParams['login'];
	} elseif( !empty( $pParams['user'] ) ) {
		$lookupHash['login'] = $pParams['user'];
	} elseif( empty( $pParams ) ) {
		global $gBitUser;
		$hash = $gBitUser->mInfo;
	}

	if( !empty( $lookupHash ) ) {
		$hash = $gBitUser->getUserInfo( $lookupHash );
	}

	$displayName = !empty( $hash )
		? RoleUser::getDisplayNameFromHash( $hash, empty( $pParams['nolink'] ) )
		// Now we're really in trouble. We don't even have a user_id to work with
		: "Unknown";

	return $displayName;
}