1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Theme editor |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\editor; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module as CoreModule; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Main class for Theme editor module |
16
|
|
|
*/ |
17
|
|
|
class Module |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Module class instance |
22
|
|
|
* @var \gplcart\core\Module $module |
23
|
|
|
*/ |
24
|
|
|
protected $module; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param CoreModule $module |
28
|
|
|
*/ |
29
|
|
|
public function __construct(CoreModule $module) |
30
|
|
|
{ |
31
|
|
|
$this->module = $module; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Implements hook "route.list" |
36
|
|
|
* @param array $routes |
37
|
|
|
*/ |
38
|
|
|
public function hookRouteList(array &$routes) |
39
|
|
|
{ |
40
|
|
|
$routes['admin/tool/editor'] = array( |
41
|
|
|
'access' => 'editor', |
42
|
|
|
'menu' => array('admin' => /* @text */'Theme editor'), |
43
|
|
|
'handlers' => array( |
44
|
|
|
'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'themeEditor') |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$routes['admin/tool/editor/(\w+)'] = array( |
49
|
|
|
'access' => 'editor', |
50
|
|
|
'handlers' => array( |
51
|
|
|
'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'listEditor') |
52
|
|
|
) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$routes['admin/tool/editor/(\w+)/([^/]+)'] = array( |
56
|
|
|
'access' => 'editor_content', |
57
|
|
|
'handlers' => array( |
58
|
|
|
'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'editEditor') |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Implements hook "construct.controller.backend" |
65
|
|
|
* @param \gplcart\core\controllers\backend\Controller $controller |
66
|
|
|
*/ |
67
|
|
|
public function hookConstructControllerBackend($controller) |
68
|
|
|
{ |
69
|
|
|
$this->setModuleAssets($controller); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Implements hook "user.role.permissions" |
74
|
|
|
* @param array $permissions |
75
|
|
|
*/ |
76
|
|
|
public function hookUserRolePermissions(array &$permissions) |
77
|
|
|
{ |
78
|
|
|
$permissions['editor'] = /* @text */'Theme editor: access'; |
79
|
|
|
$permissions['editor_edit'] = /* @text */'Theme editor: edit file'; |
80
|
|
|
$permissions['editor_content'] = /* @text */'Theme editor: access file content'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Sets module specific assets |
85
|
|
|
* @param \gplcart\core\controllers\backend\Controller $controller |
86
|
|
|
*/ |
87
|
|
|
protected function setModuleAssets($controller) |
88
|
|
|
{ |
89
|
|
|
if ($controller->path('^admin/tool/editor') && $this->module->isEnabled('codemirror')) { |
90
|
|
|
$this->getCodemirrorModule()->addLibrary($controller); |
91
|
|
|
$controller->setJs('system/modules/editor/js/common.js', array('aggregate' => false)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns CodeMirror module instance |
97
|
|
|
* @return \gplcart\modules\codemirror\Codemirror |
98
|
|
|
*/ |
99
|
|
|
protected function getCodemirrorModule() |
100
|
|
|
{ |
101
|
|
|
return $this->module->getInstance('codemirror'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|