1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Vanillaforums plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Single Sign On plugin for VanillaForums/jsConnect and CraftCMS |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com/ |
8
|
|
|
* @copyright Copyright (c) 2019 nystudio107 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace nystudio107\vanillaforums; |
12
|
|
|
|
13
|
|
|
use nystudio107\vanillaforums\services\Sso as SsoService; |
14
|
|
|
use nystudio107\vanillaforums\variables\VanillaforumsVariable; |
15
|
|
|
use nystudio107\vanillaforums\models\Settings; |
16
|
|
|
|
17
|
|
|
use Craft; |
18
|
|
|
use craft\base\Plugin; |
19
|
|
|
use craft\web\twig\variables\CraftVariable; |
20
|
|
|
|
21
|
|
|
use yii\base\Event; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Vanillaforums |
25
|
|
|
* |
26
|
|
|
* @author nystudio107 |
27
|
|
|
* @package Vanillaforums |
28
|
|
|
* @since 3.0.0 |
29
|
|
|
* |
30
|
|
|
* @property SsoService $sso |
31
|
|
|
*/ |
32
|
|
|
class Vanillaforums extends Plugin |
33
|
|
|
{ |
34
|
|
|
// Static Properties |
35
|
|
|
// ========================================================================= |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Vanillaforums |
39
|
|
|
*/ |
40
|
|
|
public static $plugin; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
public static $craft31 = false; |
46
|
|
|
|
47
|
|
|
// Public Properties |
48
|
|
|
// ========================================================================= |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
public $schemaVersion = '1.0.0'; |
54
|
|
|
|
55
|
|
|
// Public Methods |
56
|
|
|
// ========================================================================= |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
|
public function init() |
62
|
|
|
{ |
63
|
|
|
parent::init(); |
64
|
|
|
self::$plugin = $this; |
65
|
|
|
|
66
|
|
|
self::$craft31 = version_compare(Craft::$app->getVersion(), '3.1', '>='); |
67
|
|
|
|
68
|
|
|
Event::on( |
69
|
|
|
CraftVariable::class, |
70
|
|
|
CraftVariable::EVENT_INIT, |
71
|
|
|
function (Event $event) { |
72
|
|
|
/** @var CraftVariable $variable */ |
73
|
|
|
$variable = $event->sender; |
74
|
|
|
$variable->set('vanillaforums', VanillaforumsVariable::class); |
75
|
|
|
} |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
Craft::info( |
79
|
|
|
Craft::t( |
80
|
|
|
'vanillaforums', |
81
|
|
|
'{name} plugin loaded', |
82
|
|
|
['name' => $this->name] |
83
|
|
|
), |
84
|
|
|
__METHOD__ |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// Protected Methods |
89
|
|
|
// ========================================================================= |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
|
|
protected function createSettingsModel() |
95
|
|
|
{ |
96
|
|
|
return new Settings(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
|
|
protected function settingsHtml(): string |
103
|
|
|
{ |
104
|
|
|
// Set up the form controls for editing the connection. |
105
|
|
|
$hashTypes = hash_algos(); |
106
|
|
|
$hashTypes = array_combine($hashTypes, $hashTypes); |
107
|
|
|
|
108
|
|
|
return Craft::$app->view->renderTemplate( |
109
|
|
|
'vanillaforums/settings', |
110
|
|
|
[ |
111
|
|
|
'settings' => $this->getSettings(), |
112
|
|
|
'hashTypes' => $hashTypes, |
113
|
|
|
] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|