forked from gergo85/oc-paste-content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
190 lines (171 loc) · 6.21 KB
/
Plugin.php
File metadata and controls
190 lines (171 loc) · 6.21 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php namespace Indikator\Paste;
use System\Classes\PluginBase;
use Backend;
use Lang;
use Indikator\Paste\Models\Text;
use Indikator\Paste\Models\Code;
use Indikator\Paste\Models\Block;
use Backend\FormWidgets\RichEditor;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'indikator.paste::lang.plugin.name',
'description' => 'indikator.paste::lang.plugin.description',
'author' => 'indikator.paste::lang.plugin.author',
'icon' => 'icon-clipboard',
'homepage' => 'https://github.com/gergo85/oc-paste-content'
];
}
public function registerNavigation()
{
return [
'paste' => [
'label' => 'indikator.paste::lang.plugin.name',
'url' => Backend::url('indikator/paste/block'),
'icon' => 'icon-clipboard',
'iconSvg' => 'plugins/indikator/paste/assets/images/paste-icon.svg',
'permissions' => ['indikator.paste.*'],
'order' => 201,
'sideMenu' => [
'block' => [
'label' => 'indikator.paste::lang.menu.block',
'url' => Backend::url('indikator/paste/block'),
'icon' => 'icon-th-large',
'permissions' => ['indikator.paste.block']
],
'text' => [
'label' => 'indikator.paste::lang.menu.text',
'url' => Backend::url('indikator/paste/text'),
'icon' => 'icon-file-text',
'permissions' => ['indikator.paste.text']
],
'code' => [
'label' => 'indikator.paste::lang.menu.code',
'url' => Backend::url('indikator/paste/code'),
'icon' => 'icon-file-code-o',
'permissions' => ['indikator.paste.code']
]
]
]
];
}
public function registerComponents()
{
return [
'Indikator\Paste\Components\Blocks' => 'blocks'
];
}
public function registerPermissions()
{
return [
'indikator.paste.block' => [
'tab' => 'indikator.paste::lang.plugin.name',
'label' => 'indikator.paste::lang.permission.block',
'order' => 100,
'roles' => ['publisher']
],
'indikator.paste.text' => [
'tab' => 'indikator.paste::lang.plugin.name',
'label' => 'indikator.paste::lang.permission.text',
'order' => 200,
'roles' => ['publisher']
],
'indikator.paste.code' => [
'tab' => 'indikator.paste::lang.plugin.name',
'label' => 'indikator.paste::lang.permission.code',
'order' => 300,
'roles' => ['publisher']
]
];
}
public function registerListColumnTypes()
{
return [
'paste_status' => function($value) {
$text = [
1 => 'active',
2 => 'inactive'
];
$class = [
1 => 'text-info',
2 => 'text-danger'
];
return '<span class="oc-icon-circle '.$class[$value].'">'.Lang::get('indikator.content::lang.form.status_'.$text[$value]).'</span>';
}
];
}
public function registerMarkupTags()
{
return [
'filters' => [
'paste' => [$this, 'paste']
],
'functions' => [
'paste' => function($filter = 'text', $param = 0) {
if ($filter == 'text') {
if (is_string($param) && Text::where(['code' => $param, 'status' => 1])->count() == 1) {
return Text::where('code', $param)->value('content');
}
else if (is_numeric($param) && Text::where(['id' => $param, 'status' => 1])->count() == 1) {
return Text::where('id', $param)->value('content');
}
}
else if ($filter == 'code') {
if (is_string($param) && Code::where(['code' => $param, 'status' => 1])->count() == 1) {
return Code::where('code', $param)->value('content');
}
else if (is_numeric($param) && Code::where(['id' => $param, 'status' => 1])->count() == 1) {
return Code::where('id', $param)->value('content');
}
}
return '';
}
]
];
}
public function paste($text)
{
$text = $this->pasteContent($text, 'text');
$text = $this->pasteContent($text, 'code');
return $text;
}
public function pasteContent($text = '', $type = 'text')
{
if ($type == 'text') {
$sql = Text::get();
}
else {
$sql = Code::get();
}
foreach ($sql as $item) {
if ($item->status == 1) {
$replace = $item->content;
}
else {
$replace = '';
}
$text = str_replace(
[
'{{'.$item->code.'}}',
'{{ '.$item->code.'}}',
'{{'.$item->code.' }}',
'{{ '.$item->code.' }}'
],
$replace,
$text
);
}
return $text;
}
public function boot()
{
if (Text::count() + Code::count() > 0) {
RichEditor::extend(function($widget) {
$widget->addJs('/indikator/paste/list.js');
$widget->addJs('/plugins/indikator/paste/assets/js/froala.paste.plugin.js');
});
}
}
}