collective / collective.disqus

Integration of Disqus Service into Plone. Disqus is a comment plateform
3 stars 7 forks source link

best way to implement a comment counter for an object? #3

Closed hvelarde closed 11 years ago

hvelarde commented 12 years ago

Disqus provides an easy-to-use JavaScript code snippet which will fetch the comment counts for desired threads and then display them with your page links. This is typically used on the main or index page of a website or blog.

See http://help.disqus.com/customer/portal/articles/472106-how-do-i-get-comment-counts-on-the-main-or-index-page- for more information.

frisi commented 12 years ago

a viewlet would not help a lot since comment counts are needed for each item that can have comments. (eg each news item in a folder listing)

iirc the package already contains a customized version of folder_summary_view (with hard-coded disqus api shortnames)

of our homepage, i adapted folder_summary_view with the following changes:

...

                    <p class="tileFooter">
                        <a href="" class="disqus"
                           data-disqus-identifier="see http://docs.disqus.com/developers/universal/"
                           tal:attributes="href string:${item_url}#disqus_thread;
                                           data-disqus-identifier item_object/UID;"
                           i18n:translate=""
                           i18n:domain="collective.disqus">Comments are loading</a>
                        <span class="more"><a href=""
                           tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);"
                           i18n:translate="read_more">
                        Read More&hellip;
                        </a></span>
                    </p>

...
        </metal:definitions>
        <script type="text/javascript"
                tal:define="shortname python:context.portal_url.getPortalObject().forum_id or 'unknown'"
                tal:content="string:var disqus_shortname = '${shortname}';">
            /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
            var disqus_shortname = '<set by system settings>'; // required: replace example with your forum shortname
        </script>

        <script type="text/javascript">
            /* * * DON'T EDIT BELOW THIS LINE * * */
            (function () {
                var s = document.createElement('script'); s.async = true;
                s.type = 'text/javascript';
                s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
                (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
            }());
        </script>

        </metal:listingmacro>
....
hvelarde commented 12 years ago

I think this is a different use case, and a very valid also; what I want to implement with the viewlet is a way to show readers how many comments has a piece of content near its header.

hvelarde commented 12 years ago

also there's another use case: I want to know how many comments does a content has on a frontpage; solving this using Disqus javascript will be slow as we will need to open a new connection for every item.

seems to me we need both solutions: JavaScript and Python based.

@Quimera , @frapell , comments?

hvelarde commented 12 years ago

comment counter universal code could be found here: http://vtvtesting.disqus.com/admin/universal/

current code implements the HTML5 async attribute on the script tag, so seems loading should be faster enough... I don't know.

frapell commented 11 years ago

@frisi I'm about to implement this and I'm thinking if it makes sense to provide a customized folder_summary_view, or any default Plone view for that matter... I see a bunch of down-sides on doing that. To name a few:

For closing this ticket, I propose to implement a viewlet that will provide the count.js and the link with the #disqus_thread, without registering it to any viewlet manager. Then, document how to register the viewlet to be shown where each person wants it, and also document what needs to be added to a custom folder_summary_view or any Plone customized template, in order to include it in listings and such.

What do you think ?

frisi commented 11 years ago

summary view with comments

i'd go for an additional view disqus_summary_view (available for folders and collections). this way people can decide whether they want to use it or not. if they use it, a comment count is fetched for every item (which will fit 95% of the usecases anyway)

to go for the other 5% where people mix items with comments and w/o in the same listing you could also check if comments are allowed for every item or add a marker interface for disqus commentable types (much like contentleadimage does). however, this would mean not relying on plone's default commenting settings any longer. personally, i'd skip this for the start

the question of positioning does not matter that much i think, as diazo is getting more and more popular.

if you don't implement the view with this ticket, please add another feature with a link to this issue so the work/comments on this do not get lost.

viewlet

a) you can register the viewlet for a certain marker interface and add a configuration to the control panel where integrators can choose which content types to show the viewlet for (collective.contentleadimage has the same approach afaik)

b) alternatively you can register for all interfaces and hide or show it on the installation. the viewlet will be empty if the content item has comments turned off and will return "n comments" in case commenting is turned on. so all integrators will have to do is do hide/show the viewlet in viewlets.xml or via @@manage-viewlets

both are valid solutions. we should just be consitent (i.e. take the same approach for the disqus_summary_view as explained above)

hvelarde commented 11 years ago

:+1:

and please, don't forget to update the documentation ;-)