1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Summernote |
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\summernote; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module, |
13
|
|
|
gplcart\core\Library; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Main class for Summernote 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['summernote'] = array( |
50
|
|
|
'name' => /* @text */'Summernote', |
51
|
|
|
'description' => /* @text */'Super simple WYSIWYG Editor', |
52
|
|
|
'type' => 'asset', |
53
|
|
|
'module' => 'summernote', |
54
|
|
|
'url' => 'https://github.com/summernote/summernote', |
55
|
|
|
'download' => 'https://github.com/summernote/summernote/archive/v0.8.3.zip', |
56
|
|
|
'version_source' => array( |
57
|
|
|
'file' => 'vendor/summernote/summernote/dist/summernote.min.js', |
58
|
|
|
'pattern' => '/v(\\d+\\.+\\d+\\.+\\d+)/' |
59
|
|
|
), |
60
|
|
|
'files' => array( |
61
|
|
|
'vendor/summernote/summernote/dist/summernote.min.js', |
62
|
|
|
'vendor/summernote/summernote/dist/summernote.css' |
63
|
|
|
), |
64
|
|
|
'dependencies' => array( |
65
|
|
|
'jquery' => '>= 1.9.0', |
66
|
|
|
'bootstrap' => '>= 3.0.1' |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Implements hook "route.list" |
73
|
|
|
* @param array $routes |
74
|
|
|
*/ |
75
|
|
|
public function hookRouteList(array &$routes) |
76
|
|
|
{ |
77
|
|
|
$routes['admin/module/settings/summernote'] = array( |
78
|
|
|
'access' => 'module_edit', |
79
|
|
|
'handlers' => array( |
80
|
|
|
'controller' => array('gplcart\\modules\\summernote\\controllers\\Settings', 'editSettings') |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Implements hook "construct.controller.backend" |
87
|
|
|
* @param \gplcart\core\controllers\backend\Controller $controller |
88
|
|
|
*/ |
89
|
|
|
public function hookConstructControllerBackend($controller) |
90
|
|
|
{ |
91
|
|
|
$this->setModuleAssets($controller); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Implements hook "module.enable.after" |
96
|
|
|
*/ |
97
|
|
|
public function hookModuleEnableAfter() |
98
|
|
|
{ |
99
|
|
|
$this->library->clearCache(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Implements hook "module.disable.after" |
104
|
|
|
*/ |
105
|
|
|
public function hookModuleDisableAfter() |
106
|
|
|
{ |
107
|
|
|
$this->library->clearCache(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Implements hook "module.install.after" |
112
|
|
|
*/ |
113
|
|
|
public function hookModuleInstallAfter() |
114
|
|
|
{ |
115
|
|
|
$this->library->clearCache(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Implements hook "module.uninstall.after" |
120
|
|
|
*/ |
121
|
|
|
public function hookModuleUninstallAfter() |
122
|
|
|
{ |
123
|
|
|
$this->library->clearCache(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Sets module specific assets |
128
|
|
|
* @param \gplcart\core\controllers\backend\Controller $controller |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
protected function setModuleAssets($controller) |
132
|
|
|
{ |
133
|
|
|
if ($controller->isInternalRoute()) { |
134
|
|
|
return false; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$settings = $this->module->getSettings('summernote'); |
138
|
|
|
|
139
|
|
|
if (empty($settings['selector']) || !is_array($settings['selector'])) { |
140
|
|
|
return false; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$controller->setJsSettings('summernote', $settings); |
144
|
|
|
$controller->addAssetLibrary('summernote'); |
145
|
|
|
$controller->setJs('system/modules/summernote/js/common.js'); |
146
|
|
|
return true; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|