1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Code Mirror |
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\codemirror; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module, |
13
|
|
|
gplcart\core\Library; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Main class for Code Mirror module |
17
|
|
|
*/ |
18
|
|
|
class Main |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Module class instance |
23
|
|
|
* @var \gplcart\core\Module $module |
24
|
|
|
*/ |
25
|
|
|
protected $module; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Library class instance |
29
|
|
|
* @var \gplcart\core\Library $library |
30
|
|
|
*/ |
31
|
|
|
protected $library; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Module $module |
35
|
|
|
* @param Library $library |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Module $module, Library $library) |
38
|
|
|
{ |
39
|
|
|
$this->module = $module; |
40
|
|
|
$this->library = $library; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Implements hook "library.list" |
45
|
|
|
* @param array $libraries |
46
|
|
|
*/ |
47
|
|
|
public function hookLibraryList(array &$libraries) |
48
|
|
|
{ |
49
|
|
|
$libraries['codemirror'] = array( |
50
|
|
|
'name' => /* @text */'Codemirror', |
51
|
|
|
'description' => /* @text */'In-browser code editor', |
52
|
|
|
'type' => 'asset', |
53
|
|
|
'module' => 'codemirror', |
54
|
|
|
'url' => 'https://codemirror.net', |
55
|
|
|
'download' => 'http://codemirror.net/codemirror.zip', |
56
|
|
|
'version_source' => array( |
57
|
|
|
'file' => 'vendor/codemirror/CodeMirror/package.json' |
58
|
|
|
), |
59
|
|
|
'files' => array( |
60
|
|
|
'vendor/codemirror/CodeMirror/lib/codemirror.js', |
61
|
|
|
'vendor/codemirror/CodeMirror/lib/codemirror.css', |
62
|
|
|
), |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Implements hook "route.list" |
68
|
|
|
* @param array $routes |
69
|
|
|
*/ |
70
|
|
|
public function hookRouteList(array &$routes) |
71
|
|
|
{ |
72
|
|
|
$routes['admin/module/settings/codemirror'] = array( |
73
|
|
|
'access' => 'module_edit', |
74
|
|
|
'handlers' => array( |
75
|
|
|
'controller' => array('gplcart\\modules\\codemirror\\controllers\\Settings', 'editSettings') |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Implements hook "module.enable.after" |
82
|
|
|
*/ |
83
|
|
|
public function hookModuleEnableAfter() |
84
|
|
|
{ |
85
|
|
|
$this->library->clearCache(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Implements hook "module.disable.after" |
90
|
|
|
*/ |
91
|
|
|
public function hookModuleDisableAfter() |
92
|
|
|
{ |
93
|
|
|
$this->library->clearCache(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Implements hook "module.install.after" |
98
|
|
|
*/ |
99
|
|
|
public function hookModuleInstallAfter() |
100
|
|
|
{ |
101
|
|
|
$this->library->clearCache(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Implements hook "module.uninstall.after" |
106
|
|
|
*/ |
107
|
|
|
public function hookModuleUninstallAfter() |
108
|
|
|
{ |
109
|
|
|
$this->library->clearCache(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Add CodeMirror library and extra files |
114
|
|
|
* @param \gplcart\core\Controller $controller |
115
|
|
|
*/ |
116
|
|
|
public function addLibrary($controller) |
117
|
|
|
{ |
118
|
|
|
$settings = $this->module->getSettings('codemirror'); |
119
|
|
|
$controller->setJsSettings('codemirror', $settings); |
120
|
|
|
|
121
|
|
|
$controller->addAssetLibrary('codemirror'); |
122
|
|
|
$controller->setCss("system/modules/codemirror/vendor/codemirror/CodeMirror/theme/{$settings['theme']}.css"); |
123
|
|
|
|
124
|
|
|
foreach ($settings['mode'] as $mode) { |
125
|
|
|
$controller->setJs("system/modules/codemirror/vendor/codemirror/CodeMirror/mode/$mode/$mode.js"); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|