-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
167 lines (151 loc) · 4.1 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
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
<?php
/**
* Plugin.php
*
* This file is part of the Xpressengine package.
*
* PHP version 7
*
* @category Page
* @package Xpressengine\Plugins\Page
* @author XE Developers <[email protected]>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
namespace Xpressengine\Plugins\Page;
use Route;
use XeConfig;
use Xpressengine\Plugin\AbstractPlugin;
use XeLang;
use Xpressengine\Plugins\Page\Migrations\PageCommentTargetMigration;
use Xpressengine\Plugins\Page\Module\Page;
/**
* Plugin
*
* @category Page
* @package Xpressengine\Plugins\Page
* @author XE Developers <[email protected]>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
class Plugin extends AbstractPlugin
{
/**
* install
*
* @return void
*/
public function install()
{
$this->importLang();
(new PageCommentTargetMigration())->up();
}
/**
* update
*
* @return void
*
* @throws \Exception
*/
public function update()
{
$this->importLang();
// v0.9.11
$pageCommentTargetMigration = new PageCommentTargetMigration();
if ($pageCommentTargetMigration->tableExists() === false) {
$pageCommentTargetMigration->up();
$pageCommentTargetMigration->originDataMigration();
}
}
/**
* import lang
*
* @return void
*/
private function importLang()
{
XeLang::putFromLangDataSource(self::getId(), __DIR__.'/langs/lang.php');
}
/**
* activate
*
* @param null $installedVersion installed version
* @return void
*/
public function activate($installedVersion = null)
{
if (XeConfig::get('module/page@page') === null) {
XeConfig::add('module/page@page', []);
}
}
/**
* boot
*
* @return void
*/
public function boot()
{
$this->routes();
}
/**
* register
*
* @return void
*/
public function register()
{
$app = app();
$app->singleton(PageHandler::class, function ($app) {
return new PageHandler(
$app['xe.document'],
$app['xe.plugin.comment']->getHandler(),
$app['xe.config'],
$app['auth']->guard()
);
});
$app->alias(PageHandler::class, 'xe.page.handler');
}
/**
* register route
*
* @return void
*/
private function routes()
{
Route::settings(Page::getId(), function () {
Route::get('edit/{pageId}', ['as' => 'manage.plugin.page.edit', 'uses' => 'PageManageController@edit']);
Route::post(
'update/{pageId}',
['as' => 'manage.plugin.page.update', 'uses' => 'PageManageController@update']
);
Route::get(
'editor/edit/{pageId}',
['as' => 'manage.plugin.page.editor', 'uses' => 'PageManageController@editEditor']
);
Route::get(
'skin/edit/{pageId}',
['as' => 'manage.plugin.page.skin', 'uses' => 'PageManageController@editSkin']
);
}, ['namespace' => 'Xpressengine\Plugins\Page\Controller']);
Route::instance(Page::getId(), function () {
Route::get('/', ['as' => 'index', 'uses' => 'PageUserController@index']);
Route::post('/preview', ['as' => 'preview', 'uses' => 'PageUserController@preview']);
}, ['namespace' => 'Xpressengine\Plugins\Page\Controller']);
}
/**
* check update
*
* @return bool
*/
public function checkUpdated()
{
$checkUpdate = true;
// v0.9.11
if ((new PageCommentTargetMigration())->tableExists() === false) {
$checkUpdate = false;
}
return $checkUpdate;
}
}