-
Notifications
You must be signed in to change notification settings - Fork 5
/
Plugin.php
57 lines (49 loc) · 1.77 KB
/
Plugin.php
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
53
54
55
56
57
<?php namespace RainLab\BlogVideo;
use Backend;
use Controller;
use Backend\Classes\BackendController;
use System\Classes\PluginBase;
use RainLab\Blog\Controllers\Posts as PostsController;
use RainLab\Blog\Classes\TagProcessor;
class Plugin extends PluginBase
{
public $require = ['RainLab.Blog'];
public function pluginDetails()
{
return [
'name' => 'Blog Video Extension',
'description' => 'Adds responsive video embedding features to the RainLab Blog module.',
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-video-camera',
'homepage' => 'https://github.com/rainlab/blogvideo-plugin'
];
}
/**
* Register method, called when the plugin is first registered.
*/
public function register()
{
PostsController::extend(function($controller) {
if (!in_array(BackendController::$action, ['create', 'update'])) {
return;
}
$controller->addJs('/plugins/rainlab/blogvideo/assets/js/blog-video.js');
$controller->addCss('/plugins/rainlab/blogvideo/assets/css/blog-video.css');
});
/*
* Register the video tag processing callback
*/
TagProcessor::instance()->registerCallback(function($input, $preview) {
if (!$preview) {
return $input;
}
$popup = file_get_contents(__DIR__.'/partials/popup.htm');
return preg_replace('|\<img src="video" alt="([0-9]+)" \/>|m',
'<span class="video-placeholder" data-index="$1">
<a href="#">Click to embed a video...</a>
'.$popup.'
</span>',
$input);
});
}
}