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 |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2019 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
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 |
|
|
|
|
25
|
|
|
* @package YoutubeLiveEmbed |
|
|
|
|
26
|
|
|
* @since 1.0.0 |
|
|
|
|
27
|
|
|
*/ |
|
|
|
|
28
|
|
|
class YoutubeLiveEmbed extends Plugin |
29
|
|
|
{ |
30
|
|
|
// Traits |
31
|
|
|
// ========================================================================= |
32
|
|
|
|
33
|
|
|
use ServicesTrait; |
34
|
|
|
|
35
|
|
|
// Static Properties |
36
|
|
|
// ========================================================================= |
37
|
|
|
|
38
|
|
|
/** |
|
|
|
|
39
|
|
|
* @var YoutubeLiveEmbed |
40
|
|
|
*/ |
41
|
|
|
public static $plugin; |
42
|
|
|
|
43
|
|
|
/** |
|
|
|
|
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
public static $youtubeChannelId; |
47
|
|
|
|
48
|
|
|
// Public Properties |
49
|
|
|
// ========================================================================= |
50
|
|
|
|
51
|
|
|
/** |
|
|
|
|
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
public $schemaVersion = '1.0.10'; |
55
|
|
|
|
56
|
|
|
/** |
|
|
|
|
57
|
|
|
* @var bool |
58
|
|
|
*/ |
59
|
|
|
public $hasCpSection = false; |
60
|
|
|
|
61
|
|
|
/** |
|
|
|
|
62
|
|
|
* @var bool |
63
|
|
|
*/ |
64
|
|
|
public $hasCpSettings = true; |
65
|
|
|
|
66
|
|
|
// Public Methods |
67
|
|
|
// ========================================================================= |
68
|
|
|
|
69
|
|
|
/** |
|
|
|
|
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
|
|
|
|
72
|
|
|
public function init() |
73
|
|
|
{ |
74
|
|
|
parent::init(); |
75
|
|
|
self::$plugin = $this; |
76
|
|
|
/** @var Settings $settings */ |
|
|
|
|
77
|
|
|
$settings = $this->getSettings(); |
78
|
|
|
self::$youtubeChannelId = $settings->youtubeChannelId; |
79
|
|
|
|
80
|
|
|
Event::on( |
81
|
|
|
CraftVariable::class, |
82
|
|
|
CraftVariable::EVENT_INIT, |
83
|
|
|
function(Event $event) { |
|
|
|
|
84
|
|
|
/** @var CraftVariable $variable */ |
|
|
|
|
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
|
|
|
/** |
|
|
|
|
104
|
|
|
* @inheritdoc |
105
|
|
|
*/ |
|
|
|
|
106
|
|
|
protected function createSettingsModel() |
107
|
|
|
{ |
108
|
|
|
return new Settings(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
|
|
|
|
112
|
|
|
* @inheritdoc |
113
|
|
|
*/ |
|
|
|
|
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
|
|
|
|