1 | <?php |
||
2 | /** |
||
3 | * YouTube Live Embed plugin for Craft CMS |
||
4 | * |
||
5 | * This plugin allows you to embed a YouTube live stream and/or live chat on your webpage |
||
6 | * |
||
7 | * @link https://nystudio107.com |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
8 | * @copyright Copyright (c) 2019 nystudio107 |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\youtubeliveembed; |
||
12 | |||
13 | use Craft; |
||
14 | use craft\base\Plugin; |
||
15 | use craft\web\twig\variables\CraftVariable; |
||
16 | use nystudio107\youtubeliveembed\models\Settings; |
||
17 | use nystudio107\youtubeliveembed\services\ServicesTrait; |
||
18 | use nystudio107\youtubeliveembed\variables\YoutubeLiveEmbedVariable; |
||
19 | use yii\base\Event; |
||
20 | |||
21 | /** |
||
22 | * Class YoutubeLiveEmbed |
||
23 | * |
||
24 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
25 | * @package YoutubeLiveEmbed |
||
0 ignored issues
–
show
|
|||
26 | * @since 1.0.0 |
||
0 ignored issues
–
show
|
|||
27 | */ |
||
0 ignored issues
–
show
|
|||
28 | class YoutubeLiveEmbed extends Plugin |
||
29 | { |
||
30 | // Traits |
||
31 | // ========================================================================= |
||
32 | |||
33 | use ServicesTrait; |
||
34 | |||
35 | // Static Properties |
||
36 | // ========================================================================= |
||
37 | |||
38 | /** |
||
0 ignored issues
–
show
|
|||
39 | * @var YoutubeLiveEmbed |
||
40 | */ |
||
41 | public static $plugin; |
||
42 | |||
43 | /** |
||
0 ignored issues
–
show
|
|||
44 | * @var string |
||
45 | */ |
||
46 | public static $youtubeChannelId; |
||
47 | |||
48 | // Public Properties |
||
49 | // ========================================================================= |
||
50 | |||
51 | /** |
||
0 ignored issues
–
show
|
|||
52 | * @var string |
||
53 | */ |
||
54 | public $schemaVersion = '1.0.10'; |
||
55 | |||
56 | /** |
||
0 ignored issues
–
show
|
|||
57 | * @var bool |
||
58 | */ |
||
59 | public $hasCpSection = false; |
||
60 | |||
61 | /** |
||
0 ignored issues
–
show
|
|||
62 | * @var bool |
||
63 | */ |
||
64 | public $hasCpSettings = true; |
||
65 | |||
66 | // Public Methods |
||
67 | // ========================================================================= |
||
68 | |||
69 | /** |
||
0 ignored issues
–
show
|
|||
70 | * @inheritdoc |
||
71 | */ |
||
0 ignored issues
–
show
|
|||
72 | public function init() |
||
73 | { |
||
74 | parent::init(); |
||
75 | self::$plugin = $this; |
||
76 | /** @var Settings $settings */ |
||
0 ignored issues
–
show
|
|||
77 | $settings = $this->getSettings(); |
||
78 | self::$youtubeChannelId = $settings->youtubeChannelId; |
||
79 | |||
80 | Event::on( |
||
81 | CraftVariable::class, |
||
82 | CraftVariable::EVENT_INIT, |
||
83 | function(Event $event) { |
||
0 ignored issues
–
show
|
|||
84 | /** @var CraftVariable $variable */ |
||
0 ignored issues
–
show
|
|||
85 | $variable = $event->sender; |
||
86 | $variable->set('youtubelive', YoutubeLiveEmbedVariable::class); |
||
87 | } |
||
88 | ); |
||
89 | |||
90 | Craft::info( |
||
91 | Craft::t( |
||
92 | 'youtubeliveembed', |
||
93 | '{name} plugin loaded', |
||
94 | ['name' => $this->name] |
||
95 | ), |
||
96 | __METHOD__ |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | // Protected Methods |
||
101 | // ========================================================================= |
||
102 | |||
103 | /** |
||
0 ignored issues
–
show
|
|||
104 | * @inheritdoc |
||
105 | */ |
||
0 ignored issues
–
show
|
|||
106 | protected function createSettingsModel() |
||
107 | { |
||
108 | return new Settings(); |
||
109 | } |
||
110 | |||
111 | /** |
||
0 ignored issues
–
show
|
|||
112 | * @inheritdoc |
||
113 | */ |
||
0 ignored issues
–
show
|
|||
114 | protected function settingsHtml(): string |
||
115 | { |
||
116 | return Craft::$app->view->renderTemplate( |
||
117 | 'youtubeliveembed/settings', |
||
118 | [ |
||
119 | 'settings' => $this->getSettings(), |
||
120 | ] |
||
121 | ); |
||
122 | } |
||
123 | } |
||
124 |