-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvents.php
More file actions
52 lines (41 loc) · 1.23 KB
/
Events.php
File metadata and controls
52 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Banner
* @link https://www.cuzy.app
* @license https://www.cuzy.app/cuzy-license
* @author [Marc FARRE](https://marc.fun)
*/
namespace humhub\modules\banner;
use humhub\components\View;
use humhub\helpers\Html;
use humhub\modules\banner\assets\BannerAssets;
use Yii;
use yii\base\Event;
class Events
{
public static function onViewBeginBody(Event $event)
{
if (Yii::$app->request->isAjax) {
return;
}
/** @var Module $module */
$module = Yii::$app->getModule('banner');
$configuration = $module->getConfiguration();
if (!$configuration->enabled) {
return;
}
$closeButton = $configuration->closeButton;
$content = Yii::$app->user->isGuest ? $configuration->contentGuests : $configuration->content;
if (empty($content)) {
return;
}
$content = str_ireplace('<script>', '<script ' . Html::nonce() . '>', $content);
/** @var View $view */
$view = $event->sender;
BannerAssets::register($view);
echo Yii::$app->controller->renderPartial('@banner/views/banner/index', [
'content' => $content,
'closeButton' => $closeButton,
]);
}
}