Skip to content

Commit

Permalink
User Profile now display last 10 likes and dislikes by user
Browse files Browse the repository at this point in the history
For feature #1120
  • Loading branch information
eSilverStrike committed May 26, 2022
1 parent fd6caf3 commit 822cfe0
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 5 deletions.
5 changes: 5 additions & 0 deletions language/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@
'no_liked_items' => 'There are no Liked items.',
'no_disliked_items' => 'There are no Disliked items.',
'no_action_items' => 'There are no Liked or Disliked items.',
'last_num_likes_by' => 'Last %s Likes and Dislikes by %s',
'msg_no_likes' => 'No likes or dislikes found by user.',
'total_num_likes' => 'Total number of likes and dislikes:',
'title_liked' => '%s Liked on ',
'title_disliked' => '%s Disliked on ',
// Likes Block Core Supported Plurals
'articles' => 'Articles',
'comments' => 'Comments'
Expand Down
3 changes: 3 additions & 0 deletions language/english_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@
'no_liked_items' => 'There are no Liked items.',
'no_disliked_items' => 'There are no Disliked items.',
'no_action_items' => 'There are no Liked or Disliked items.',
'last_num_likes_by' => 'Last %n Likes and/or Dislikes by %s',
'title_liked' => '%s Liked on ',
'title_disliked' => '%s Disliked on ',
// Likes Block Core Supported Plurals
'articles' => 'Articles',
'comments' => 'Comments'
Expand Down
2 changes: 2 additions & 0 deletions language/japanese_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,8 @@
'no_liked_items' => 'There are no Liked items.',
'no_disliked_items' => 'There are no Disliked items.',
'no_action_items' => 'There are no Liked or Disliked items.',
'title_liked' => '%s Liked on ',
'title_disliked' => '%s Disliked on ',
// Likes Block Core Supported Plurals
'articles' => 'Articles',
'comments' => 'Comments'
Expand Down
7 changes: 6 additions & 1 deletion plugins/staticpages/functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,12 @@ function plugin_getiteminfo_staticpages($sp_id, $what, $uid = 0, $options = arra
break;

case 'likes':
$props['likes'] = $A['likes'];
if ($A['likes'] == -1) {
// Set to use Plugin Likes default setting
$props['likes'] = $_SP_CONF['likes_pages'];
} else {
$props['likes'] = $A['likes'];
}
break;

case 'url':
Expand Down
87 changes: 86 additions & 1 deletion system/lib-likes.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ function LIKES_displayLikesBlock($displayAction = null, $type = '', $subtype = '
$sql_type = " AND type = '{$type}' AND subtype = '{$subtype}'";
}

// We do not know permissions of items being returned that has likes (or if likes enabled for item) so cannot limit number of rows since some items may not have read permissions for user
// We do not know permissions of items being returned that has likes (or if likes currently enabled for item) so cannot limit number of rows since some items may not have read permissions for user
$sql = "SELECT COUNT(lid) actioncount, type, subtype, id, MAX(created) latestdate FROM {$_TABLES['likes']}
WHERE 1=1
{$sql_type}
Expand Down Expand Up @@ -1111,3 +1111,88 @@ function plugin_itemdeleted_likes($id, $type, $sub_type)
LIKES_deleteActions($type, $sub_type, $id);
}

/**
* Geeklog is about to display the user's profile. Plugins now get a chance to
* add their own variables to the profile.
*
* @param int $uid user id of the user profile to be edited
* @param Template $template reference of the Template for the profile edit form
* @return void
*/
function plugin_profilevariablesdisplay_likes ($uid, &$template)
{
global $_TABLES, $_CONF, $LANG_LIKES;

if (!$_CONF['likes_enabled']) {
return;
}

$listLimit = "10"; // How many posts you want displayed

$username = DB_getItem ($_TABLES['users'], 'username', "uid = $uid");
$title = sprintf($LANG_LIKES['last_num_likes_by'], $listLimit, $username);
$template->set_var ('start_block_last10', COM_startBlock($title, '', 'blockheader-child.thtml'));
$template->set_var('end_block_last10', COM_endBlock('blockfooter-child.thtml'));

// We do not know permissions of items being returned that has likes (or if likes currently enabled for item) so cannot limit number of rows since some items may not have read permissions for user
// No need to group by as user should only have 1 action per item
$sql = "SELECT type, subtype, id, created, action FROM {$_TABLES['likes']}
WHERE uid = {$uid}
ORDER BY created DESC";

$result = DB_Query($sql);
$nrows = DB_numRows($result);

$listCount = 0;
$likeItems = array();
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);

// Some items may not be set depending on current permissions set
// Ie at some point dislikes allowed but currently disabled so do not want to display old ones
$itemSet = false;

$options['sub_type'] = $A['subtype'];
$info = PLG_getItemInfo($A['type'], $A['id'], 'url,title,likes', 0, $options);
// If info returned then user has permission to view item
// If the item type, subtype, id have likes currently enabled
if (!empty($info[2]) && $info[2] > 0) {
$listCount++;
$likeDate = COM_getUserDateTimeFormat($A['created']);
$template->set_var ('row_number', $listCount . '.');
$title = COM_createLink($info[1], $info[0], array('class'=>'b'));
if ($A['action'] == LIKES_ACTION_LIKE) {
$title = sprintf($LANG_LIKES['title_liked'], $title);
} else {
$title = sprintf($LANG_LIKES['title_disliked'], $title);
}
$template->set_var('item_title', $title);
$template->set_var ('item_date', $likeDate[0]);

if ($listCount == 1) {
$template->parse('last10_rows', 'last10_row');
} else {
$template->parse('last10_rows', 'last10_row', true);
}

if ($listCount >= $listLimit) {
break;
}
}
}

if ($listCount == 0) {
$template->set_var('last10_rows', $LANG_LIKES['msg_no_likes']);
}
$template->parse('last10_blocks', 'last10_block', true);

// Cannot take just this as may include items the user viewing does not have access too
// Unfortunately to return a list of all items another user has liked that the current user has read access
// could use a lot of resources as items would have to be checked individually for permissions (since items could be made up of aritcles, comments, polls, pages, etc.)
$count = DB_count ($_TABLES['likes'], 'uid', $uid);

$template->set_var ('lang_number_field', $LANG_LIKES['total_num_likes']);
$template->set_var ('number_field', COM_numberFormat($count));
$template->parse('field_statistics', 'field_statistic', true);
}

8 changes: 6 additions & 2 deletions system/lib-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,13 @@ function PLG_profileExtrasSave($plugin = '', $uid = '')
*/
function PLG_profileVariablesDisplay($uid, $template)
{
global $_PLUGINS;
global $_CONF, $_PLUGINS;

require_once $_CONF['path_system'] . 'lib-likes.php';

foreach ($_PLUGINS as $pi_name) {
$all_plugins = array_merge($_PLUGINS, array('likes'));

foreach ($all_plugins as $pi_name) {
$function = 'plugin_profilevariablesdisplay_' . $pi_name;
if (function_exists($function)) {
$function ($uid, $template);
Expand Down
2 changes: 1 addition & 1 deletion system/lib-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ function USER_showProfile($uid, $preview = false, $msg = 0, $plugin = '')
$user_templates->set_var('customfields', CUSTOM_userDisplay($uid));
}

// See if other plugins want to add any extra profile informaiton
// See if other plugins want to add any extra profile information
PLG_profileVariablesDisplay($uid, $user_templates);

$user_templates->parse('output', 'profile');
Expand Down

0 comments on commit 822cfe0

Please sign in to comment.