Skip to content

Commit

Permalink
updates to forum likes and mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
jessewoo committed Feb 5, 2025
1 parent a9acf29 commit 3229547
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 78 deletions.
5 changes: 5 additions & 0 deletions core/components/com_forum/api/controllers/likesv1_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function addLikeToPostTask()
$userId = Request::getString('userId');
$created = Date::of('now')->toSql();

if (!userId || (userId === 0))
{
throw new Exception("Please sign into post a Like", 404);
}

$db = \App::get('db');
$insertQuery = "INSERT INTO `#__forum_posts_like` (`threadId`, `postId`, `userId`, `created`)
VALUES (?,?,?,?)";
Expand Down
9 changes: 5 additions & 4 deletions core/components/com_forum/site/controllers/threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,11 @@ public function saveTask()
$domComment->loadHTML($fields['comment']);
$mentionEmailList = array();
foreach ($domComment->getElementsByTagName('a') as $item) {
$hrefLink = $item->getAttribute('href');
if (strpos($hrefLink, 'mailto:') !== false) {
$mentionEmailList[] = str_replace('mailto:', "", $hrefLink);
}
$userId = $item->getAttribute('data-user-id');
$user = User::getInstance($userId);
$email = $user->get('email');

$mentionEmailList[] = $email;
}

// Authorization check
Expand Down
69 changes: 36 additions & 33 deletions core/components/com_forum/site/views/threads/tmpl/_comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,44 @@
<?php echo $comment; ?>

<!-- Heart and "Like" link Button -->
<div class="elementInline likeContainer">
<a class="icon-heart like <?php if ($userLikesComment) { echo "userLiked"; } ?>" href="#"
data-thread="<?php echo $this->thread->get('id'); ?>"
data-post="<?php echo $this->comment->get('id'); ?>"
data-user="<?php echo User::get('id'); ?>"
data-user-name="<?php echo User::get('name'); ?>"
data-likes-list="<?php echo $userNameLikesArray; ?>"
data-count="<?php echo $countLike; ?>"
></a>
<span class="likesStat <?php if ($countLike==0) { echo "noLikes"; } ?>">
<?php echo ($countLike>0) ? "View Likes (" . $countLike . ")" : "No Likes"; ?>
</span>
</div>
<div class="clear"></div>
<!-- Only show if people is logged in -->
<?php if (!User::isGuest()) { ?>
<div class="elementInline likeContainer">
<a class="icon-heart like <?php if ($userLikesComment) { echo "userLiked"; } ?>" href="#"
data-thread="<?php echo $this->thread->get('id'); ?>"
data-post="<?php echo $this->comment->get('id'); ?>"
data-user="<?php echo User::get('id'); ?>"
data-user-name="<?php echo User::get('name'); ?>"
data-likes-list="<?php echo $userNameLikesArray; ?>"
data-count="<?php echo $countLike; ?>"
></a>
<span class="likesStat <?php if ($countLike==0) { echo "noLikes"; } ?>">
<?php echo ($countLike>0) ? "View Likes (" . $countLike . ")" : "No Likes"; ?>
</span>
</div>
<div class="clear"></div>

<div class="whoLikedPost">
<?php if (strlen($userNameLikesArray) > 0) { ?>
<div class="names">
<?php
$nameArray = preg_split("#/#", $userNameLikesArray);
$links = array();
foreach ($nameArray as $nameString)
{
$nameArray = explode("#", $nameString);
$userName = $nameArray[0];
$userId = $nameArray[1];
$userProfileUrl = "/members/$userId/profile";
<div class="whoLikedPost">
<?php if (strlen($userNameLikesArray) > 0) { ?>
<div class="names">
<?php
$nameArray = preg_split("#/#", $userNameLikesArray);
$links = array();
foreach ($nameArray as $nameString)
{
$nameArray = explode("#", $nameString);
$userName = $nameArray[0];
$userId = $nameArray[1];
$userProfileUrl = "/members/$userId/profile";

$links[] = "<a href=$userProfileUrl target='_blank'>$userName</a>";
}
echo join(", ", $links) . " liked this";
?>
</div>
<?php } ?>
</div>
$links[] = "<a href=$userProfileUrl target='_blank'>$userName</a>";
}
echo join(", ", $links) . " liked this";
?>
</div>
<?php } ?>
</div>
<?php } ?>

