TinyPortal

Development => Block Codes => Topic started by: Freddy on October 16, 2009, 05:42:31 PM

Title: [Block] Recent comments on articles.
Post by: Freddy on October 16, 2009, 05:42:31 PM
As per request here is a block that will show you the most recent comments made on your articles.  You can use this in a PHP article or block.

You can configure it to limit the number of comments to show.

I made this similar in appearance to the recent posts block code.

Demo here (http://aidreams.co.uk/forum/index.php?page=121)- not much there though as I stopped using comments as they tend to get lost, but with this maybe I will start using them again. Using my own system now, so no demo on my site.

// Block code to show recent comments made on articles.
// Freddy888 - with some of Bloc's layout code.

// *** Config ***

// Set the maximum number of comments to show.
$limit = 5;

// *** End Of Config ***


// Now the code..

global $scripturl, $db_prefix;

$request = db_query("
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.authorID, m.author, m.shortname, o.memberName
FROM {$db_prefix}tp_articles m
INNER JOIN {$db_prefix}tp_variables n
ON n.value5 = m.id INNER JOIN {$db_prefix}members o
ON n.value3 = o.ID_MEMBER
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC
LIMIT $limit
", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['memberName'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname']
);

// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' commented :</span>
</div>
<div style="overflow: auto">
' , $details['comment'] , '
</div>
</div>
</div>';
}

mysql_free_result($request);
Title: Re: [Block] Recent comments on articles.
Post by: dimdom on October 17, 2009, 11:39:44 AM
Excellent work freddy!

Here is my modified code to make it look better in a side block:

// Block code to show recent comments made on articles.
// Freddy888 - with some of Bloc's layout code.

// *** Config ***

// Set the maximum number of comments to show.
$limit = 5;

// *** End Of Config ***


// Now the code..

global $scripturl, $db_prefix;

$request = db_query("
SELECT n.value2, value3, value4, n.value5, m.subject, m.authorID, m.author, m.shortname, o.memberName
FROM {$db_prefix}tp_articles m
INNER JOIN {$db_prefix}tp_variables n
ON n.value5 = m.id INNER JOIN {$db_prefix}members o
ON n.value3 = o.ID_MEMBER
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC
LIMIT $limit
", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['memberName'] . '</a>',
'comment' => $row['value2'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname']
);

// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="smalltext"><span class="tp_thindivider"></span>
<span class="smalltext">' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' .

$details['subject'] . '</a>') , '</span>
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' ÏÆ'χολίαÏÆ'ε:</span>
</div>
<div style="overflow: auto">
<span class="smalltext">' , $details['comment'] , '</span>
</div>
</div>
</div>';
}

mysql_free_result($request);


No dates and smaller letters. Thats all. :)



Title: Re: [Block] Recent comments on articles.
Post by: Renegd98 on October 17, 2009, 01:16:37 PM
Nice work Freddy and dimdom...
Title: Re: [Block] Recent comments on articles.
Post by: mymistake on October 17, 2009, 01:25:36 PM
This is excellent - just what I was looking for. Thanks a lot!
Title: Re: [Block] Recent comments on articles.
Post by: Freddy on October 17, 2009, 01:42:47 PM
Thanks Renegd and well done Dimdom, that's perfect for side blocks :)

Glad it's okay mymistake, it was a good idea and worth doing.

The trickiest bit was the SQL, but it's good to learn new tricks  ^-^
Title: Re: [Block] Recent comments on articles.
Post by: Rus on May 18, 2011, 11:45:45 PM
Do you have any interest in updating this?  I'm going to hazard a guess that it doesn't work on either SMF2 or TP1 RC1 because I got errors with it.

Love the idea though.
Title: Re: [Block] Recent comments on articles.
Post by: IchBin on May 19, 2011, 03:37:16 PM
Updated code from first post. Post back if there are any errors.
// *** Config ***

// Set the maximum number of comments to show.
$limit = 5;

// *** End Of Config ***


// Now the code..

global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname']
);

// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' commented :</span>
</div>
<div style="overflow: auto">
' , $details['comment'] , '
</div>
</div>
</div>';
}

$smcFunc['db_free_result']($request);
Title: Re: [Block] Recent comments on articles.
Post by: Freddy on May 19, 2011, 03:56:27 PM
Well done IchBin.  I had this on my desktop to do but for most of the day I have had really bad eye strain or something.  I could barely open my left eye.  Feeling a lot better now though touch wood.
Title: Re: [Block] Recent comments on articles.
Post by: Rus on May 20, 2011, 10:18:53 PM
Worked great.  Thank you!
Title: Re: [Block] Recent comments on articles.
Post by: MrCare on August 06, 2012, 08:17:03 AM
How we can limit comment character?
Title: Re: [Block] Recent comments on articles.
Post by: IchBin on August 06, 2012, 03:50:27 PM
You can use substr() on any text to limit it. You can see the examples on this page.

http://php.net/manual/en/function.substr.php
Title: Re: [Block] Recent comments on articles.
Post by: MrCare on August 06, 2012, 05:28:41 PM
</div>
' , strlen($details['comment']) > 47 ? substr($details['comment'], 0, 47) .'... ' : $details['comment'] , '
</div>
</div>
</div>';
}

$smcFunc['db_free_result']($request);


hope anybody can help ... tq
Title: Re: [Block] Recent comments on articles.
Post by: IchBin on August 06, 2012, 06:29:01 PM
What do you need help with?
Title: Re: [Block] Recent comments on articles.
Post by: blu4lyf on August 12, 2012, 06:22:42 PM
I decided to share my variation of this block of code, in case anybody else is interested in it.  Changes I made are as follows: // *** Config ***

// Set the maximum number of comments to show.
$limit = 5;
$commlim = 60;

// *** End Of Config ***


// Now the code..

global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.real_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['real_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
             $details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="font-size: smaller;">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext" style="font-size: smaller;">
<div class="tp_details" style="overflow: auto">
<span class="smalltext" style="font-size: xx-small;">' , $details['commenter'] , ' commented :</span><br />
' , $details['comment'] , '
</div>
</div>
</div>';
}

$smcFunc['db_free_result']($request);
Title: Re: [Block] Recent comments on articles.
Post by: Rus on January 31, 2013, 06:06:19 PM
Thanks!  Just used this version and changed the formatting back to regular size.  The biggest thing I liked more was using the Screen names instead of logins.  :)
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 12, 2018, 09:37:34 AM
Hi,

I found this code which is nearly perfect for me. However, if a comment is posted by a guest, the comment is not showing in this block.

What needs to be changed / added to also show the guest comments?

   
   
// *** Config ***

// Set the maximum number of comments to show.
$limit = 25;
$commlim = 90;

// *** End Of Config ***


// Now the code..

global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
             $details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="font-size: large;">


' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><B>
<div class="">On
<span class="tp_thindivider"></span>
<span class="">' , date("l",$details['date']) , '</span>
<span class="">' , date("d",$details['date']) , '</span>
<span class="">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class=""> ' , date("Y",$details['date']) , '</span>
<span class=""> ' , date("H:i:s",$details['date']) , '</span>
<span class="tp_day"> ' , $details['commenter'] , '</span>
<span class="">commented: </B></span>

<div class="" style="color: #330000; font-size: 16px""><br>

' , $details['comment'] , '

</div>
<br></div>';
}


$smcFunc['db_free_result']($request);
Title: Re: [Block] Recent comments on articles.
Post by: @rjen on November 12, 2018, 04:10:08 PM
You are using an inner join on the member table. Guests are not members so will not be included. Try a left OUTER join instead...
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 12, 2018, 06:50:05 PM
Thanks @rjen,

Changing

      INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
      INNER JOIN {db_prefix}members o ON n.value3 = o.id_member

into

      LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
      LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member

was indeed the solution.

Do you know what I should add to show "Guest" in case a guest comment is posted?

