TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

December 04, 2024, 08:47:53 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,443
  • Total Topics: 21,252
  • Online today: 171
  • Online ever: 6,457 (November 30, 2024, 02:40:09 PM)
Users Online
  • Users: 1
  • Guests: 74
  • Total: 75
  • @rjen

[Block] Recent comments on articles.

Started by freddy888, October 16, 2009, 05:42:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wildenborch


tino

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');
    };

}}}

?>

tino

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.

wildenborch

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

wildenborch

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);

tino

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.

wildenborch

I really don't know. I started to use the scrip because of the layout.