-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlugin.php
More file actions
101 lines (87 loc) · 3.47 KB
/
Plugin.php
File metadata and controls
101 lines (87 loc) · 3.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php namespace Linkonoid\ShortcodesEngine;
use Less_Parser;
use Event;
use Response;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use Linkonoid\ShortcodesEngine\Classes\ShortcodesManager;
use Linkonoid\ShortcodesEngine\Classes\Shortcode;
use Linkonoid\ShortcodesEngine\Classes\ShortcodeObject;
/**
* @package linkonoid\shortcodesEngine
* @author Max Barulin (https://github.com/linkonoid)
*/
class Plugin extends PluginBase
{
protected $shortcodesManager;
/**
* @var array Plugin dependencies
*/
public $require = [];
public function pluginDetails()
{
return [
'name' => 'ShortcodesEngine',
'description' => 'Shortcodes engine for OctoberCMS',
'author' => 'Linkonoid',
'icon' => 'icon-code',
'homepage' => 'https://github.com/linkonoid'
];
}
public function registerPermissions()
{
return [
'linkonoid.shortcodesengine.access_settings' => [
'tab' => 'linkonoid.shortcodesengine::lang.plugin.settings.permissions.tab',
'label' => 'linkonoid.shortcodesengine::lang.plugin.settings.permissions.label',
],
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'linkonoid.shortcodesengine::lang.plugin.settings.label',
'description' => 'linkonoid.shortcodesengine::lang.plugin.settings.description',
'category' => 'Shortcodes',
'icon' => 'icon-code',
'class' => 'Linkonoid\ShortcodesEngine\Models\Settings',
'keywords' => 'linkonoid.shortcodesengine::lang.plugin.settings.keywords',
'order' => 550,
'permissions' => ['linkonoid.shortcodesengine.access_settings']
]
];
}
public function registerMarkupTags()
{
return [
'filters' => [
'shortcodes' => [$this->shortcodesManager, 'processshortcodes']
]
];
}
public function boot()
{
$shortcodesManager = $this->shortcodesManager = new shortcodesManager();
Event::listen('cms.page.init', function ($controller, $page) {
$this->shortcodesManager->resetObjects();
$this->shortcodesManager->resetAssets();
$onshortcodeHandlers = Event::fire('linkonoid.shortcodesengine.onshortcodeHandlers',[$this->shortcodesManager]);
});
Event::listen('linkonoid.shortcodesengine.onshortcodeHandlers', function () {
$this->shortcodesManager->registerUsershortcodes();
$this->shortcodesManager->registerAllshortcodes(__DIR__.'/shortcodes');
});
Event::listen('cms.page.start', function ($controller) {
$shortcode_assets = $this->shortcodesManager->getAssets();
if (!empty($shortcode_assets)) {
if (array_key_exists('css',$shortcode_assets)) foreach ($shortcode_assets['css'] as $key => $value) if (!empty($value)) $controller->addCss($value,'core');
if (array_key_exists('js',$shortcode_assets)) foreach ($shortcode_assets['js'] as $key => $value) if (!empty($value)) $controller->addJs($value);
//plugins/linkonoid/shortcodesengine/assets/js/test.js - alert test function
}
});
Event::listen('cms.page.postprocess', function ($controller, $url, $page, $dataHolder) {
$dataHolder->content = $this->shortcodesManager->processContent($dataHolder->content);
});
}
}