nystudio107 /
craft-disqus
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Disqus plugin for Craft CMS 3.x |
||
| 4 | * |
||
| 5 | * Integrates the Disqus commenting system into Craft 3 websites, including |
||
| 6 | * Single Sign On (SSO) and custom login/logout URLs |
||
| 7 | * |
||
| 8 | * @link https://nystudio107.com |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 9 | * @copyright Copyright (c) 2017 nystudio107 |
||
|
0 ignored issues
–
show
|
|||
| 10 | */ |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | namespace nystudio107\disqus; |
||
| 13 | |||
| 14 | use Craft; |
||
| 15 | use craft\base\Plugin; |
||
| 16 | use craft\web\twig\variables\CraftVariable; |
||
| 17 | use nystudio107\disqus\models\Settings; |
||
| 18 | use nystudio107\disqus\services\DisqusService; |
||
| 19 | use nystudio107\disqus\twigextensions\DisqusTwigExtension; |
||
| 20 | use nystudio107\disqus\variables\DisqusVariable; |
||
| 21 | use yii\base\Event; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class Disqus |
||
| 25 | * |
||
| 26 | * @author nystudio107 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 27 | * @package Disqus |
||
|
0 ignored issues
–
show
|
|||
| 28 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 29 | * |
||
| 30 | * @property DisqusService $disqusService |
||
|
0 ignored issues
–
show
|
|||
| 31 | */ |
||
|
0 ignored issues
–
show
|
|||
| 32 | class Disqus extends Plugin |
||
| 33 | { |
||
| 34 | // Static Properties |
||
| 35 | // ========================================================================= |
||
| 36 | |||
| 37 | /** |
||
|
0 ignored issues
–
show
|
|||
| 38 | * @var ?Disqus |
||
| 39 | */ |
||
| 40 | public static ?Disqus $plugin = null; |
||
| 41 | |||
| 42 | // Public Properties |
||
| 43 | // ========================================================================= |
||
| 44 | |||
| 45 | /** |
||
|
0 ignored issues
–
show
|
|||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | public string $schemaVersion = '1.0.0'; |
||
| 49 | |||
| 50 | /** |
||
|
0 ignored issues
–
show
|
|||
| 51 | * @var bool |
||
| 52 | */ |
||
| 53 | public bool $hasCpSection = false; |
||
| 54 | |||
| 55 | /** |
||
|
0 ignored issues
–
show
|
|||
| 56 | * @var bool |
||
| 57 | */ |
||
| 58 | public bool $hasCpSettings = true; |
||
| 59 | |||
| 60 | // Static Methods |
||
| 61 | // ========================================================================= |
||
| 62 | |||
| 63 | /** |
||
|
0 ignored issues
–
show
|
|||
| 64 | * @inheritdoc |
||
| 65 | */ |
||
| 66 | public function __construct($id, $parent = null, array $config = []) |
||
| 67 | { |
||
| 68 | $config['components'] = [ |
||
| 69 | 'disqusService' => DisqusService::class, |
||
| 70 | ]; |
||
| 71 | |||
| 72 | parent::__construct($id, $parent, $config); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Public Methods |
||
| 76 | // ========================================================================= |
||
| 77 | |||
| 78 | /** |
||
|
0 ignored issues
–
show
|
|||
| 79 | * @inheritdoc |
||
| 80 | */ |
||
|
0 ignored issues
–
show
|
|||
| 81 | public function init(): void |
||
| 82 | { |
||
| 83 | parent::init(); |
||
| 84 | self::$plugin = $this; |
||
| 85 | Event::on( |
||
| 86 | CraftVariable::class, |
||
| 87 | CraftVariable::EVENT_INIT, |
||
| 88 | static function(Event $event) { |
||
|
0 ignored issues
–
show
|
|||
| 89 | /** @var CraftVariable $variable */ |
||
|
0 ignored issues
–
show
|
|||
| 90 | $variable = $event->sender; |
||
| 91 | $variable->set('disqus', DisqusVariable::class); |
||
| 92 | } |
||
| 93 | ); |
||
| 94 | Craft::$app->view->registerTwigExtension(new DisqusTwigExtension()); |
||
| 95 | Craft::info( |
||
| 96 | Craft::t( |
||
| 97 | 'disqus', |
||
| 98 | '{name} plugin loaded', |
||
| 99 | ['name' => $this->name] |
||
| 100 | ), |
||
| 101 | __METHOD__ |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Protected Methods |
||
| 106 | // ========================================================================= |
||
| 107 | |||
| 108 | /** |
||
|
0 ignored issues
–
show
|
|||
| 109 | * @inheritdoc |
||
| 110 | */ |
||
|
0 ignored issues
–
show
|
|||
| 111 | protected function createSettingsModel(): Settings |
||
| 112 | { |
||
| 113 | return new Settings(); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
|
0 ignored issues
–
show
|
|||
| 117 | * @inheritdoc |
||
| 118 | */ |
||
|
0 ignored issues
–
show
|
|||
| 119 | protected function settingsHtml(): ?string |
||
| 120 | { |
||
| 121 | // Render our settings template |
||
| 122 | return Craft::$app->view->renderTemplate( |
||
| 123 | 'disqus/settings', |
||
| 124 | [ |
||
| 125 | 'settings' => $this->getSettings(), |
||
| 126 | ] |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | } |
||
| 130 |