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 nystudio107\disqus\services\DisqusService as DisqusService; |
15
|
|
|
use nystudio107\disqus\variables\DisqusVariable; |
16
|
|
|
use nystudio107\disqus\twigextensions\DisqusTwigExtension; |
17
|
|
|
use nystudio107\disqus\models\Settings; |
18
|
|
|
|
19
|
|
|
use Craft; |
20
|
|
|
use craft\base\Plugin; |
21
|
|
|
use craft\web\twig\variables\CraftVariable; |
22
|
|
|
|
23
|
|
|
use yii\base\Event; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Disqus |
27
|
|
|
* |
28
|
|
|
* @author nystudio107 |
|
|
|
|
29
|
|
|
* @package Disqus |
|
|
|
|
30
|
|
|
* @since 1.0.0 |
|
|
|
|
31
|
|
|
* |
32
|
|
|
* @property DisqusService $disqusService |
|
|
|
|
33
|
|
|
*/ |
|
|
|
|
34
|
|
|
class Disqus extends Plugin |
35
|
|
|
{ |
36
|
|
|
// Static Properties |
37
|
|
|
// ========================================================================= |
38
|
|
|
|
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* @var Disqus |
41
|
|
|
*/ |
42
|
|
|
public static $plugin; |
43
|
|
|
|
44
|
|
|
/** |
|
|
|
|
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
public static $craft31 = false; |
48
|
|
|
|
49
|
|
|
// Public Properties |
50
|
|
|
// ========================================================================= |
51
|
|
|
|
52
|
|
|
/** |
|
|
|
|
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
public $schemaVersion = '1.0.0'; |
56
|
|
|
|
57
|
|
|
/** |
|
|
|
|
58
|
|
|
* @var bool |
59
|
|
|
*/ |
60
|
|
|
public $hasCpSection = false; |
61
|
|
|
|
62
|
|
|
/** |
|
|
|
|
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
public $hasCpSettings = true; |
66
|
|
|
|
67
|
|
|
// Static Methods |
68
|
|
|
// ========================================================================= |
69
|
|
|
|
70
|
|
|
/** |
|
|
|
|
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
|
|
public function __construct($id, $parent = null, array $config = []) |
74
|
|
|
{ |
75
|
|
|
$config['components'] = [ |
76
|
|
|
'disqusService' => DisqusService::class, |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
parent::__construct($id, $parent, $config); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// Public Methods |
83
|
|
|
// ========================================================================= |
84
|
|
|
|
85
|
|
|
/** |
|
|
|
|
86
|
|
|
* @inheritdoc |
87
|
|
|
*/ |
|
|
|
|
88
|
|
|
public function init() |
89
|
|
|
{ |
90
|
|
|
parent::init(); |
91
|
|
|
self::$plugin = $this; |
92
|
|
|
|
93
|
|
|
// Version helpers |
94
|
|
|
self::$craft31 = version_compare(Craft::$app->getVersion(), '3.1', '>='); |
|
|
|
|
95
|
|
|
|
96
|
|
|
Event::on( |
97
|
|
|
CraftVariable::class, |
98
|
|
|
CraftVariable::EVENT_INIT, |
99
|
|
|
function (Event $event) { |
100
|
|
|
/** @var CraftVariable $variable */ |
|
|
|
|
101
|
|
|
$variable = $event->sender; |
102
|
|
|
$variable->set('disqus', DisqusVariable::class); |
103
|
|
|
} |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
Craft::$app->view->registerTwigExtension(new DisqusTwigExtension()); |
107
|
|
|
|
108
|
|
|
Craft::info( |
109
|
|
|
Craft::t( |
110
|
|
|
'disqus', |
111
|
|
|
'{name} plugin loaded', |
112
|
|
|
['name' => $this->name] |
113
|
|
|
), |
114
|
|
|
__METHOD__ |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// Protected Methods |
119
|
|
|
// ========================================================================= |
120
|
|
|
|
121
|
|
|
/** |
|
|
|
|
122
|
|
|
* @inheritdoc |
123
|
|
|
*/ |
|
|
|
|
124
|
|
|
protected function createSettingsModel() |
125
|
|
|
{ |
126
|
|
|
return new Settings(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
|
|
|
|
130
|
|
|
* @inheritdoc |
131
|
|
|
*/ |
|
|
|
|
132
|
|
|
protected function settingsHtml(): string |
133
|
|
|
{ |
134
|
|
|
// Render our settings template |
135
|
|
|
return Craft::$app->view->renderTemplate( |
136
|
|
|
'disqus/settings', |
137
|
|
|
[ |
138
|
|
|
'settings' => $this->getSettings(), |
139
|
|
|
] |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|