Developed with love by KnpLabs Hire us for your project!
70

KnpDisqusBundle

by KnpLabs

A Symfony2 bundle to fetch and render disqus comments via their API. Your SEO other-half will love it.

KnpDisqusBundle

If you use Disqus on your website for comments, you know that it's no good for SEO − as the comments are loaded dynamically via javascript.

This bundle will fetch the comments using Disqus API so that you can include them in 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:

php composer.phar require knplabs/knp-disqus-bundle:dev-master

Register the bundles in your AppKernel:

$bundles = array(
    //...
    new Knp\Bundle\DisqusBundle\KnpDisqusBundle(),
    //...
);

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). More details hereunder.

Configuration

config.yml

knp_disqus:
    api_key: %knp_disqus.api_key%
    secret_key: %knp_disqus.secret_key% # optional, for SSO auth only
    forums:
        lorem:
            shortname: %knp_disqus.lorem.shortname%
            cache: my_cache_for_lorem # cache template key, usage described below
        ipsum:
            shortname: %knp_disqus.ipsum.shortname%

my_cache_for_lorem:
    # If you setup up an cache, you should also configure cache provider, which will be used automatically
    # ...

parameters.yml

knp_disqus.api_key:    YOUR_PUBLIC_API_KEY
knp_disqus.secret_key: YOUR_SECRET_API_KEY # optional, for SSO auth only
# Insert your disqus shortname
# it's the unique identifier for your website as registered on Disqus
knp_disqus.lorem.shortname: "dolor-sid"
# you can also register more than one forum
knp_disqus.ipsum.shortname: "amet"

Usage:

In your Twig template:

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

You can also show comments for specific language:

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

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': 'john.doe@example.com',
            },
            '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' )
}}

Or in Controller:

public function myPageAction()
{
    // ...

    $comments = $this->get('knp_disqus.request')->fetch('dolor-sid', array(
        '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('LoremIpsumBundle:Lorem:myPage.html.twig', array(
        'comments' => $comments,
    ));
}
Copyright (c) 2011-2012 KnpLabs, http://KnpLabs.com

The MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
knp_disqus:
api_key: ~ # Required
secret_key:
base_url:
debug: ~
forums:

# Prototype
shortname:
shortname: ~
cache: ~
  • Merge pull request #35 from jlaso/master
    By umpirsky, 2 years ago
  • Fixed typo in the name of disqus
    By jlaso, 2 years ago
  • Merge pull request #34 from KnpLabs/symfony-2.4
    By weaverryan, 3 years ago
  • Changing composer.json to support Symfony 2.4 and higher
    By weaverryan, 3 years ago
  • Merge pull request #33 from weaverryan/limit-fix
    By pilot, 3 years ago
  • Actually using the limit option
    By weaverryan, 3 years ago
  • Merge pull request #32 from digitalkaoz/patch-1
    By pilot, 3 years ago
  • Update composer.json
    By digitalkaoz, 3 years ago
  • Add tests build status badge
    By pilot, 3 years ago
  • Add travis config
    By pilot, 3 years ago
  • Ignite tests
    By pilot, 3 years ago
  • Remove zend cache dependency, add yml for tests
    By pilot, 3 years ago
  • Clean up requirements
    By pilot, 3 years ago
  • Update composer instalation, cache provider usage
    By pilot, 3 years ago
  • Update readme to the lastest state
    By pilot, 3 years ago
  • Merge pull request #27 from KnpLabs/2.2-support
    By pilot, 3 years ago
  • Remove excess use class definition
    By pilot, 3 years ago
  • Inject just environment instead of whole container
    By pilot, 3 years ago
  • Update error message
    By pilot, 3 years ago
  • Add occurred error explanation if disqus is no available in some reasons
    By pilot, 3 years ago
  • [wip] Add 2.2 support
    By pilot, 3 years ago
  • Merge pull request #29 from KnpLabs/ssl-fix
    By stloyd, 4 years ago
  • Adding a comment about why we're caching on a filed request
    By stloyd, 4 years ago
  • If the API request fails, we now fail silently
    By stloyd, 4 years ago
  • Handling case where the response from disqus is not an array (it's an error)
    By stloyd, 4 years ago
  • Fixing SSL problem with disqus sending us back http URLs in a different format - see the long description in the commit
    By stloyd, 4 years ago
  • Trying to fix more content warnings for SSL
    By stloyd, 4 years ago
  • Trying a hack to make the images go to the secure server
    By stloyd, 4 years ago
  • Update composer.json
    By stloyd, 4 years ago
  • Add knpbundles.com badge
    By pilot, 4 years ago