Issues (234)

src/Disqus.php (12 issues)

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
9
 * @copyright Copyright (c) 2017 nystudio107
10
 */
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
27
 * @package   Disqus
28
 * @since     1.0.0
29
 *
30
 * @property  DisqusService $disqusService
31
 */
32
class Disqus extends Plugin
33
{
34
    // Static Properties
35
    // =========================================================================
36
37
    /**
38
     * @var ?Disqus
39
     */
40
    public static ?Disqus $plugin = null;
41
42
    // Public Properties
43
    // =========================================================================
44
45
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
46
     * @var string
47
     */
48
    public string $schemaVersion = '1.0.0';
49
50
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
51
     * @var bool
52
     */
53
    public bool $hasCpSection = false;
54
55
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
56
     * @var bool
57
     */
58
    public bool $hasCpSettings = true;
59
60
    // Static Methods
61
    // =========================================================================
62
63
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
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
    /**
79
     * @inheritdoc
80
     */
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
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
89
                /** @var CraftVariable $variable */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
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
Missing short description in doc comment
Loading history...
109
     * @inheritdoc
110
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
111
    protected function createSettingsModel(): Settings
112
    {
113
        return new Settings();
114
    }
115
116
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
117
     * @inheritdoc
118
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
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