Skip to content

Commit

Permalink
Tooltips now can be displayed on like numbers showing who liked or di…
Browse files Browse the repository at this point in the history
…sliked the item

For feature #1021
  • Loading branch information
eSilverStrike committed Mar 17, 2022
1 parent f4abe0d commit b1c5504
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 13 deletions.
9 changes: 8 additions & 1 deletion language/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,13 @@
'likes_speedlimit' => "You last used the Likes system on an item %s seconds ago. This site requires at least %s seconds between using the Likes system",
'likes_ip_error' => 'Your IP address has already performed this Likes action.',
'likes_uid_error' => 'Your User account has already performed this Likes action.',
'own_item_error' => 'Either you own the item or do not have permission to Like/Dislike it.'
'own_item_error' => 'Either you own the item or do not have permission to Like/Dislike it.',
'liked_by' => 'Liked by:',
'disliked_by' => 'Disliked by:',
'num_anon_users' => '<br>%s Anonymous Users',
'one_anon_users' => '<br>1 Anonymous User',
'num_more_users' => '<br>+%s more Users',
'username_in_likes_list' => '<br>%s'
);

###############################################################################
Expand Down Expand Up @@ -2506,6 +2512,7 @@
'likes_articles' => 'Article Likes',
'likes_comments' => 'Comment Likes',
'likes_speedlimit' => 'Likes Speed Limit',
'likes_users_listed' => 'User Listed',
'passwordspeedlimit' => 'Password Speed Limit',
'login_attempts' => 'Max. Login Attempts',
'login_speedlimit' => 'Login Speed Limit',
Expand Down
9 changes: 8 additions & 1 deletion language/english_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,13 @@
'likes_speedlimit' => "You last used the Likes system on an item %s seconds ago. This site requires at least %s seconds between using the Likes system",
'likes_ip_error' => 'Your IP address has already performed this Likes action.',
'likes_uid_error' => 'Your User account has already performed this Likes action.',
'own_item_error' => 'Either you own the item or do not have permission to Like/Dislike it.'
'own_item_error' => 'Either you own the item or do not have permission to Like/Dislike it.',
'liked_by' => 'Liked by:',
'disliked_by' => 'Disliked by:',
'num_anon_users' => '<br>%s Anonymous Users',
'one_anon_users' => '<br>1 Anonymous User',
'num_more_users' => '<br>+%s more Users',
'username_in_likes_list' => '<br>%s'
);

###############################################################################
Expand Down Expand Up @@ -2506,6 +2512,7 @@
'likes_articles' => 'Article Likes',
'likes_comments' => 'Comment Likes',
'likes_speedlimit' => 'Likes Speed Limit',
'likes_users_listed' => 'User Listed',
'passwordspeedlimit' => 'Password Speed Limit',
'login_attempts' => 'Max. Login Attempts',
'login_speedlimit' => 'Login Speed Limit',
Expand Down
9 changes: 8 additions & 1 deletion language/japanese_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,13 @@
'likes_speedlimit' => 'あなたは %s 秒前にお気に入りを投票しました。このサイトでは次にお気に入りの記事を投票する前に少なくとも %s 秒待つ必要があります。',
'likes_ip_error' => 'あなたのIPアドレスから既にお気に入りは投票されています。',
'likes_uid_error' => 'あなたのアカウントを用いて既にお気に入りは投票されています。',
'own_item_error' => '自分自身のアイテムに対してはお気に入りは実行できません。'
'own_item_error' => '自分自身のアイテムに対してはお気に入りは実行できません。',
'liked_by' => 'Liked by:',
'disliked_by' => 'Disliked by:',
'num_anon_users' => '<br>%s Anonymous Users',
'one_anon_users' => '<br>1 Anonymous User',
'num_more_users' => '<br>+%s more Users',
'username_in_likes_list' => '<br>%s'
);

###############################################################################
Expand Down Expand Up @@ -2495,6 +2501,7 @@
'likes_articles' => '記事のLikes',
'likes_comments' => 'コメントのLikes',
'likes_speedlimit' => 'Likesの実行制限間隔(秒)',
'likes_users_listed' => 'User Listed',
'passwordspeedlimit' => 'パスワードの取得制限間隔',
'login_attempts' => 'ログイン試行最大回数',
'login_speedlimit' => 'ログイン試行制限間隔',
Expand Down
1 change: 1 addition & 0 deletions public_html/admin/configuration_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
'rule' => ['inList', [0, 1, 2], false],
];
$_CONF_VALIDATE['Core']['likes_speedlimit'] = ['rule' => 'numeric'];
$_CONF_VALIDATE['Core']['likes_users_listed'] = ['rule' => 'numeric'];

