├── composer.json ├── controllers └── DisqusController.php ├── variables └── DisqusVariable.php ├── config.php ├── resources └── icon.svg ├── LICENSE.md ├── twigextensions └── DisqusTwigExtension.php ├── CHANGELOG.md ├── templates ├── disqusEmbedTag.twig └── settings.twig ├── releases.json ├── DisqusPlugin.php ├── services └── DisqusService.php └── README.md /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nystudio107/disqus", 3 | "description": "Integrates the Disqus commenting system into Craft CMS websites, including Single Sign On (SSO) and custom login/logout URLs.", 4 | "type": "craft-plugin", 5 | "authors": [ 6 | { 7 | "name": "nystudio107", 8 | "homepage": "https://nystudio107.com" 9 | } 10 | ], 11 | "require": { 12 | "composer/installers": "~1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /controllers/DisqusController.php: -------------------------------------------------------------------------------- 1 | userSession->logout(false); 17 | $this->redirect($_SERVER['HTTP_REFERER']); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /variables/DisqusVariable.php: -------------------------------------------------------------------------------- 1 | disqus->outputEmbedTag( 23 | $disqusIdentifier, 24 | $disqusTitle, 25 | $disqusUrl, 26 | $disqusCategoryId, 27 | $disqusLanguage 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | '', 16 | 'useSSO' => false, 17 | 'disqusPublicKey' => '', 18 | 'disqusSecretKey' => '', 19 | 'customLogin' => false, 20 | 'loginName' => '', 21 | 'loginButton' => '', 22 | 'loginIcon' => '', 23 | 'loginUrl' => '', 24 | 'loginLogoutUrl' => '', 25 | 'loginWidth' => '', 26 | 'loginHeight' => '', 27 | ); 28 | -------------------------------------------------------------------------------- /resources/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 nystudio107 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. -------------------------------------------------------------------------------- /twigextensions/DisqusTwigExtension.php: -------------------------------------------------------------------------------- 1 | new Twig_Filter_Method($this, 'disqusEmbed'), 26 | ); 27 | } 28 | 29 | /** 30 | * @inheritdoc 31 | */ 32 | public function getFunctions() 33 | { 34 | return array( 35 | 'disqusEmbed' => new Twig_Function_Method($this, 'disqusEmbed'), 36 | ); 37 | } 38 | 39 | /** 40 | * @param string $disqusIdentifier 41 | * @param string $disqusTitle 42 | * @param string $disqusUrl 43 | * @param string $disqusCategoryId 44 | * @param string $disqusLanguage 45 | * 46 | * @return mixed 47 | */ 48 | public function disqusEmbed( 49 | $disqusIdentifier = "", 50 | $disqusTitle = "", 51 | $disqusUrl = "", 52 | $disqusCategoryId = "", 53 | $disqusLanguage = "" 54 | ) { 55 | return craft()->disqus->outputEmbedTag( 56 | $disqusIdentifier, 57 | $disqusTitle, 58 | $disqusUrl, 59 | $disqusCategoryId, 60 | $disqusLanguage 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Disqus Changelog 2 | 3 | ## 1.1.1 - 2017.03.20 4 | ### Changed 5 | * Fixed broken SSO implementation by moving it all to one template 6 | * Changed `[]` to `array()` for ancient PHP compatibility 7 | * Deprecated the separate `outputSSOTag()` functions 8 | * Removed errant (and unneeded) `|escape('js')` filters 9 | * Updated `README.md` 10 | 11 | ## 1.1.0 - 2017.03.18 12 | ### Added 13 | * All settings can now be overridden via `config.php` in a multi-environment friendly way 14 | * Added multi-lingual support for both the Disqus embed and comments 15 | * Added Composer support 16 | * Broke out the changelog into `CHANGELOG.md` 17 | 18 | ### Changed 19 | * Separated the various tags out into Twig templates 20 | * Cleaned up & refactored the templates & code 21 | 22 | ### 1.0.3 - 2016.10.03 23 | 24 | * [Fixed] Resolve broken $disqusIdentifier encoding when set as a string. 25 | * [Fixed] Fixes Disqus from loading when encoding the URL 26 | * [Improved] Updated README.md 27 | 28 | ### 1.0.2 - 2016.09.19 29 | 30 | * [Improved] We now JSON-encode the data in the Disqus embed 31 | * [Improved] Added data-cfasync=false to the script tags for CloudFlare RocketScript support 32 | * [Improved] Updated README.md 33 | 34 | ### 1.0.1 - 2015.11.23 35 | 36 | * Added support for Craft 2.5 new plugin features 37 | * Added a controller to handle the custom logout URL 38 | * Fixed an issue where custom avatars no longer appeared 39 | 40 | ### 1.0.0 - 2015.05.09 41 | 42 | * Initial release 43 | 44 | Brought to you by [nystudio107](http://nystudio107.com) -------------------------------------------------------------------------------- /templates/disqusEmbedTag.twig: -------------------------------------------------------------------------------- 1 |
2 | 47 | 48 | -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "version": "1.1.1", 4 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 5 | "date": "2017-03-20T11:00:00-05:00", 6 | "notes": [ 7 | "[Fixed] Fixed broken SSO implementation by moving it all to one template", 8 | "[Improved] Changed `[]` to `array()` for ancient PHP compatibility", 9 | "[Improved] Deprecated the separate `outputSSOTag()` functions", 10 | "[Improved] * Removed errant (and unneeded) `|escape('js')` filters", 11 | "[Improved] Updated `README.md`" 12 | ] 13 | }, 14 | { 15 | "version": "1.1.0", 16 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 17 | "date": "2017-03-18T11:00:00-05:00", 18 | "notes": [ 19 | "[Added] All settings can now be overridden via `config.php` in a multi-environment friendly way", 20 | "[Added] Added multi-lingual support for both the Disqus embed and comments", 21 | "[Added] Added Composer support", 22 | "[Added] Broke out the changelog into `CHANGELOG.md`", 23 | "[Improved] Separated the various tags out into Twig templates", 24 | "[Improved] Cleaned up & refactored the templates & code", 25 | "[Improved] Updated `README.md`" 26 | ] 27 | }, 28 | { 29 | "version": "1.0.3", 30 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 31 | "date": "2016-10-03T11:00:00-05:00", 32 | "notes": [ 33 | "[Fixed] We now JSON-encode the data in the Disqus embed", 34 | "[Fixed] Added data-cfasync=false to the script tags for CloudFlare RocketScript support", 35 | "[Improved] Updated README.md" 36 | ] 37 | }, 38 | { 39 | "version": "1.0.2", 40 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 41 | "date": "2016-09-19T11:00:00-05:00", 42 | "notes": [ 43 | "[Improved] We now JSON-encode the data in the Disqus embed", 44 | "[Improved] Added data-cfasync=false to the script tags for CloudFlare RocketScript support", 45 | "[Improved] Updated README.md" 46 | ] 47 | }, 48 | { 49 | "version": "1.0.1", 50 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 51 | "date": "2015-11-23T11:00:00-05:00", 52 | "notes": [ 53 | "[Added] Added support for Craft 2.5 new plugin features", 54 | "[Added] Added a controller to handle the custom logout URL", 55 | "[Fixed] Fixed an issue where custom avatars no longer appeared" 56 | ] 57 | }, 58 | { 59 | "version": "1.0.0", 60 | "downloadUrl": "https://github.com/khalwat/disqus/archive/master.zip", 61 | "date": "2015-05-09T11:00:00-05:00", 62 | "notes": [ 63 | "[Added] Initial release" 64 | ] 65 | } 66 | ] 67 | -------------------------------------------------------------------------------- /DisqusPlugin.php: -------------------------------------------------------------------------------- 1 | array( 65 | AttributeType::String, 66 | 'label' => 'Disqus Site Short Name', 67 | 'default' => '' 68 | ), 69 | 'useSSO' => array( 70 | AttributeType::Bool, 71 | 'label' => 'Use Single Sign On', 72 | 'default' => false 73 | ), 74 | 'disqusPublicKey' => array( 75 | AttributeType::String, 76 | 'label' => 'Disqus Public Key', 77 | 'default' => '' 78 | ), 79 | 'disqusSecretKey' => array( 80 | AttributeType::String, 81 | 'label' => 'Disqus Secret Key', 82 | 'default' => '' 83 | ), 84 | 'customLogin' => array( 85 | AttributeType::Bool, 86 | 'label' => 'Use Custom Login/Logout URLs', 87 | 'default' => false 88 | ), 89 | 'loginName' => array( 90 | AttributeType::String, 91 | 'label' => 'name', 92 | 'default' => '' 93 | ), 94 | 'loginButton' => array( 95 | AttributeType::String, 96 | 'label' => 'button', 97 | 'default' => '' 98 | ), 99 | 'loginIcon' => array( 100 | AttributeType::String, 101 | 'label' => 'icon', 102 | 'default' => '' 103 | ), 104 | 'loginUrl' => array( 105 | AttributeType::String, 106 | 'label' => 'url', 107 | 'default' => '' 108 | ), 109 | 'loginLogoutUrl' => array( 110 | AttributeType::String, 111 | 'label' => 'logout', 112 | 'default' => '' 113 | ), 114 | 'loginWidth' => array( 115 | AttributeType::String, 116 | 'label' => 'width', 117 | 'default' => '800' 118 | ), 119 | 'loginHeight' => array( 120 | AttributeType::String, 121 | 'label' => 'height', 122 | 'default' => '400' 123 | ), 124 | ); 125 | } 126 | 127 | /** 128 | * @inheritdoc 129 | */ 130 | public function getSettings() 131 | { 132 | $settings = parent::getSettings(); 133 | $base = $this->defineSettings(); 134 | 135 | foreach ($base as $key => $row) { 136 | $override = craft()->config->get($key, 'disqus'); 137 | 138 | if (!is_null($override) && !empty($override)) { 139 | $settings->$key = $override; 140 | } 141 | } 142 | 143 | return $settings; 144 | } 145 | 146 | /** 147 | * @inheritdoc 148 | */ 149 | public function getSettingsHtml() 150 | { 151 | return craft()->templates->render('disqus/settings', array( 152 | 'settings' => $this->getSettings() 153 | )); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /templates/settings.twig: -------------------------------------------------------------------------------- 1 | {% import "_includes/forms" as forms %} 2 | 3 | {% macro configWarning(setting) -%} 4 | {% if (craft.config.get(setting, 'disqus')) |length %} 5 | {{ "This is being overridden by the {setting} config setting in your disqus.php config file." |t({ 6 | setting: setting 7 | }) |raw }} 8 | {% endif %} 9 | {%- endmacro %} 10 | {% from _self import configWarning %} 11 | 12 | {{ forms.textField({ 13 | 'label': 'Disqus Site Short Name', 14 | 'instructions': 'Enter your Disqus Site Short Name here.', 15 | 'id': 'disqusShortname', 16 | 'name': 'disqusShortname', 17 | 'value': settings['disqusShortname'], 18 | 'warning': configWarning('disqusShortname') 19 | }) }} 20 | 21 |
22 | 23 |

Please see Integrating Single Sign-On for details on how to set up your Disqus account to use SSO

24 | 25 | {{ forms.lightswitchField({ 26 | 'label': 'Use Single Sign On', 27 | 'instructions': 'Do you want to use SSO with Disqus?', 28 | 'id': 'useSSO', 29 | 'name': 'useSSO', 30 | 'on': settings['useSSO'], 31 | 'warning': configWarning('useSSO') 32 | }) }} 33 | 34 | {{ forms.textField({ 35 | 'label': 'Disqus Public Key (API Key)', 36 | 'instructions': 'Enter your Disqus API Key.', 37 | 'id': 'disqusPublicKey', 38 | 'name': 'disqusPublicKey', 39 | 'value': settings['disqusPublicKey'], 40 | 'warning': configWarning('disqusPublicKey') 41 | }) }} 42 | 43 | {{ forms.textField({ 44 | 'label': 'Disqus Secret Key (API Secret)', 45 | 'instructions': 'Enter your .', 46 | 'id': 'disqusSecretKey', 47 | 'name': 'disqusSecretKey', 48 | 'value': settings['disqusSecretKey'], 49 | 'warning': configWarning('disqusSecretKey') 50 | }) }} 51 | 52 |
53 | 54 |

Please see Adding your own SSO login and logout links for details.

55 | 56 | {{ forms.lightswitchField({ 57 | 'label': 'Use Custom Login/Logout URLs', 58 | 'instructions': 'Do you want to use custom login/logout URLs?', 59 | 'id': 'customLogin', 60 | 'name': 'customLogin', 61 | 'on': settings['customLogin'], 62 | 'warning': configWarning('customLogin') 63 | }) }} 64 | 65 | {{ forms.textField({ 66 | 'label': 'name', 67 | 'instructions': 'Your site name. We will display it in the Post As window.', 68 | 'id': 'loginName', 69 | 'name': 'loginName', 70 | 'value': settings['loginName'], 71 | 'warning': configWarning('loginName') 72 | }) }} 73 | 74 | {{ forms.textField({ 75 | 'label': 'button', 76 | 'instructions': 'Address of the image that acts as a button. Disqus 2012 users, see style guide below.', 77 | 'id': 'loginButton', 78 | 'name': 'loginButton', 79 | 'value': settings['loginButton'], 80 | 'warning': configWarning('loginButton') 81 | }) }} 82 | 83 | {{ forms.textField({ 84 | 'label': 'icon', 85 | 'instructions': 'Address of the image that appears on the login modal SSO tab. Favicons work well here. (Not required in Disqus 2012.)', 86 | 'id': 'loginIcon', 87 | 'name': 'loginIcon', 88 | 'value': settings['loginIcon'], 89 | 'warning': configWarning('loginIcon') 90 | }) }} 91 | 92 | {{ forms.textField({ 93 | 'label': 'url', 94 | 'instructions': '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.', 95 | 'id': 'loginUrl', 96 | 'name': 'loginUrl', 97 | 'value': settings['loginUrl'], 98 | 'warning': configWarning('loginUrl') 99 | }) }} 100 | 101 | {{ forms.textField({ 102 | 'label': 'logout', 103 | 'instructions': 'Address of your logout page. This page must redirect user back to the original page after logout.', 104 | 'id': 'loginLogoutUrl', 105 | 'name': 'loginLogoutUrl', 106 | 'value': settings['loginLogoutUrl'], 107 | 'warning': configWarning('loginLogoutUrl') 108 | }) }} 109 | 110 | {{ forms.textField({ 111 | 'label': 'width', 112 | 'instructions': 'Width of the login popup window. Default is 800.', 113 | 'id': 'loginWidth', 114 | 'name': 'loginWidth', 115 | 'value': settings['loginWidth'], 116 | 'warning': configWarning('loginWidth') 117 | }) }} 118 | 119 | {{ forms.textField({ 120 | 'label': 'height', 121 | 'instructions': 'Height of the login popup window. Default is 400.', 122 | 'id': 'loginHeight', 123 | 'name': 'loginHeight', 124 | 'value': settings['loginHeight'], 125 | 'warning': configWarning('loginHeight') 126 | }) }} 127 | -------------------------------------------------------------------------------- /services/DisqusService.php: -------------------------------------------------------------------------------- 1 | plugins->getPlugin('disqus')->getSettings(); 25 | $disqusShortname = $settings['disqusShortname']; 26 | 27 | $vars = array( 28 | 'disqusShortname' => $disqusShortname, 29 | 'disqusIdentifier' => $disqusIdentifier, 30 | 'disqusTitle' => $disqusTitle, 31 | 'disqusUrl' => $disqusUrl, 32 | 'disqusCategoryId' => $disqusCategoryId, 33 | 'disqusLanguage' => $disqusLanguage, 34 | ); 35 | $vars = array_merge($vars, $this->getSSOVars()); 36 | $result = $this->renderPluginTemplate('disqusEmbedTag', $vars); 37 | 38 | return $result; 39 | } 40 | 41 | /** 42 | * Return the SSO vars 43 | * 44 | * @return array 45 | */ 46 | protected function getSSOVars() 47 | { 48 | $settings = craft()->plugins->getPlugin('disqus')->getSettings(); 49 | $vars = array( 50 | 'useSSO' => false, 51 | 'useCustomLogin' => false, 52 | ); 53 | if ($settings['useSSO']) { 54 | $data = array(); 55 | 56 | // Set the data array 57 | $currentUser = craft()->userSession->user; 58 | if ($currentUser) { 59 | $data['id'] = $currentUser->id; 60 | if (craft()->config->get('useEmailAsUsername')) { 61 | $data['username'] = $currentUser->getFullName(); 62 | } else { 63 | $data['username'] = $currentUser->username; 64 | } 65 | $data['email'] = $currentUser->email; 66 | $data['avatar'] = $currentUser->getPhotoUrl(); 67 | } 68 | 69 | // Encode the data array and generate the hMac 70 | $message = base64_encode(json_encode($data)); 71 | $timestamp = time(); 72 | $hMac = $this->disqusHmacSha1( 73 | $message 74 | .' ' 75 | .$timestamp, 76 | $settings['disqusSecretKey'] 77 | ); 78 | 79 | // Set the vars for the template 80 | $vars = array_merge($vars, array( 81 | 'useSSO' => true, 82 | 'message' => $message, 83 | 'hmac' => $hMac, 84 | 'timestamp' => $timestamp, 85 | 'disqusPublicKey' => $settings['disqusPublicKey'], 86 | )); 87 | 88 | // Render the SSO custom login template 89 | if ($settings['customLogin']) { 90 | $vars = array_merge($vars, array( 91 | 'useCustomLogin' => true, 92 | 'loginName' => $settings['loginName'], 93 | 'loginButton' => $settings['loginButton'], 94 | 'loginIcon' => $settings['loginIcon'], 95 | 'loginUrl' => $settings['loginUrl'], 96 | 'loginLogoutUrl' => $settings['loginLogoutUrl'], 97 | 'loginWidth' => $settings['loginWidth'], 98 | 'loginHeight' => $settings['loginHeight'], 99 | )); 100 | } 101 | } 102 | 103 | return $vars; 104 | } 105 | 106 | /** 107 | * Render a plugin template 108 | * 109 | * @param $templatePath 110 | * @param $vars 111 | * 112 | * @return string 113 | */ 114 | protected function renderPluginTemplate($templatePath, $vars) 115 | { 116 | // Stash the old template path, and set it to our plugin's templates folder 117 | $oldPath = method_exists(craft()->templates, 'getTemplatesPath') 118 | ? craft()->templates->getTemplatesPath() 119 | : craft()->path->getTemplatesPath(); 120 | $newPath = craft()->path->getPluginsPath() . 'disqus/templates'; 121 | method_exists(craft()->templates, 'setTemplatesPath') 122 | ? craft()->templates->setTemplatesPath($newPath) 123 | : craft()->path->setTemplatesPath($newPath); 124 | 125 | // Render the template with our vars passed in 126 | try { 127 | $htmlText = craft()->templates->render($templatePath, $vars); 128 | } catch (\Exception $e) { 129 | $htmlText = 'Error rendering template ' . $templatePath . ' -> ' . $e->getMessage(); 130 | DisqusPlugin::log($htmlText, LogLevel::Error); 131 | } 132 | 133 | // Restore the old template path 134 | method_exists(craft()->templates, 'setTemplatesPath') 135 | ? craft()->templates->setTemplatesPath($oldPath) 136 | : craft()->path->setTemplatesPath($oldPath); 137 | 138 | return TemplateHelper::getRaw($htmlText); 139 | } 140 | 141 | /** 142 | * HMAC->SHA1 143 | * From: https://github.com/disqus/DISQUS-API-Recipes/blob/master/sso/php/sso.php 144 | * 145 | * @param $data 146 | * @param $key 147 | * 148 | * @return string 149 | */ 150 | protected function disqusHmacSha1($data, $key) 151 | { 152 | $blockSize = 64; 153 | $hashFunc = 'sha1'; 154 | if (strlen($key) > $blockSize) { 155 | $key = pack('H*', $hashFunc($key)); 156 | } 157 | $key = str_pad($key, $blockSize, chr(0x00)); 158 | $iPad = str_repeat(chr(0x36), $blockSize); 159 | $oPad = str_repeat(chr(0x5c), $blockSize); 160 | $hMac = pack( 161 | 'H*', 162 | $hashFunc( 163 | ($key ^ $oPad).pack( 164 | 'H*', 165 | $hashFunc( 166 | ($key ^ $iPad).$data 167 | ) 168 | ) 169 | ) 170 | ); 171 | 172 | return bin2hex($hMac); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 2 | 3 | # DEPRECATED 4 | 5 | This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons. 6 | 7 | The Craft CMS 3.x version of this plugin can be found here: [craft-disqus](https://github.com/nystudio107/craft-disqus) and can also be installed via the Craft Plugin Store in the Craft CP. 8 | 9 | # Disqus plugin for Craft CMS 10 | 11 | Integrate the [Disqus](https://disqus.com) commenting system into [Craft CMS](http://buildwithcraft.com) websites, including Single Sign On (SSO) and custom login/logout URLs. 12 | 13 | Related: [Disqus for Craft 3.x](https://github.com/nystudio107/craft3-disqus) 14 | 15 | **Installation** 16 | 17 | 1. Download & unzip the file and place the `disqus` directory into your `craft/plugins` directory 18 | 2. -OR- do a `git clone https://github.com/nystudio107/disqus.git` directly into your `craft/plugins` folder. You can then update it with `git pull` 19 | 3. -OR- install with Composer via `composer require nystudio107/disqus` 20 | 4. Install plugin in the Craft Control Panel under Settings > Plugins 21 | 5. 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. 22 | 23 | ## Configuring Disqus 24 | 25 | First, make sure you have [set up a Disqus account](https://disqus.com/websites/). 26 | 27 | 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. 28 | 29 | All settings are also configurable via the `config.php` file, which is a multi-environment friendly way to store the default settings. Don't edit this file, instead copy it to `craft/config` as `disqus.php` and make your changes there. 30 | 31 | ### Single Sign On (SSO) 32 | 33 | The real usefulness of the Disqus plugin is that it takes care of the Single Sign On (SSO) integration with your Craft site. 34 | 35 | Before you can use this, you'll need to set up the Disqus SSO API as described on the [Integrating Single Sign-On](https://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on) web page. 36 | 37 | Then copy and paste the API Key and API Secret into the Disqus plugin settings, and turn on the "User Single Sign On" lightswitch. 38 | 39 | ### Custom Login/Logout URLs 40 | 41 | The Disqus 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](https://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on#sso-login) for details. 42 | 43 | You only need this is you want to have a custom login button displayed in the Disqus UI itself. 44 | 45 | `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. 46 | 47 | `logout` should be set to `http://example.com/actions/disqus/logoutRedirect` to hit the Disqus controller that handles the logout and redirect. 48 | 49 | ## Using the Disqus plugin in your templates 50 | 51 | All of these methods accomplish the same thing: 52 | 53 | {# Output the Disqus embed code using the 'disqusEmbed' function #} 54 | {{ disqusEmbed( DISQUS_IDENTIFIER, DISQUS_TITLE, DISQUS_URL, DISQUS_CATEGORY_ID, DISQUS_LANGUAGE) }} 55 | 56 | {# Output the Disqus embed code using the 'disqusEmbed' filter #} 57 | {{ DISQUS_IDENTIFIER | disqusEmbed(DISQUS_TITLE, DISQUS_URL, DISQUS_CATEGORY_ID, DISQUS_LANGUAGE) }} 58 | 59 | {# Output the Disqus embed code using the 'disqusEmbed' variable #} 60 | {{ craft.disqus.disqusEmbed( DISQUS_IDENTIFIER, DISQUS_TITLE, DISQUS_URL, DISQUS_CATEGORY_ID, DISQUS_LANGUAGE) }} 61 | 62 | All of the parameters except for `DISQUS_IDENTIFIER` are optional. For more information on what these parameters are, please see [Javascript configuration variables](https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables) 63 | 64 | Disqus ignores any settings that are empty strings, e.g.: `''` 65 | 66 | The typical Twig tag you'll use would look like this: 67 | 68 | {{ disqusEmbed(entry.slug, entry.title, entry.url) }} 69 | 70 | ...which will result in comments that are unique on a per-entry basis. 71 | 72 | In its most basic case, this will result in output to your Craft template that looks like this: 73 | 74 |
75 | 104 | 105 | 106 | The `DISQUS_SHORTNAME` setting is taken from the Admin CP or `config.php` settings, and the rest of the `DISQUS_*` settings are passed in as variables from the `disqusEmbed` Twig filter/function. 107 | 108 | If you have turned on "User Single Sign On" it will also output something like this inside the above tag: 109 | 110 | this.page.remote_auth_s3 = "eyJpZCI6IjEiLCJ1c2VybmFtZSI6IkFkbWluIiwiZW1haWwiOiJhbmRyZXdAbWVnYWxvbWFuaWFjLmNvbSJ9 c0e4b8f2eca3c0e995cdd64ba2dedd720820ab5b 1431214361"; 111 | this.page.api_key = "GTX1r1JBbiJah3hzZkBO06hI71VxjyWxgdurckHYBWLiELkHDidVmnDkBW0XeROe"; 112 | 113 | 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. 114 | 115 | If you have "Use Custom Login/Logout URLs" turned on, it will also generate the `this.sso` settings for you, [as described here](https://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on#sso-login) 116 | 117 | ## Disqus Multi-lingual websites 118 | 119 | By default, Disqus will use the language you have set in `Disqus Admin > Setup > Appearance`, however you can use it on [Multi-lingual websites](https://help.disqus.com/customer/portal/articles/466249-multi-lingual-websites) as well. 120 | 121 | The `DISQUS_LANGUAGE` parameter you can provide to `{{ disqusEmbed() }}` allows you to control the language that the Disqus embed is displayed in. The comments, however, will still be the same for all languages. 122 | 123 | If you wish to have the comments themselves be different per-language, you can do something like: 124 | 125 | {{ disqusEmbed(entry.slug ~ "_" ~ entry.locale, entry.title, entry.url, '', entry.locale ) }} 126 | 127 | This will result in comments that are different for each language, and the Disqus embed will be displayed in the same language as the comments. 128 | 129 | Brought to you by [nystudio107](http://nystudio107.com) 130 | --------------------------------------------------------------------------------