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_avatar_info()
9{
10	return [
11		'name' => tra('Profile picture'),
12		'documentation' => 'PluginAvatar',
13		'description' => tra('Display a user\'s profile picture'),
14		'prefs' => ['wikiplugin_avatar'],
15		'body' => tra('username'),
16		'iconname' => 'user',
17		'introduced' => 1,
18		'format' => 'html',
19		'params' => [
20			'page' => [
21				'required' => false,
22				'name' => tra('Page'),
23				'description' => tra('The wiki page the profile picture will link to. If empty and the user\'s
24					information is public, then the profile picture will link automatically the that user\'s user
25					information page'),
26				'since' => '1',
27				'default' => '',
28				'profile_reference' => 'wiki_page',
29			],
30			'float' => [
31				'required' => false,
32				'name' => tra('Float'),
33				'description' => tra('Align the profile picture on the page'),
34				'since' => '1',
35				'filter' => 'word',
36				'options' => [
37					['text' => '', 'value' => ''],
38					['text' => tra('Right'), 'value' => 'right'],
39					['text' => tra('Left'), 'value' => 'left'],
40				],
41			],
42			'fullsize' => [
43				'required' => false,
44				'name' => tra('Full Size'),
45				'description' => tra('If full-size images are stored in the file gallery, show the full-size image.'),
46				'default' => 'n',
47				'since' => '10.0',
48			],
49		],
50	];
51}
52
53function wikiplugin_avatar($data, $params)
54{
55	global $prefs, $user;
56	$userlib = TikiLib::lib('user');
57	$tikilib = TikiLib::lib('tiki');
58
59	extract($params, EXTR_SKIP);
60
61	if (! $data) {
62		$data = $user;
63	}
64
65	if (isset($float)) {
66		$avatar = $tikilib->get_user_avatar($data, $float);
67	} else {
68		$avatar = $tikilib->get_user_avatar($data);
69	}
70
71
72	if (isset($fullsize) && $fullsize == 'y' && $prefs["user_store_file_gallery_picture"] == 'y') {
73		$avatar = '<img src="tiki-show_user_avatar.php?fullsize=y&user=' . urlencode($data) . '"></img>';
74	}
75
76	if (isset($page)) {
77		$avatar = "<a href='tiki-index.php?page=$page'>" . $avatar . '</a>';
78	} elseif ($userlib->user_exists($data) && $tikilib->get_user_preference($data, 'user_information', 'public') == 'public') {
79		$id = $userlib->get_user_id($data);
80		$avatar = "<a href=\"tiki-user_information.php?userId=$id\">" . $avatar . '</a>';
81	}
82
83	return $avatar;
84}
85