// Subgroup Images, Tab Image Library
$_CONF_VALIDATE['Core']['image_lib'] = [
Expand Down
6 changes: 5 additions & 1 deletion public_html/docs/english/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,11 @@ <h3><a name="users_comments">Users and Submissions: Likes</a></h3>
<tr>
<td valign="top"><a name="desc_likes_speedlimit">likes_speedlimit</a></td>
<td valign="top">45</td>
<td valign="top">Number of seconds between using the Likes System for the user</td></tr>
<td valign="top">Number of seconds between using the Likes System for the user.</td></tr>
<tr>
<td valign="top"><a name="desc_likes_users_listed">likes_users_listed</a></td>
<td valign="top">5</td>
<td valign="top">List the last X number of users in a tooltip on the actual number who liked or disliked the item. 0 disables this feature.</td></tr>
</table>

<h2><a name="images">Images</a></h2>
Expand Down
4 changes: 4 additions & 0 deletions public_html/docs/japanese/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,10 @@ <h3><a name="users_comments">ユーザーと投稿: Likes(お気に入り)</a></
<td valign="top"><a name="desc_likes_speedlimit">Likesの投稿間隔制限(likes_speedlimit)</a></td>
<td valign="top">45</td>
<td valign="top">一度Likesシステムを使用した後で次に使用するまであけなければならない時間を秒単位で指定します。</td></tr>
<tr>
<td valign="top"><a name="desc_likes_users_listed">likes_users_listed</a></td>
<td valign="top">5</td>
<td valign="top">List the last X number of users in a tooltip on the actual number who liked or disliked the item. 0 disables this feature.</td></tr>
</table>

<h2><a name="images">画像</a></h2>
Expand Down
4 changes: 2 additions & 2 deletions public_html/layout/denim/controls/likes.thtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<span class="{!if user_liked}uk-icon-thumbs-up{!else}uk-icon-thumbs-o-up{!endif} uk-icon-small" data-uk-tooltip title="{lang_like_action}"></span>
{!endif}

<span class="gl-like-num">{num_of_likes}</span>
<span class="gl-like-num" data-uk-tooltip title="{lang_num_of_likes}">{num_of_likes}</span>
{!if dislike_enabled}
&nbsp;&nbsp;&nbsp;&nbsp;

Expand All @@ -22,7 +22,7 @@
<span class="{!if user_liked}uk-icon-thumbs-down{!else}uk-icon-thumbs-o-down{!endif} uk-icon-small" data-uk-tooltip title="{lang_dislike_action}"></span>
{!endif}

<span class="gl-dislike-num">{num_of_dislikes}</span>
<span class="gl-dislike-num" data-uk-tooltip title="{lang_num_of_dislikes}">{num_of_dislikes}</span>
{!endif}

<span class="gl-likes-message">{lang_message}</span>
Expand Down
84 changes: 77 additions & 7 deletions system/lib-likes.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
*
* @param string $type plugin name
* @param string $sub_type Sub type of plugin to allow plugins to have likes for more than one type of item (not required)
* @param string $id item id WARNING must be no larger that 128 characters
* @param string $item_id item id WARNING must be no larger that 128 characters
* @param int $likes_setting if 2 dislikes will not be displayed
* @param string $message language string of message to pass to user
* @return string html of the likes control
*
*/
function LIKES_control($type, $sub_type, $id, $likes_setting, $message = '') {
function LIKES_control($type, $sub_type, $item_id, $likes_setting, $message = '') {
global $_USER, $_CONF, $LANG_LIKES, $_SCRIPTS;

// Figure out if dislike is enabled or not
Expand All @@ -90,7 +90,7 @@ function LIKES_control($type, $sub_type, $id, $likes_setting, $message = '') {
$dislike = false;
}

list($num_likes, $num_dislikes) = LIKES_getLikes($type, $sub_type, $id);
list($num_likes, $num_dislikes) = LIKES_getLikes($type, $sub_type, $item_id);

// Find likes control template file to use
if ($type != 'article' OR $type != 'comment') {
Expand All @@ -116,18 +116,18 @@ function LIKES_control($type, $sub_type, $id, $likes_setting, $message = '') {

$likes_templates->set_var('item_type', $type);
$likes_templates->set_var('item_sub_type', $sub_type);
$likes_templates->set_var('item_id', $id);
$likes_templates->set_var('item_id', $item_id);

$uid = isset($_USER['uid']) ? $_USER['uid'] : 1;
$ip = \Geeklog\IP::getIPAddress();

$action_enabled = PLG_canUserLike($type, $sub_type, $id, $uid, $ip);
$action_enabled = PLG_canUserLike($type, $sub_type, $item_id, $uid, $ip);

$likes_templates->set_var('dislike_enabled', $dislike);
$likes_templates->set_var('action_enabled', $action_enabled);

if ($action_enabled) {
$prev_action = LIKES_hasAction($type, $sub_type, $id, $uid, $ip);
$prev_action = LIKES_hasAction($type, $sub_type, $item_id, $uid, $ip);
if ($prev_action == LIKES_ACTION_LIKE) {
$likes_templates->set_var('user_liked', true);
$likes_templates->set_var('lang_like_action', $LANG_LIKES['unlike']);
Expand All @@ -152,13 +152,19 @@ function LIKES_control($type, $sub_type, $id, $likes_setting, $message = '') {
}

// Debug
//$message .= " t=".$type." st=".$sub_type." i=".$id." u=".$uid." a=".$action_enabled;
//$message .= " t=".$type." st=".$sub_type." i=".$item_id." u=".$uid." a=".$action_enabled;

$likes_templates->set_var('lang_message', $message);

$likes_templates->set_var('num_of_likes', LIKES_formatNum($num_likes));
if ($num_likes > 0) {
$likes_templates->set_var('lang_num_of_likes', LIKES_numberTooltip($type, $sub_type, $item_id, LIKES_ACTION_LIKE));
}
if ($dislike) {
$likes_templates->set_var('num_of_dislikes', LIKES_formatNum($num_dislikes));
if ($num_dislikes > 0) {
$likes_templates->set_var('lang_num_of_dislikes', LIKES_numberTooltip($type, $sub_type, $item_id, LIKES_ACTION_DISLIKE));
}
}

$likes_templates->parse('output', 'likes_control');
Expand All @@ -167,6 +173,70 @@ function LIKES_control($type, $sub_type, $id, $likes_setting, $message = '') {
return $retval;
}

/**
* Returns the likes/dislikes number tooltip
*
* @param string $type plugin name
* @param string $sub_type Sub type of plugin to allow plugins to have likes for more than one type of item (not required)
* @param string $item_id item id WARNING must be no larger that 128 characters
* @param int $action LIKES_ACTION_LIKE or LIKES_ACTION_DISLIKE
* @return string tooltip text for Likes or Dislikes number
*
*/
function LIKES_numberTooltip($type, $sub_type, $item_id, $action)
{
global $_CONF, $LANG_LIKES, $_TABLES;

if (!($action == LIKES_ACTION_LIKE || $action == LIKES_ACTION_DISLIKE)
|| (!isset($_CONF['likes_users_listed']) || $_CONF['likes_users_listed'] == 0)) {
return '';
}

$sql = "SELECT uid FROM {$_TABLES['likes']} WHERE type='" . DB_escapeString($type) . "' AND subtype='" . DB_escapeString($sub_type) . "' AND id='" . DB_escapeString($item_id) . "' AND uid = 1 AND action = " . $action;
$result = DB_query($sql);
$num_anon_likes = DB_numRows($result);

$sql = "SELECT uid FROM {$_TABLES['likes']} WHERE type='" . DB_escapeString($type) . "' AND subtype='" . DB_escapeString($sub_type) . "' AND id='" . DB_escapeString($item_id) . "' AND uid > 1 AND action = " . $action . " ORDER BY created DESC";
$result = DB_query($sql);
$num_user_likes = DB_numRows($result);
$user_list = '';
$user_count = 0;
$num_more_users = 0;

while (($A = DB_fetchArray($result, false)) != false) {
$user_count++;
$user_list .= sprintf($LANG_LIKES['username_in_likes_list'], COM_getDisplayName($A['uid']));
if ($user_count == $_CONF['likes_users_listed']) {
$num_more_users = $num_user_likes - $user_count;
// Only stop if greater than 1 more else just go through it one more time
if (($user_count + 1) < $num_user_likes) {
break;
}
}
}

if ($action == LIKES_ACTION_LIKE) {
$lang_num_of_likes = $LANG_LIKES['liked_by'];
} else {
$lang_num_of_likes = $LANG_LIKES['disliked_by'];
}

if ($num_anon_likes == 1) {
$lang_num_of_likes .= $LANG_LIKES['one_anon_users'];
} elseif ($num_anon_likes > 1) {
$lang_num_of_likes .= sprintf($LANG_LIKES['num_anon_users'], $num_anon_likes);
}

$lang_num_of_likes .= $user_list;

if (($user_count + 1) < $num_user_likes) {
$lang_num_of_likes .= sprintf($LANG_LIKES['num_more_users'], $num_more_users);
}

return $lang_num_of_likes;

}

/**
* Returns the likes number in a rounded format over 1000
*
Expand Down

0 comments on commit b1c5504

Please sign in to comment.