=2.0.10",
25 | "php": ">=5.5.0",
26 | "loveorigami/yii2-jsoneditor": "*"
27 | },
28 | "autoload": {
29 | "psr-4": {
30 | "lo\\plugins\\": "src/"
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/docs/create_plugin.md:
--------------------------------------------------------------------------------
1 | # Create your plugin
2 |
3 | To create your plugin you need to run the following required steps
4 |
5 | ### 1. Create in dir with our plugins `@common\plugins` new folder:
6 | * For example: `test`
7 |
8 | ### 2. In this folder create:
9 | * `README.md` with usage instruction for this plugin
10 | * New class `TestPlugin`, with information about plugin
11 |
12 | ```php
13 |
14 | use lo\plugins\BasePlugin;
15 |
16 | namespace common\plugins\test;
17 |
18 | /**
19 | * Plugin Name: Test plugin
20 | * Plugin URI:
21 | * Version: 1.0
22 | * Description: Small test plugin
23 | * Author: Andrey Lukyanov
24 | * Author URI: https://github.com/loveorigami
25 | */
26 |
27 | class TestPlugin extends BasePlugin
28 | {
29 | ...
30 | }
31 |
32 | ```
33 |
34 | * Add static property `$appId`
35 |
36 | ```php
37 |
38 | /**
39 | * Application id, where plugin will be worked.
40 | * @var appId integer
41 | */
42 | public static $appId = self::APP_FRONTEND;
43 |
44 | ```
45 |
46 | * And default configuration
47 |
48 | ```php
49 | /**
50 | * Default configuration for plugin.
51 | * @var config array()
52 | */
53 | public static $config = [
54 | 'term' => 'Hello, world!',
55 | ];
56 | ```
57 |
58 | * Then, assign a template events
59 |
60 | ```php
61 | public static function events()
62 | {
63 | return [
64 | $eventSenderClassName => [
65 | $eventName => [$handlerMethodName, self::$config]
66 | ],
67 | ];
68 | }
69 | ```
70 |
71 | for example:
72 |
73 | ```php
74 | public static function events()
75 | {
76 | return [
77 | yii\web\Response::class => [
78 | yii\web\Response::EVENT_AFTER_PREPARE => ['foo', self::$config]
79 | ],
80 | ];
81 | }
82 | ```
83 | more about `$eventSenderClassName` and `$eventName` you can be found on the info tab of this module
84 |
85 | 
86 |
87 | * Create a handler method `foo` with the necessary logic
88 |
89 | ```php
90 | /**
91 | * handler method foo
92 | */
93 | public static function foo($event)
94 | {
95 | $term = ($event->data['term']) ? $event->data['term'] : self::$config['term'];
96 | $event->sender->content = str_replace($term,"
$term
", $event->sender->content);
97 | return true;
98 | }
99 | ```
100 |
101 | * That's all. Then you have to [install](install_plugin.md) this plugin
--------------------------------------------------------------------------------
/docs/img/demo_events.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/demo_events.jpg
--------------------------------------------------------------------------------
/docs/img/event_edit.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/event_edit.jpg
--------------------------------------------------------------------------------
/docs/img/tab_events.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/tab_events.jpg
--------------------------------------------------------------------------------
/docs/img/tab_info.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/tab_info.jpg
--------------------------------------------------------------------------------
/docs/img/tab_install.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/tab_install.jpg
--------------------------------------------------------------------------------
/docs/img/tab_plugins.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loveorigami/yii2-plugins-system/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/docs/img/tab_plugins.jpg
--------------------------------------------------------------------------------
/docs/install_plugin.md:
--------------------------------------------------------------------------------
1 | # Install plugin
2 |
3 | After [creating](create_plugin.md) your `TestPlugin` first, you must make sure that the our directory plugins included in the module configuration
4 |
5 | ```php
6 | 'modules' => [
7 | 'plugins' => [
8 | 'class' => 'lo\plugins\Module',
9 | 'pluginsDir'=>[
10 | '@lo/plugins/plugins', // default dir with core plugins
11 | '@common/plugins', // dir with our plugins
12 | ]
13 | ],
14 | ],
15 | ```
16 |
17 | * Then go to the install tab and press button
18 |
19 | 
20 |
21 | * Go to the events tab for enabled and configure plugin event
22 |
23 | 
24 |
25 | * If you want, change configuration, update...
26 |
27 | 
28 |
29 | * Go to the website to see the result
30 |
31 | 
--------------------------------------------------------------------------------
/src/BasePlugin.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | abstract class BasePlugin implements IPlugin
12 | {
13 | const APP_FRONTEND = 1;
14 | const APP_BACKEND = 2;
15 | const APP_COMMON = 3;
16 | const APP_API = 4;
17 | const APP_CONSOLE = 5;
18 |
19 | /**
20 | * Application id, where plugin will be worked.
21 | * Support values: frontend, backend, common, api
22 | * Default: frontend
23 | * @var string $appId
24 | */
25 | public static $appId = self::APP_FRONTEND;
26 |
27 | /**
28 | * Default configuration for plugin.
29 | * @var array $config
30 | */
31 | public static $config = [];
32 |
33 | }
--------------------------------------------------------------------------------
/src/BaseShortcode.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | abstract class BaseShortcode implements IShortcode
12 | {
13 | const APP_FRONTEND = 1;
14 | const APP_BACKEND = 2;
15 | const APP_COMMON = 3;
16 |
17 | const SHORTCODES_METHOD = 'shortcodes';
18 |
19 | /**
20 | * Application id, where plugin will be worked.
21 | * Support values: frontend, backend, common, api
22 | * Default: frontend
23 | * @var string $appId
24 | */
25 | public static $appId = self::APP_FRONTEND;
26 |
27 | }
--------------------------------------------------------------------------------
/src/Module.php:
--------------------------------------------------------------------------------
1 | i18n->translations['plugin'])) {
21 | Yii::$app->i18n->translations['plugin'] = [
22 | 'class' => 'yii\i18n\PhpMessageSource',
23 | 'sourceLanguage' => 'en',
24 | 'basePath' => '@lo/plugins/messages'
25 | ];
26 | }
27 |
28 | //user did not define the Navbar?
29 | if (!$this->pluginsDir) {
30 | throw new InvalidConfigException('"pluginsDir" must be set');
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/components/FlashNotification.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class FlashNotification
13 | {
14 | /**
15 | * @param $message
16 | */
17 | public function success($message)
18 | {
19 | Yii::$app->session->setFlash('success', $message);
20 | }
21 |
22 | /**
23 | * @param $message
24 | */
25 | public function error($message)
26 | {
27 | Yii::$app->session->setFlash('error', $message);
28 | }
29 | }
--------------------------------------------------------------------------------
/src/components/PluginsManager.php:
--------------------------------------------------------------------------------
1 |
18 | */
19 | class PluginsManager extends Component implements BootstrapInterface
20 | {
21 | /**
22 | * Application id for category plugins.
23 | * Support constants: APP_FRONTEND, APP_BACKEND, APP_COMMON
24 | * @var integer $appId
25 | */
26 | public $appId;
27 |
28 | /**
29 | * Attaches events to all app models.
30 | * @var bool
31 | */
32 | public $enablePlugins = true;
33 |
34 | /**
35 | * Shortcodes plugin
36 | * @var bool
37 | */
38 | public $shortcodesParse = true;
39 |
40 | /**
41 | * Ignore blocks from parsing.
42 | * Set as array regex ['openTag' => 'closeTag']
43 | * ```
44 | * [
45 | * '
]*>' => '<\/pre>',
46 | * '
18 |
19 | = $this->render('/_menu') ?>
20 |
21 |
22 |
23 |
24 |
MVC
25 |
26 |
27 | Controller or Module |
28 |
29 |
30 | EVENT_BEFORE_ACTION |
31 | beforeAction |
32 |
33 |
34 | EVENT_AFTER_ACTION |
35 | afterAction |
36 |
37 |
38 | Model |
39 |
40 |
41 | EVENT_BEFORE_VALIDATE |
42 | beforeValidate |
43 |
44 |
45 | EVENT_AFTER_VALIDATE |
46 | afterValidate |
47 |
48 |
49 | yii\base\View |
50 |
51 |
52 | EVENT_BEGIN_PAGE |
53 | beginPage |
54 |
55 |
56 | EVENT_END_PAGE |
57 | endPage |
58 |
59 |
60 | EVENT_BEFORE_RENDER |
61 | beforeRender |
62 |
63 |
64 | EVENT_AFTER_RENDER |
65 | afterRender |
66 |
67 |
68 | yii\web\View |
69 |
70 |
71 | EVENT_BEGIN_BODY |
72 | beginBody |
73 |
74 |
75 | EVENT_END_BODY |
76 | endBody |
77 |
78 |
79 |
80 |
Components
81 |
82 |
83 | MessageSource |
84 |
85 |
86 | EVENT_MISSING_TRANSLATION |
87 | missingTranslation |
88 |
89 |
90 | BaseMailer |
91 |
92 |
93 | EVENT_BEFORE_SEND |
94 | beforeSend |
95 |
96 |
97 | EVENT_AFTER_SEND |
98 | afterSend |
99 |
100 |
101 | User |
102 |
103 |
104 | EVENT_BEFORE_LOGIN |
105 | beforeLogin |
106 |
107 |
108 | EVENT_AFTER_LOGIN |
109 | afterLogin |
110 |
111 |
112 | EVENT_BEFORE_LOGOUT |
113 | beforeLogout |
114 |
115 |
116 | EVENT_AFTER_LOGOUT |
117 | afterLogout |
118 |
119 |
120 |
121 |
122 |
123 |
Database
124 |
125 |
126 | BaseActiveRecord |
127 |
128 |
129 | EVENT_INIT
130 |
131 | |
132 | init |
133 |
134 |
135 | EVENT_AFTER_FIND |
136 | afterFind |
137 |
138 |
139 | EVENT_BEFORE_INSERT |
140 | beforeInsert |
141 |
142 |
143 | EVENT_AFTER_INSERT |
144 | afterInsert |
145 |
146 |
147 | EVENT_BEFORE_UPDATE |
148 | beforeUpdate |
149 |
150 |
151 | EVENT_AFTER_UPDATE |
152 | afterUpdate |
153 |
154 |
155 | EVENT_BEFORE_DELETE |
156 | beforeDelete |
157 |
158 |
159 | EVENT_AFTER_DELETE |
160 | afterDelete |
161 |
162 |
163 | ActiveQuery |
164 |
165 |
166 | EVENT_INIT |
167 | init |
168 |
169 |
170 | Connection |
171 |
172 |
173 | EVENT_AFTER_OPEN |
174 | afterOpen |
175 |
176 |
177 | EVENT_BEGIN_TRANSACTION |
178 | beginTransaction |
179 |
180 |
181 | EVENT_COMMIT_TRANSACTION |
182 | commitTransaction |
183 |
184 |
185 | EVENT_ROLLBACK_TRANSACTION |
186 | rollbackTransaction |
187 |
188 |
189 |
190 |
Request
191 |
192 |
193 | yii\base\Application |
194 |
195 |
196 | EVENT_BEFORE_REQUEST |
197 | beforeRequest |
198 |
199 |
200 | EVENT_AFTER_REQUEST |
201 | afterRequest |
202 |
203 |
204 | Response |
205 |
206 |
207 | EVENT_BEFORE_SEND |
208 | beforeSend |
209 |
210 |
211 | EVENT_AFTER_SEND |
212 | afterSend |
213 |
214 |
215 | EVENT_AFTER_PREPARE |
216 | afterPrepare |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
--------------------------------------------------------------------------------
/src/views/plugin/install.php:
--------------------------------------------------------------------------------
1 | title = Yii::t('plugin', 'Install');
12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('plugin', 'Items'), 'url' => ['info']];
13 | $this->params['breadcrumbs'][] = $this->title;
14 | ?>
15 |
16 |
17 | = $this->render('/_menu') ?>
18 |
20 |
21 | Plugin name |
22 | Ver. |
23 | Author |
24 | Plugin description |
25 | |
26 |
27 | ';
28 | ?>
29 |
30 | = ListView::widget([
31 | 'dataProvider' => $dataProvider,
32 | 'layout' => "$thead{items}",
33 | 'itemView' => '_item',
34 | 'options' => [
35 | 'tag' => 'table',
36 | 'class' => 'table table-bordered table-striped',
37 | ],
38 | 'itemOptions' => [
39 | 'class' => 'item',
40 | 'tag' => false,
41 | ],
42 | ]) ?>
43 |
44 | = LinkPager::widget([
45 | 'pagination' => $dataProvider->pagination,
46 | ]); ?>
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/views/plugin/update.php:
--------------------------------------------------------------------------------
1 | title = Yii::t('plugin', 'Update {modelClass}: ', [
9 | 'modelClass' => 'Item',
10 | ]) . ' ' . $model->name;
11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('plugin', 'Items'), 'url' => ['index']];
12 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
13 | $this->params['breadcrumbs'][] = Yii::t('plugin', 'Update');
14 | ?>
15 |
16 |
17 | = $this->render('_form', [
18 | 'model' => $model,
19 | ]) ?>
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/views/plugin/view.php:
--------------------------------------------------------------------------------
1 | title = $model->name;
10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('plugin', 'Items'), 'url' => ['index']];
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
16 | = Html::a(Yii::t('plugin', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
17 | = Html::a(Yii::t('plugin', 'Delete'), ['delete', 'id' => $model->id], [
18 | 'class' => 'btn btn-danger',
19 | 'data' => [
20 | 'confirm' => Yii::t('plugin', 'Are you sure you want to delete this item?'),
21 | 'method' => 'post',
22 | ],
23 | ]) ?>
24 |
25 |
26 | = DetailView::widget([
27 | 'model' => $model,
28 | 'attributes' => [
29 | 'id',
30 | 'name',
31 | 'url:url',
32 | 'version',
33 | 'text:ntext',
34 | 'author',
35 | 'author_url:url',
36 | 'status',
37 | ],
38 | ]) ?>
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/views/shortcode/_form.php:
--------------------------------------------------------------------------------
1 |
16 |
17 |
65 |
--------------------------------------------------------------------------------
/src/views/shortcode/_search.php:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 | ['index'],
17 | 'method' => 'get',
18 | ]); ?>
19 |
20 | = $form->field($model, 'id') ?>
21 | = $form->field($model, 'tag') ?>
22 |
23 |
24 | = Html::submitButton(Yii::t('plugin', 'Search'), ['class' => 'btn btn-primary']) ?>
25 | = Html::resetButton(Yii::t('plugin', 'Reset'), ['class' => 'btn btn-default']) ?>
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/views/shortcode/index.php:
--------------------------------------------------------------------------------
1 | title = Yii::t('plugin', 'Shortcodes');
17 | $this->params['breadcrumbs'][] = $this->title;
18 | ?>
19 |
20 |
21 | = $this->render('/_menu') ?>
22 |
23 | = GridView::widget([
24 | 'dataProvider' => $dataProvider,
25 | 'filterModel' => $searchModel,
26 | 'columns' => [
27 | ['class' => 'yii\grid\SerialColumn'],
28 | [
29 | 'attribute' => 'app_id',
30 | 'label' => Yii::t('plugin', 'App'),
31 | 'options' => ['style' => 'width: 25px; align: center;'],
32 | 'value' => function ($model) {
33 | return BS::appLabel($model->app_id);
34 | },
35 | 'filter' => ArrayHelper::map(App::find()->orderBy('name')->all(), 'id', 'name'),
36 | 'format' => "raw"
37 | ],
38 | 'tag',
39 | 'tooltip',
40 | [
41 | 'attribute' => 'data',
42 | 'value' => function ($model) {
43 | return StringHelper::truncate($model->data, 60);
44 | },
45 | ],
46 | [
47 | 'attribute' => 'status',
48 | 'options' => ['style' => 'width: 75px; align: center;'],
49 | 'value' => function ($model) {
50 | return $model->status == $model::STATUS_ACTIVE ? BS::label('Enabled', BS::TYPE_SUCCESS) : BS::label('Disabled', BS::TYPE_DANGER);
51 | },
52 | 'filter' => [
53 | 1 => Yii::t('plugin', 'Enabled'),
54 | 0 => Yii::t('plugin', 'Disabled')
55 | ],
56 | 'format' => "raw"
57 | ],
58 | [
59 | 'class' => 'yii\grid\ActionColumn',
60 | 'template' => '{update} {delete}',
61 | 'options' => ['style' => 'width: 75px;'],
62 | 'buttons' => [
63 | 'update' => function ($url) {
64 | return Html::a(BS::icon('pencil'), $url, [
65 | 'class' => 'btn btn-xs btn-primary',
66 | 'title' => Yii::t('plugin', 'Update'),
67 | ]);
68 | },
69 | 'delete' => function ($url) {
70 | return Html::a(BS::icon('trash'), $url, [
71 | 'class' => 'btn btn-xs btn-danger',
72 | 'data-method' => 'post',
73 | 'data-confirm' => Yii::t('plugin', 'Are you sure to delete this item?'),
74 | 'title' => Yii::t('plugin', 'Delete'),
75 | ]);
76 | },
77 | ]
78 | ],
79 | ],
80 | ]); ?>
81 |
82 |
83 |
--------------------------------------------------------------------------------
/src/views/shortcode/update.php:
--------------------------------------------------------------------------------
1 | title = Yii::t('plugin', 'Update {modelClass}: ', [
7 | 'modelClass' => 'Shortcode',
8 | ]) . ' ' . $model->tag;
9 | $this->params['breadcrumbs'][] = ['label' => Yii::t('plugin', 'Shortcodes'), 'url' => ['index']];
10 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
11 | $this->params['breadcrumbs'][] = Yii::t('plugin', 'Update');
12 | ?>
13 |
14 |
15 | = $this->render('_form', [
16 | 'model' => $model,
17 | ]) ?>
18 |
19 |
20 |
--------------------------------------------------------------------------------