Tinyportal / TinyPortal

A portal mod for Simple Machines Forum
www.tinyportal.net
Mozilla Public License 2.0
20 stars 14 forks source link

Add count option for article comments to be used on frontpanel and category pages #637

Closed Bopske closed 4 years ago

Bopske commented 4 years ago

Not an issue, but a question. I added the comments counter on article pages in this commit. https://github.com/Tinyportal/TinyPortal/pull/588/commits/4b00dd78a631ab7d10b28b59842c203f0b6a395b

In order to also show the comment counter on the frontpage and the category views we would need a function that counts the comments per articles there too. I did not manage to get that working. Tino, would you be willing to add that in?

tinoest commented 4 years ago
            $tpArticle  = TPArticle::getInstance();
            $articles   = $tpArticle->getArticle($aposts);

returns the number of comments along with all the other article data.

If you just want the article comments then you can call this.

            $tpArticle  = TPArticle::getInstance();
            $tpArticle->getArticleData('comments', array( 'id' => $article_id));

I don't know where you want it added so thought it best to give you examples.

Bopske commented 4 years ago

Thanks, I’ll have a look maybe I need some more directions. If so I’ll ask here ...

Bopske commented 4 years ago

Did some digging, but I am sorry, this exceeds my coding skills.

What I want is to use the $context['TPortal']['article_comments_count'] here to be populated also when on the Frontpage or Category view. (If that gets populated I can sort out the display in the template)

File: TPsubs.template.php, function article_comments_total

That must be populated from TPortal.php: function doTPfrontpage() and function doTPcat() these do not provide the 'article_comments_count' to the context. So I assume this function should go in there, but how and where...

This is the function that I think should be called from Base.php: public function getArticleComments($user_id, $item_id) {{{ return parent::getComments('1', $user_id, $item_id); }}}

I am sorry: I just lack the coding skills, so unless you can add it in in the right place we'll have to do without...

tinoest commented 4 years ago

Adding $context['TPortal']['article_comments_count'] doesn't make anything show on the front page. I can do that easily enough for each article, it just does nothing?

The functions you want for the comment count are the two I posted above, the one you put gets all the comments for that article. Or is that what you want?

tinoest commented 4 years ago

I "think" what you wanted to do is this.

function article_comments_total($render = true)
{
    global $scripturl, $txt, $context;

    $data = '';

    if(in_array('comments', $context['TPortal']['article']['visual_options']) && (isset($context['TPortal']['article']['comments']))) {
        $data = '
        <span class="article_comments">' .  $txt['tp-comments'] . ':  ' . $context['TPortal']['article']['comments'] . '</span>';
    }
    elseif(in_array('comments', $context['TPortal']['article']['visual_options']) && (empty($context['TPortal']['article']['comments']))) {
        $data = '
        <span class="article_comments"><a href="' . $scripturl . '?page=' . (!empty($context['TPortal']['article']['shortname']) ? $context['TPortal']['article']['shortname'] : $context['TPortal']['article']['id']) . '">' . $txt['tp-comments'] . '</a></span>';
    }

    if($render) {
        echo $data;
    }   
    else {
        return $data;
    }   
}   
Bopske commented 4 years ago

What I want do do is make the comment count information available to show for each article, both on the article page (page=xx) as on the category pages (cat=yy) and when an article is on the frontpage.

I cannot describe it any clearer than that.. I am sorry, but it is a bit frustrating not being able to explain better...

I got it to show on the article page

2020-06-14_163030

But not on the cat page and the frontpage: simply because the "comment counter" is not availabe there...

2020-06-14_163100

tinoest commented 4 years ago

I think the code I just posted does that on the front page? Although I liked having the link there myself.

Bopske commented 4 years ago

Let me try yout code: it did not seem that much different from what I had, maybe I missed something...

Bopske commented 4 years ago

I must be a complete pain in the ... your code was exactly what I was looking for. I cannot understand why I did not get that working in the first place. I must have been blind or something...

tinoest commented 4 years ago

I must be a complete pain in the ... your code was exactly what I was looking for. I cannot understand why I did not get that working in the first place. I must have been blind or something...

Not a pain at all, I was just confused with what you were trying to do when the data was already there. I thought I was missing something obvious.

Bopske commented 4 years ago

I am afraid I was (confused that is): I was so much focussing on using the variable $context['TPortal']['article_comments_count'] that I completely missed that variable $context['TPortal']['article']['comments'] was readily available with exactly the information is needed...