All Projects → KnpLabs → KnpDisqusBundle

KnpLabs / KnpDisqusBundle

Licence: MIT License
A Symfony bundle to fetch and render disqus comments via their API. Your SEO other-half will love it.

Programming Languages

PHP
23972 projects - #3 most used programming language
Twig
543 projects

Projects that are alternatives of or similar to KnpDisqusBundle

LiipMultiplexBundle
[DEPRECATED] Symfony2 controller that allows calling multiple URL's in one request as well as JSON-ifying any controller
Stars: ✭ 12 (-80.65%)
Mutual labels:  symfony-bundle
routing-auto-bundle
Adding automatic route generating on top of the symfony cmf routing
Stars: ✭ 14 (-77.42%)
Mutual labels:  symfony-bundle
domain-event-bundle
Library to create the domain layer of your DDD application
Stars: ✭ 14 (-77.42%)
Mutual labels:  symfony-bundle
eav-bundle
A Symfony bundle for basic EAV management
Stars: ✭ 19 (-69.35%)
Mutual labels:  symfony-bundle
DunglasTorControlBundle
Integration of PHP TorControl library in Symfony
Stars: ✭ 13 (-79.03%)
Mutual labels:  symfony-bundle
hcaptcha-bundle
A Symfony 4+ bundle to bring hCaptcha into your forms
Stars: ✭ 15 (-75.81%)
Mutual labels:  symfony-bundle
ParamConverterBundle
This bundle provides additional param converters for Symfony.
Stars: ✭ 16 (-74.19%)
Mutual labels:  symfony-bundle
time-ago-bundle
Provides a simple twig filter for expressing time difference in words.
Stars: ✭ 13 (-79.03%)
Mutual labels:  symfony-bundle
SonataTranslationBundle
SonataTranslationBundle
Stars: ✭ 72 (+16.13%)
Mutual labels:  symfony-bundle
mongodb-migrations-bundle
Symfony MongoDBMigrationsBundle
Stars: ✭ 21 (-66.13%)
Mutual labels:  symfony-bundle
LolautruchePaylineBundle
Symfony integration for Payline payment system
Stars: ✭ 15 (-75.81%)
Mutual labels:  symfony-bundle
AutoFormBundle
Automate Symfony form building
Stars: ✭ 68 (+9.68%)
Mutual labels:  symfony-bundle
acl-bundle
Integrates the ACL Security component into Symfony applications.
Stars: ✭ 91 (+46.77%)
Mutual labels:  symfony-bundle
block-bundle
Extends the SonataBlockBundle to integrate with PHPCR ODM
Stars: ✭ 20 (-67.74%)
Mutual labels:  symfony-bundle
health-check-bundle
A bundle that provides a simple /healthcheck route
Stars: ✭ 27 (-56.45%)
Mutual labels:  symfony-bundle
LexikCronFileGeneratorBundle
This symfony bundle provides service for generate cron file
Stars: ✭ 20 (-67.74%)
Mutual labels:  symfony-bundle
BeelabUserBundle
👥 Simple user management for Symfony.
Stars: ✭ 17 (-72.58%)
Mutual labels:  symfony-bundle
doctrine-json-odm
JSON Object-Document Mapping bundle for Symfony and Doctrine
Stars: ✭ 15 (-75.81%)
Mutual labels:  symfony-bundle
EasyAuditBundle
A Symfony Bundle To Log Selective Events
Stars: ✭ 84 (+35.48%)
Mutual labels:  symfony-bundle
EzCoreExtraBundle
Extra features for eZ Platform (v1.x compatible with eZ Publish 5.4)
Stars: ✭ 29 (-53.23%)
Mutual labels:  symfony-bundle

KnpDisqusBundle

If you use Disqus on your website for comments the comments are loaded dynamically via JavaScript, which could negatively impact SEO.

This bundle will fetch the comments using Disqus API so that you can include them on your page… before replacing the comment div by the Disqus JavaScript widget.

This way you benefit from both the JavaScript widget and the robot-friendly comments.

Build Status

knpbundles.com

Requirements

Installation

With composer, run:

composer require knplabs/knp-disqus-bundle

If you're not using Symfony Flex, then you will also need to enable Knp\Bundle\DisqusBundle\KnpDisqusBundle in your bundles.php file.

Next, create a config/packages/knp_disqus.yaml file:

# config/packages/knp_disqus.yaml
knp_disqus:
    api_key: '%env(DISQUS_API_KEY)%'

And finally, configure the DISQUS_API_KEY in your .env or .env.local file:

# .env

DISQUS_API_KEY=ABC123

Usage:

In your Twig template:

{{ knp_disqus_render('your_disqus_shortname', {'identifier': '/december-2010/the-best-day-of-my-life/', 'limit': 10}) }}

You can also show comments for specific language:

{{ knp_disqus_render('your_disqus_shortname', {'identifier': '/december-2010/the-best-day-of-my-life/', 'language': 'de_formal'}) }}

Or in Controller:

use Knp\Bundle\DisqusBundle\Client\DisqusClientInterface;

public function somePage(DisqusClientInterface $disqusClient)
{
    // ...

    $comments = $disqusClient->fetch('your_disqus_shortname', [
        'identifier' => '/december-2010/the-best-day-of-my-life/',
        'limit'      => 10, // Default limit is set to max. value for Disqus (100 entries)
    //    'language'   => 'de_formal', // You can fetch comments only for specific language
    ]);

    return $this->render('articles/somePage.html.twig', [
        'comments' => $comments,
    ]);
}

Adding a Callback for New Comments

If you want a JavaScript function to be called when a new comment is added (e.g. to trigger some Analytics), first, create a global JavaScript function somewhere (i.e. one that is attached to the windows object):

window.onNewComment = function(comment) {
    console.log(comment);
}

Next, pass the function name when rendering:

{{ knp_disqus_render('your_disqus_shortname', {
    'identifier': '/december-2010/the-best-day-of-my-life/',
    'limit': 10,
    'newCommentCallbackFunctionName': 'onNewComment'
}) }}

SSO authentication (optional)

If you want to manage authentication through Disqus SSO mechanism, you have to add the application secret key in the configuration and pass user information (id, username, email) which will compose the HMAC payload from it, as well as specific login/logout service information to the helper. Make sure to setup your Disqus forum to use SSO and allow for local domains (for development purposes).

To use SSO auth, pass sso.user information in the parameters to tell Disqus which user is logged in. Pass a user with an empty id to force Disqus to logout user, respectively to tell Disqus no user is logged in through SSO. Add information regarding your SSO Authentication service (login/logout urls, icon, etc.) in the sso.service parameter. See Disqus SSO documentation for more information.

{{ knp_disqus_render(
    'dolor-sid',
    {
        'identifier': '/december-2010/the-best-day-of-my-life/',
        'limit': 100,
        'sso': {
            'user': {
                'id' : 'test',
                'username' : 'John Doe',
                'email': '[email protected]',
            },
            'service': {
                'name': 'MyAuthServiceProvider',
                'icon': 'http://example.com/favicon.png',
                'button': 'http://example.com/images/samplenews.gif',
                'url': 'http://example.com/login/',
                'logout': 'http://example.com/logout/',
                'width': '400',
                'height': '400'
            }
        }
    },
    'KnpDisqusBundle::list.html.twig' )
}}

Configuration

# config/packages/knp_disqus.yaml
knp_disqus:
    api_key: 'your-disqus-api-key'
    secret_key: 'disqus-api-key' # optional, for SSO auth only

Enjoy!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].