(https://www.tinyportal.net/index.php?action=dlattach;topic=31176.0;attach=27883;image)

Title: Re: [Block] Recent comments on articles.
Post by: tino on November 12, 2018, 08:33:54 PM


IFNULL(o.member_name, 'Guest') AS member_name

Title: Re: [Block] Recent comments on articles.
Post by: @rjen on November 12, 2018, 08:35:17 PM
Quote from: tino on November 12, 2018, 08:33:54 PM


IFNULL(o.member_name, 'Guest') AS member_name



Better try...



IFNULL(o.member_name, $txt['tp-guest']) AS member_name


Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 12, 2018, 09:01:43 PM
Oh that's great..... but where do I place this code?
Title: Re: [Block] Recent comments on articles.
Post by: tino on November 12, 2018, 11:29:23 PM
Quote from: wildenborch on November 12, 2018, 09:01:43 PM
Oh that's great..... but where do I place this code?

In the SQL in place of the o.memer_name
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 13, 2018, 06:31:23 AM
Hi Tino

You refer to this part?

      SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name

and change it into:


      SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, IFNULL(o.member_name, 'Guest') AS member_name
   
That does not seem to work.



Title: Re: [Block] Recent comments on articles.
Post by: tino on November 13, 2018, 08:22:32 PM

SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, IFNULL(o.member_name, 'Guest') AS member_name
FROM smf_tp_articles m
LEFT OUTER JOIN smf_tp_variables n ON n.value5 = m.id
LEFT OUTER JOIN smf_members o ON n.value3 = o.id_member
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC


Works for me on my test site.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 13, 2018, 09:21:04 PM
I copied this code into my php block but it does not show any results.

Can you post the complete code block?
Title: Re: [Block] Recent comments on articles.
Post by: tino on November 13, 2018, 09:23:37 PM
I only ran it on the MySQL Server, but it changes the member_name to guest as I would expect.

The line with the SELECT is the only one I changed from the code block.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 13, 2018, 09:33:17 PM
Ah I see.

Well it's not so important (no commenter is a guest comment).

If - in the future - you have some time to look into the code it would be a nice block to implement as a predefined block in a future release.
Title: Re: [Block] Recent comments on articles.
Post by: @rjen on November 14, 2018, 08:37:32 AM
This one works...

I made a few layout changes too because it was quite bulky in the side block but you get the idea...


// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***

// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
      LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
      LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname'],
        'id' => $row['value3']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
             $details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">

' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] <> 0) ? $details['commenter']  :  $txt['tp-guest']) , '</b></span>

<span class="">commented: </B></span>

<div class="" style="color: #330000; font-size: 16px""><br>

' ,$details['comment'], '

</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);
Title: Re: [Block] Recent comments on articles.
Post by: tino on November 14, 2018, 11:51:54 AM
(($details['id'] <> 0) ?  That looks wrong, shouldn't it be > 0
Title: Re: [Block] Recent comments on articles.
Post by: @rjen on November 14, 2018, 12:17:49 PM
Quote from: tino on November 14, 2018, 11:51:54 AM
(($details['id'] <> 0) ?  That looks wrong, shouldn't it be > 0
That will work too...
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on November 14, 2018, 12:49:32 PM
Yes this is perfect!

Thank you very much @rjen and Tino!

And for future support requests I shall mention:

"Well it's not so important ....
If - in the future - you have some time to look into it the code it would be a nice .....

;D
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 15, 2021, 11:57:17 AM
Hi Arjan, Tino,

I assume that with TP version 2 the code for showing the comments is no longer working?

// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***

// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
      LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
      LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' =>  $row['subject'],
'query' => $row['shortname'],
        'id' => $row['value3']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
             $details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">

' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] > 0) ? $details['commenter']  :  $txt['tp-guest']) , '</b></span>

<span class="">commented: </B></span>

<div class="" style="color: #330000; font-size: 16px""><br>

' ,$details['comment'], '

</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);


What should be changed to make it working again?


Title: Re: [Block] Recent comments on articles.
Post by: @rjen on March 15, 2021, 04:20:01 PM
What makes you assume that?
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 15, 2021, 05:32:00 PM
Quote from: @rjen on March 15, 2021, 04:20:01 PM
What makes you assume that?

Probably the fact I moved the article comments to their own table. The table is now tp_comments and is mapped as per this change.

https://github.com/Tinyportal/TinyPortal/blob/7b6c194a411f3187004f6c5a50b41a41a751214d/install.php#L985

So all the value# need to be changed to their respective new column name and the block updated accordingly.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 15, 2021, 05:40:43 PM
And I assume that this commmand is affected by this change as well?

index.php?action=tportal;sa=showcomments;showall

this was

index.php?action=tpmod;sa=showcomments;showall
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 15, 2021, 06:22:23 PM
Yes tpmod was changed tportal in a lot of instances. Or if it was an admin area it's tpadmin now.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 15, 2021, 10:28:24 PM
But have you an idea why index.php?action=tportal;sa=showcomments;showall isn't working (not showing any comment)?

Fred
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 15, 2021, 10:45:30 PM
Quote from: wildenborch on March 15, 2021, 10:28:24 PM
But have you an idea why index.php?action=tportal;sa=showcomments;showall isn't working (not showing any comment)?

Fred

Looking at the code. It seems it was missed in the updates. Not even sure how it's actually called atm, other than manually.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 17, 2021, 01:13:43 PM
Hi Tino,

I really tried it but I really don't know what I'm doing and what to change or delete.

If you have some time, would you mind changing the script?

Fred 
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 17, 2021, 04:40:47 PM
I'll look at it this weekend. The comments one will be a new patch release, probably 2.0.2. I don't know of any other bugs in that one so it might be a while before it's officially released, you can take the earlier release mind.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 17, 2021, 05:02:47 PM
Thank you Tino.

Title: Re: [Block] Recent comments on articles.
Post by: tino on March 17, 2021, 05:51:22 PM
Quote from: wildenborch on March 17, 2021, 05:02:47 PM
Thank you Tino.

That should fix your articleShowComments issue, its in TPArticle, just replace it with the below.

Code (php) Select
<?php

function articleShowComments() {{{
    global 
$smcFunc$scripturl$user_info$txt$context;

    if(!empty(
$_GET['tpstart']) && is_numeric($_GET['tpstart'])) {
        
$tpstart $_GET['tpstart'];
    }
    else {
        
$tpstart 0;
    }

    
$mylast 0;
    
$mylast $user_info['last_login'];
    
$showall false;
    if(isset(
$_GET['showall'])) {
        
$showall true;
    }

    
$request $smcFunc['db_query']('''
        SELECT COUNT(var.subject)
        FROM ({db_prefix}tp_comments AS var, {db_prefix}tp_articles AS art)
        WHERE var.item_type = {string:type}
        ' 
. ((!$showall || $mylast == 0) ? 'AND var.datetime > '.$mylast '') .'
        AND art.id = var.item_id'
,
        array(
'type' => 'article_comment')
    );
    
$check $smcFunc['db_fetch_row']($request);
    
$smcFunc['db_free_result']($request);

    
$request $smcFunc['db_query']('''
        SELECT art.subject, memb.real_name AS author, art.author_id AS author_id, var.subject, var.comment, var.member_id,
        var.item_id, var.datetime, mem.real_name AS real_name,
        ' 
. ($user_info['is_guest'] ? '1' '(COALESCE(log.item, 0) >= var.datetime)') . ' AS isRead
        FROM ({db_prefix}tp_comments AS var, {db_prefix}tp_articles AS art)
        LEFT JOIN {db_prefix}members AS memb ON (art.author_id = memb.id_member)
        LEFT JOIN {db_prefix}members AS mem ON (var.member_id = mem.id_member)
        LEFT JOIN {db_prefix}tp_data AS log ON (log.value = art.id AND log.type = 1 AND log.id_member = '
.$context['user']['id'].')
        WHERE var.item_type = {string:type}
        AND art.id = var.item_id
        ' 
. ((!$showall || $mylast == ) ? 'AND var.datetime > {int:last}' '') .'
        ORDER BY var.datetime DESC LIMIT {int:start}, 15'
,
        array(
'type' => 'article_comment''last' => $mylast'start' => $tpstart)
    );

    
$context['TPortal']['artcomments']['new'] = array();

    if(
$smcFunc['db_num_rows']($request) > 0) {
        while(
$row=$smcFunc['db_fetch_assoc']($request)) {
            
$context['TPortal']['artcomments']['new'][] = array(
                
'page' => $row['item_id'],
                
'subject' => $row['subject'],
                
'title' => $row['subject'],
                
'comment' => $row['comment'],
                
'membername' => $row['real_name'],
                
'time' => timeformat($row['datetime']),
                
'author' => $row['author'],
                
'author_id' => $row['authorID'],
                
'member_id' => $row['member_id'],
                
'is_read' => $row['isRead'],
                
'replies' => $check[0],
            );
        }
        
$smcFunc['db_free_result']($request);
    }

    
// construct the pages
    
$context['TPortal']['pageindex']        = TPageIndex($scripturl.'?action=tportal;sa=showcomments'$tpstart$check[0], 15);
    
$context['TPortal']['unreadcomments']   = true;
    
$context['TPortal']['showall']          = $showall;
    
TPadd_linktree($scripturl.'?action=tportal;sa=showcomments' . ($showall ';showall' '')  , $txt['tp-showcomments']);
    
loadTemplate('TParticle');
    
$context['sub_template'] = 'showcomments';
    if(
loadLanguage('TParticle') == false) {
        
loadLanguage('TParticle''english');
    };

}}}

?>
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 17, 2021, 05:54:11 PM
The block code you need to replace value1 with subject, value2 with comment, value3 with member_id, value4 with datetime, value5 with item_id, n.type with n.item_type and that should be it.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 17, 2021, 08:06:45 PM
Thank you very much Tino!

I changed the code in TPArticle.php and this is working.
index.phpindex.php?action=tportal;sa=showcomments;showall;showall will show 15 comments.

I noticed that if you have more then 15 comments you have the possibility to go to page 2 (or 3 etc) but that is not working properly. In fact is will show the result of ?action=tportal;sa=showcomments;showall 







Fred
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 17, 2021, 08:11:52 PM
The block code you need to replace value1 with subject, value2 with comment, value3 with member_id, value4 with datetime, value5 with item_id, n.type with n.item_type and that should be it.

I changed the block code into this and this is working perferct!

// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***

// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;

$request = $smcFunc['db_query']('', '
SELECT comment, member_id, datetime, item_id, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
      LEFT OUTER JOIN {db_prefix}tp_comments n ON item_id = m.id
      LEFT OUTER JOIN {db_prefix}members o ON member_id = o.id_member
WHERE n.item_type = {string:type}
ORDER BY datetime DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['member_id'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['comment'],
'date' => $row['datetime'],
'articleid' => $row['item_id'],
'subject' =>  $row['subject'],
'query' => $row['shortname'],
        'id' => $row['member_id']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
             $details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">

' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] > 0) ? $details['commenter']  :  $txt['tp-guest']) , '</b></span>

<span class="">commented: </B></span>

<div class="" style="color: #330000; font-size: 16px""><br>

' ,$details['comment'], '

</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);
Title: Re: [Block] Recent comments on articles.
Post by: tino on March 17, 2021, 09:29:28 PM
Quote from: wildenborch on March 17, 2021, 08:06:45 PM
Thank you very much Tino!

I changed the code in TPArticle.php and this is working.
index.phpindex.php?action=tportal;sa=showcomments;showall;showall will show 15 comments.

I noticed that if you have more then 15 comments you have the possibility to go to page 2 (or 3 etc) but that is not working properly. In fact is will show the result of ?action=tportal;sa=showcomments;showall 


Fred

Has that ever worked? I can't see in the logic how it did previously.
Title: Re: [Block] Recent comments on articles.
Post by: wildenborch on March 17, 2021, 10:54:06 PM
I really don't know. I started to use the scrip because of the layout.