/**
* Returns an HTML string declaring who likes something
*
* @param integer Total number of likes
* @param string Link to page showing all users who liked this content
* @param integer Timestamp at which the visitor liked this content
* @param array Array of up to 3 users who liked this content - user_id, username required.
*
* @return string
*/
/**
* Returns an HTML string declaring who likes something
*
* @param integer Total number of likes
* @param string Link to page showing all users who liked this content
* @param integer Timestamp at which the visitor liked this content
* @param array Array of up to 3 users who liked this content - user_id, username required.
*
* @return string
*/
public static function helperLikesHtml($number, $likesLink, $likeDate = 0, array $users = array())
{
$number = intval($number);
if (empty($users))
{
if ($number > 1)
{
return new XenForo_Phrase('likes_x_people_like_this', array(
'likes' => self::numberFormat($number),
'likesLink' => $likesLink
));
}
else
{
return new XenForo_Phrase('likes_1_person_likes_this', array(
'likes' => self::numberFormat($number),
'likesLink' => $likesLink
));
}
}
$userCount = count($users);
if ($userCount < 5 && $number > $userCount) // indicates some users are deleted
{
for ($i = 0; $i < $number; $i++)
{
if (empty($users[$i]))
{
$users[$i] = array(
'user_id' => 0,
'username' => new XenForo_Phrase('deleted_user_parentheses') // costs a query, but edge case
);
}
}
}
if ($likeDate)
{
$youLikeThis = true;
$visitorId = XenForo_Visitor::getUserId();
foreach ($users AS $key => $user)
{
if ($user['user_id'] == $visitorId)
{
unset($users[$key]);
break;
}
}
$users = array_values($users);
if (count($users) == 3)
{
unset($users[2]);
}
}
else
{
$youLikeThis = false;
}
$user1 = $user2 = $user3 = '';
if ($users[0])
{
$user1 = self::callHelper('username', array($users[0]));
if ($users[1])
{
$user2 = self::callHelper('username', array($users[1]));
if ($users[2])
{
$user3 = self::callHelper('username', array($users[2]));
}
}
}
$phraseParams = array(
'user1' => $user1,
'user2' => $user2,
'user3' => $user3,
'others' => self::numberFormat($number - 3),
'likesLink' => $likesLink
);
switch ($number)
{
case 1: return new XenForo_Phrase(($youLikeThis
? 'likes_you_like_this'
: 'likes_user1_likes_this'), $phraseParams, false);
case 2: return new XenForo_Phrase(($youLikeThis
? 'likes_you_and_user1_like_this'
: 'likes_user1_and_user2_like_this'), $phraseParams, false);
case 3: return new XenForo_Phrase(($youLikeThis
? 'likes_you_user1_and_user2_like_this'
: 'likes_user1_user2_and_user3_like_this'), $phraseParams, false);
case 4: return new XenForo_Phrase(($youLikeThis
? 'likes_you_user1_user2_and_1_other_like_this'
: 'likes_user1_user2_user3_and_1_other_like_this'), $phraseParams, false);
default: return new XenForo_Phrase(($youLikeThis
? 'likes_you_user1_user2_and_x_others_like_this'
: 'likes_user1_user2_user3_and_x_others_like_this'), $phraseParams, false);
}
}