</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
'minChars' => 0,
'feed' => '/api/members/mentions/list?search={encodedQuery}',
'itemTemplate' => '<li data-id="{id}"><img class="photo" src="{picture}" /><strong class="username">{username}</strong><span class="fullname">{name}</span></li>',
'outputTemplate' => '<a href="mailto:{email}">@{username}</a><span>&nbsp;</span>',
'outputTemplate' => '<a href="/members/{id}" data-user-id="{id}" target="_blank">@{username}</a>&nbsp;&nbsp;',
)
)
)); ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function listTask() {
$entries = Member::all()
->whereEquals('block', 0)
->whereEquals('activation', 1)
->where('email', '!=', '[email protected]')
->where('approved', '>', 0);

if ($search) {
Expand Down
9 changes: 5 additions & 4 deletions core/plugins/groups/forum/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,11 @@ public function savethread()
$domComment->loadHTML($fields['comment']);
$mentionEmailList = array();
foreach ($domComment->getElementsByTagName('a') as $item) {
$hrefLink = $item->getAttribute('href');
if (strpos($hrefLink, 'mailto:') !== false) {
$mentionEmailList[] = str_replace('mailto:', "", $hrefLink);
}
$userId = $item->getAttribute('data-user-id');
$user = User::getInstance($userId);
$email = $user->get('email');

$mentionEmailList[] = $email;
}

if (!$this->params->get('access-edit-thread')
Expand Down
75 changes: 40 additions & 35 deletions core/plugins/groups/forum/views/threads/tmpl/_comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,48 @@
<?php echo $comment; ?>

<!-- Heart and "Like" link Button -->
<div class="elementInline likeContainer">
<a class="icon-heart like <?php if ($userLikesComment) { echo "userLiked"; } ?>" href="#"
data-thread="<?php echo $this->thread->get('id'); ?>"
data-post="<?php echo $this->comment->get('id'); ?>"
data-user="<?php echo User::get('id'); ?>"
data-user-name="<?php echo User::get('name'); ?>"
data-likes-list="<?php echo $userNameLikesArray; ?>"
data-count="<?php echo $countLike; ?>"
></a>
<span class="likesStat <?php if ($countLike==0) { echo "noLikes"; } ?>">
<?php echo ($countLike>0) ? "View Likes (" . $countLike . ")" : "No Likes"; ?>
</span>
</div>

<div class="clear"></div>

<div class="whoLikedPost">
<?php if (strlen($userNameLikesArray) > 0) { ?>
<div class="names">
<?php
$nameArray = preg_split("#/#", $userNameLikesArray);
$links = array();

foreach ($nameArray as $nameString)
{
$nameArray = explode("#", $nameString);
$userName = $nameArray[0];
$userId = isset($nameArray[1]) ? $nameArray[1] : '0';
$userProfileUrl = "/members/$userId/profile";
<!-- Only show if people is logged in -->
<?php if (!User::isGuest()) { ?>
<div class="elementInline likeContainer">
<a class="icon-heart like <?php if ($userLikesComment) { echo "userLiked"; } ?>" href="#"
data-thread="<?php echo $this->thread->get('id'); ?>"
data-post="<?php echo $this->comment->get('id'); ?>"
data-user="<?php echo User::get('id'); ?>"
data-user-name="<?php echo User::get('name'); ?>"
data-likes-list="<?php echo $userNameLikesArray; ?>"
data-count="<?php echo $countLike; ?>"
></a>
<span class="likesStat <?php if ($countLike==0) { echo "noLikes"; } ?>">
<?php echo ($countLike>0) ? "View Likes (" . $countLike . ")" : "No Likes"; ?>
</span>
</div>

$links[] = "<a href=$userProfileUrl target='_blank'>$userName</a>";
}
echo join(", ", $links) . " liked this";
?>
<div class="clear"></div>

<div class="whoLikedPost">
<?php if (strlen($userNameLikesArray) > 0) { ?>
<div class="names">
<?php
$nameArray = preg_split("#/#", $userNameLikesArray);
$links = array();

foreach ($nameArray as $nameString)
{
$nameArray = explode("#", $nameString);
$userName = $nameArray[0];
$userId = isset($nameArray[1]) ? $nameArray[1] : '0';
$userProfileUrl = "/members/$userId/profile";

$links[] = "<a href=$userProfileUrl target='_blank'>$userName</a>";
}
echo join(", ", $links) . " liked this";
?>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>


</div>

<div class="comment-attachments">
Expand Down
2 changes: 1 addition & 1 deletion core/plugins/groups/forum/views/threads/tmpl/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
'minChars' => 0,
'feed' => $feedUrl,
'itemTemplate' => '<li data-id="{id}"><img class="photo" src="{picture}" /><strong class="username">{username}</strong><span class="fullname">{name}</span></li>',
'outputTemplate' => '<a href="mailto:{email}">@{username}</a><span>&nbsp;</span>',
'outputTemplate' => '<a href="/members/{id}" data-user-id="{id}" target="_blank">@{username}</a>&nbsp;&nbsp;',
)
)
)); ?>
Expand Down

0 comments on commit 3229547

Please sign in to comment.