Giter Club home page Giter Club logo

disqus's Introduction

Disqus plugin for Craft CMS

A simple plugin for integrating Disqus into Craft CMS websites, including Single Sign On (SSO) and custom login/logout URLs.

Installation

  1. Download & unzip the file and place the disqus directory into your craft/plugins directory
  2. -OR- do a git clone https://github.com/khalwat/disqus.git directly into your craft/plugins folder. You can then update it with git pull
  3. Install plugin in the Craft Control Panel under Settings > Plugins
  4. The plugin folder should be named disqus for Craft to see it. GitHub recently started appending -master (the branch name) to the name of the folder for zip file downloads.

Configuring Disqus

First, make sure you have set up a Disqus account.

Next in the Craft Admin CP, go to Settings->Plugins->Disqus and enter the Short Name for your Disqus site. This is the only required setting for the Disqus plugin.

Single Sign On (SSO)

The real usefulness of the Disqus plugin is that it takes care of the Single Sign On (SSO) integration with your Craft site.

Before you can use this, you'll need to set up the Disqus SSO API as described on the Integrating Single Sign-On web page.

Then copy and paste the API Key and API Secret into the Disqus plugin settings, and turn on the "User Single Sign On" lightswitch.

Custom Login/Logout URLs

The Diqus plugin will also take care of the custom login/logout URLs, should you wish to use them. Please see Adding your own SSO login and logout links for details.

You only need this is you want to have a custom login button displayed in the Disqus UI itself.

url should be the address of your login page. The page will be opened in a new window and it must close itself after authentication is done. That is how we know when it is done and reload the page.

logout should be set to http://example.com/actions/disqus/logoutRedirect to hit the Disqus controller that handles the logout and redirect.

Using the Disqus plugin in your templates

Both of these methods accomplish the same thing:

{# Output the Disqus embed code using the 'disqusEmbed' function #}
{{ disqusEmbed( DISQUS_IDENTIFIER, DISQUS_TITLE, DISQUS_URL, DISQUS_CATEGORY_ID) }}

{# Output the Disqus embed code using the 'disqusEmbed' filter #}
{{ DISQUS_IDENTIFIER | disqusEmbed(DISQUS_TITLE, DISQUS_URL, DISQUS_CATEGORY_ID) }}

All of the parameters except for DISQUS_IDENTIFIER are optional. For more information on what these parameters are, please see Javascript configuration variables

In its most basic case, this will result in output to your Craft template that looks like this:

<div id="disqus_thread"></div>
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'DISQUS_SHORTNAME';
    var disqus_identifier = 'DISQUS_IDENTIFIER';
    var disqus_title = 'DISQUS_TITLE';
    var disqus_url = 'DISQUS_URL';
    var disqus_category_id = 'DISQUS_CATEGORY_ID';
    
    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

The DISQUS_SHORTNAME setting is taken from the Admin CP settings, and the rest of the DISQUS_* settings are passed in as variables from the disqusEmbed Twig filter/function.

If you have turned on "User Single Sign On" it will also output something like this prior to the above tag:

<script type="text/javascript">
var disqus_config = function() {
    this.page.remote_auth_s3 = "eyJpZCI6IjEiLCJ1c2VybmFtZSI6IkFkbWluIiwiZW1haWwiOiJhbmRyZXdAbWVnYWxvbWFuaWFjLmNvbSJ9 c0e4b8f2eca3c0e995cdd64ba2dedd720820ab5b 1431214361";
    this.page.api_key = "GTX1r1JBbiJah3hzZkBO06hI71VxjyWxgdurckHYBWLiELkHDidVmnDkBW0XeROe";
};
</script>

Which, assuming you've set up the Disqus SSO properly, will allow your Craft users to be logged into Disqus using your Craft website credentials.

If you have "Use Custom Login/Logout URLs" turned on, it will also generate the this.sso settings for you, as described here

Changelog

1.0.4 -- 2016.10.17

  • [Fixed] Fixed some overzealous json_encode() calls that caused comments to not show up correctly
  • [Improved] Updated README.md

1.0.3 -- 2016.10.03

  • [Fixed] Resolve broken $disqusIdentifier encoding when set as a string.
  • [Fixed] Fixes Disqus from loading when encoding the URL
  • [Improved] Updated README.md

1.0.2 -- 2016.09.19

  • [Improved] We now JSON-encode the data in the Disqus embed
  • [Improved] Added data-cfasync=false to the script tags for CloudFlare RocketScript support
  • [Improved] Updated README.md

1.0.1 -- 2015.11.23

  • Added support for Craft 2.5 new plugin features
  • Added a controller to handle the custom logout URL
  • Fixed an issue where custom avatars no longer appeared

1.0.0 -- 2015.05.09

  • Initial release

disqus's People

Contributors

khalwat avatar bendalton avatar kevinouellette avatar mikestecker avatar

Watchers

Tim Kelty avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.