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_like_info()
9{
10	return [
11		'name' => tra('Like'),
12		'documentation' => 'PluginLike',
13		'description' => tra('Create a "Like" button.'),
14		'prefs' => [ 'wikiplugin_like', 'user_likes' ],
15		'introduced' => 15,
16		'iconname' => 'thumbs-up',
17		'format' => 'html',
18		'params' => [
19			'objectType' => [
20				'required' => true,
21				'name' => tra('Object Type'),
22				'description' => tra('Object Type'),
23				'since' => '15.0',
24				'filter' => 'text',
25				'default' => '',
26			],
27			'objectId' => [
28				'required' => true,
29				'name' => tra('Object ID'),
30				'description' => tra('Object ID'),
31				'since' => '15.0',
32				'filter' => 'text',
33				'default' => '',
34				'profile_reference' => 'type_in_param',
35			],
36			'count_only' => [
37				'required' => false,
38				'name' => tra('Count only'),
39				'description' => tra('Sets whether to only show the count of likes rather than give the option to vote'),
40				'since' => '15.0',
41				'filter' => 'alpha',
42				'default' => 'false',
43			],
44		]
45	];
46}
47function wikiplugin_like($data, $params)
48{
49	$smarty = TikiLib::lib('smarty');
50	if ($params['objectType'] == 'usertracker') {
51		$objectType = 'trackeritem';
52		$objectId = 0;
53		if ($userid = Tikilib::lib('tiki')->get_user_id($params['objectId'])) {
54			$tracker = TikiLib::lib('user')->get_usertracker($userid);
55			if ($tracker && $tracker['usersTrackerId']) {
56				$objectId = TikiLib::lib('trk')->get_item_id($tracker['usersTrackerId'], $tracker['usersFieldId'], $params['objectId']);
57			}
58		}
59	} else {
60		$objectType = $params['objectType'];
61		$objectId = $params['objectId'];
62	}
63	$smarty->assign('wikiplugin_like_objectId', urlencode($objectId));
64	$smarty->assign('wikiplugin_like_objectType', urlencode($objectType));
65	$smarty->assign('wikiplugin_like_count_only', urlencode($params['count_only']));
66	$ret = $smarty->fetch('wiki-plugins/wikiplugin_like.tpl');
67	return $ret;
68}
69