Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

July 30, 2021, 05:21:18 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 192346
  • Total Topics: 20981
  • Online Today: 139
  • Online Ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 101
Total: 101

Author Topic: [Block] Recent comments on articles.  (Read 31401 times)

0 Members and 1 Guest are viewing this topic.

Offline wildenborch

  • Support Team
  • *
  • Posts: 359
Re: [Block] Recent comments on articles.
« Reply #40 on: March 17, 2021, 11:02:47 AM »
Thank you Tino.


Offline tino

  • Developer
  • *
  • Posts: 2367
Re: [Block] Recent comments on articles.
« Reply #41 on: March 17, 2021, 11:51:22 AM »
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');
    };

}}}

?>

Offline tino

  • Developer
  • *
  • Posts: 2367
Re: [Block] Recent comments on articles.
« Reply #42 on: March 17, 2021, 11:54:11 AM »
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.

Offline wildenborch

  • Support Team
  • *
  • Posts: 359
Re: [Block] Recent comments on articles.
« Reply #43 on: March 17, 2021, 02: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

Offline wildenborch

  • Support Team
  • *
  • Posts: 359
Re: [Block] Recent comments on articles.
« Reply #44 on: March 17, 2021, 02:11:52 PM »
Code: [Select]
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!

Code: [Select]
// *** 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);

Offline tino

  • Developer
  • *
  • Posts: 2367
Re: [Block] Recent comments on articles.
« Reply #45 on: March 17, 2021, 03:29:28 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.

Offline wildenborch

  • Support Team
  • *
  • Posts: 359
Re: [Block] Recent comments on articles.
« Reply #46 on: March 17, 2021, 04:54:06 PM »
I really don't know. I started to use the scrip because of the layout.