├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── disqus.php └── src ├── DisqusMiddleware.php └── DisqusServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `laravel-disqus` will be documented in this file 4 | 5 | ### v1.2.2 - 2020-03-07 6 | 7 | - Code clean-up, fix cs, remove discuss js comments. 8 | 9 | ### v1.2.1 - 2020-03-07 10 | 11 | - Fix composer typo. 12 | 13 | ### v1.2.0 - 2020-03-07 14 | 15 | - Allow all Laravel versions. 16 | 17 | ### v1.1.2 - 2017-11-24 18 | 19 | - Make publishing of config optional. [commit](https://github.com/yajra/laravel-disqus/commit/2db629d79c125947d68740007f056a6cce5f3e77) 20 | 21 | ### v1.1.1 - 2017-09-26 22 | 23 | - Fix noscript html #5, credits to @the94air. 24 | 25 | ### v1.1.0 - 2017-07-31 26 | 27 | - Add support for Laravel 5.5 package discovery. 28 | 29 | ### v1.0.0 - 2017-01-05 30 | 31 | - First major version. 32 | - Add github templates. 33 | - Fix git attributes. 34 | - Update license to 2017. 35 | 36 | ### v0.1.2 - 2016-07-22 37 | 38 | - Append discus script only if disqus_thread markup is present. 39 | 40 | ### v0.1.1 - 2016-07-22 41 | 42 | - Fix travis. 43 | 44 | ### v0.1.0 - 2016-07-22 45 | 46 | - Initial release. 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2022 Arjay Angeles 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel - Disqus Platform Integration 2 | 3 | [![Latest Version on Packagist][ico-version]][link-packagist] 4 | [![Software License][ico-license]](LICENSE.md) 5 | [![Total Downloads][ico-downloads]][link-downloads] 6 | 7 | A simple package integrating Disqus platform with Laravel. 8 | 9 | ## Install 10 | 11 | - Via Composer 12 | ``` bash 13 | $ composer require yajra/laravel-disqus 14 | ``` 15 | 16 | ## Providers and Config 17 | > If you are using Laravel 5.5+ then the steps below are optional. 18 | 19 | - Register service provider 20 | ```php 21 | Yajra\Disqus\DisqusServiceProvider::class 22 | ``` 23 | 24 | - Publish config 25 | ```bash 26 | $ php artisan vendor:publish --tag=disqus 27 | ``` 28 | 29 | ## Config 30 | Append the following config on your `.env` file. 31 | 32 | ``` php 33 | DISQUS_ENABLED=true 34 | DISQUS_USERNAME=your_website_shortname 35 | ``` 36 | 37 | ## Usage 38 | To display Disqus platform on your page, just add: 39 | ```html 40 |
41 | ``` 42 | 43 | ## Changelog 44 | 45 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 46 | 47 | ## Contributing 48 | 49 | Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. 50 | 51 | ## Security 52 | 53 | If you discover any security related issues, please email aqangeles@gmail.com instead of using the issue tracker. 54 | 55 | ## Credits 56 | 57 | - [Arjay Angeles][link-author] 58 | - [All Contributors][link-contributors] 59 | 60 | ## Buy me a coffee 61 | 62 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/yajra) 63 | Become a Patron 64 | 65 | ## License 66 | 67 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 68 | 69 | [ico-version]: https://img.shields.io/packagist/v/yajra/laravel-disqus.svg?style=flat-square 70 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 71 | [ico-downloads]: https://img.shields.io/packagist/dt/yajra/laravel-disqus.svg?style=flat-square 72 | 73 | [link-packagist]: https://packagist.org/packages/yajra/laravel-disqus 74 | [link-downloads]: https://packagist.org/packages/yajra/laravel-disqus 75 | [link-author]: https://github.com/yajra 76 | [link-contributors]: ../../contributors 77 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yajra/laravel-disqus", 3 | "description": "A simple Disqus platform integration with Laravel.", 4 | "keywords": [ 5 | "yajra", 6 | "disqus", 7 | "laravel" 8 | ], 9 | "homepage": "https://github.com/yajra/laravel-disqus", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Arjay Angeles", 14 | "email": "aqangeles@gmail.com", 15 | "homepage": "http://yajrabox.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": ">=5.5.9", 21 | "illuminate/support": "*", 22 | "illuminate/filesystem": "*" 23 | }, 24 | "require-dev": { 25 | "phpunit/phpunit" : "*" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Yajra\\Disqus\\": "src" 30 | } 31 | }, 32 | "extra": { 33 | "branch-alias": { 34 | "dev-master": "1.0-dev" 35 | }, 36 | "laravel": { 37 | "providers": [ 38 | "Yajra\\Disqus\\DisqusServiceProvider" 39 | ] 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /config/disqus.php: -------------------------------------------------------------------------------- 1 | to load disqus section. 7 | */ 8 | 'enabled' => env('DISQUS_ENABLED', false), 9 | 10 | /* 11 | * Your disqus username. 12 | */ 13 | 'username' => env('DISQUS_USERNAME', ''), 14 | ]; 15 | -------------------------------------------------------------------------------- /src/DisqusMiddleware.php: -------------------------------------------------------------------------------- 1 | appendDisqusScript($request, $response); 23 | } 24 | 25 | return $response; 26 | } 27 | 28 | /** 29 | * Append disqus script on the end of the page. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Illuminate\Http\Response $response 33 | * @return mixed 34 | */ 35 | protected function appendDisqusScript($request, $response) 36 | { 37 | $content = $response->getContent(); 38 | 39 | if (! Str::contains($content, '
')) { 40 | return; 41 | } 42 | 43 | $uri = $request->getRequestUri(); 44 | $pageUrl = url($uri); 45 | $pageId = 'route'.implode('.', explode('/', $uri)); 46 | $username = config('disqus.username'); 47 | 48 | $disqusHtml = << 50 | var disqus_config = function () { 51 | this.page.url = '$pageUrl'; 52 | this.page.identifier = '$pageId'; 53 | }; 54 | 55 | (function() { 56 | var d = document, s = d.createElement('script'); 57 | 58 | s.src = '//$username.disqus.com/embed.js'; 59 | 60 | s.setAttribute('data-timestamp', +new Date()); 61 | (d.head || d.body).appendChild(s); 62 | })(); 63 | 64 | 65 | CDATA; 66 | 67 | $bodyPosition = strripos($content, ''); 68 | 69 | if (false !== $bodyPosition) { 70 | $content = substr($content, 0, $bodyPosition).$disqusHtml.substr($content, $bodyPosition); 71 | } 72 | 73 | $response->setContent($content); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/DisqusServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishConfig(); 18 | 19 | $this->registerMiddleware(); 20 | } 21 | 22 | /** 23 | * Register and publish the config. 24 | */ 25 | protected function publishConfig() 26 | { 27 | $path = __DIR__.'/../config/disqus.php'; 28 | $this->mergeConfigFrom($path, 'disqus'); 29 | $this->publishes([ 30 | $path => config_path('disqus.php'), 31 | ], 'disqus'); 32 | } 33 | 34 | /** 35 | * Register disqus middleware. 36 | */ 37 | protected function registerMiddleware() 38 | { 39 | $this->app[Kernel::class]->pushMiddleware( 40 | DisqusMiddleware::class 41 | ); 42 | } 43 | 44 | /** 45 | * Register any application services. 46 | * 47 | * @return void 48 | */ 49 | public function register() 50 | { 51 | // 52 | } 53 | } 54 | --------------------------------------------------------------------------------