-
Notifications
You must be signed in to change notification settings - Fork 0
/
AceEditor2.module.php
203 lines (179 loc) · 6.44 KB
/
AceEditor2.module.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
*
* Copyright:
*
* MajorLabel - Guido Goluke
* Web: www.majorlabel.nl
* Email: info@majorlabel.nl
*
*
* Authors:
*
* Guido Goluke, <info@majorlabel.nl>
*
*
* License:
*-------------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
*
* ------------------------------------------------------------------------- */
class AceEditor2 extends CMSModule
{
const MANAGE_PERM = 'manage_ace';
public function GetName() {
return basename(__CLASS__);
}
public function GetVersion() {
return "1.05";
}
public function GetFriendlyName() {
return 'Ace Editor 2.0';
}
public function GetAdminDescription() {
return 'Ace Editor Implementation for CMSMS 2.x series';
}
public function IsPluginModule() {
return FALSE;
}
public function HasAdmin() {
return TRUE;
}
public function GetAuthor() {
return 'Guido Goluke';
}
public function GetAuthorEmail() {
return 'info[a]majorlabel.nl';
}
public function VisibleToAdminUser() {
return $this->CheckPermission(self::MANAGE_PERM);
}
public function HasCapability($capability, $params = array())
{
if( $capability == CmsCoreCapabilities::SYNTAX_MODULE ) return TRUE;
return FALSE;
}
public function GetHelp() {
$smarty = cmsms()->GetSmarty();
$smarty->assign('help_title',$this->Lang('help_title'));
$smarty->assign('help_p1',$this->Lang('help_p1'));
$smarty->assign('help_h1',$this->Lang('help_h1'));
$smarty->assign('help_p2',$this->Lang('help_p2'));
$smarty->assign('help_h2',$this->Lang('help_h2'));
$smarty->assign('help_p3',$this->Lang('help_p3'));
$smarty->assign('help_feat_listitem1',$this->Lang('help_feat_listitem1'));
$smarty->assign('help_feat_listitem2',$this->Lang('help_feat_listitem2'));
$smarty->assign('help_feat_listitem3',$this->Lang('help_feat_listitem3'));
$smarty->assign('help_feat_listitem4',$this->Lang('help_feat_listitem4'));
$smarty->assign('help_feat_listitem5',$this->Lang('help_feat_listitem5'));
$smarty->assign('help_feat_listitem6',$this->Lang('help_feat_listitem6'));
$smarty->assign('help_h3',$this->Lang('help_h3'));
$smarty->assign('help_p4',$this->Lang('help_p4'));
$smarty->assign('help_prefs_listitem1',$this->Lang('help_prefs_listitem1'));
$smarty->assign('help_prefs_listitem2',$this->Lang('help_prefs_listitem2'));
$smarty->assign('help_prefs_listitem3',$this->Lang('help_prefs_listitem3'));
$smarty->assign('help_prefs_listitem4',$this->Lang('help_prefs_listitem4'));
$smarty->assign('help_prefs_listitem5',$this->Lang('help_prefs_listitem5'));
$smarty->assign('help_h4',$this->Lang('help_h4'));
$smarty->assign('help_p5',$this->Lang('help_p5'));
$smarty->assign('help_h5',$this->Lang('help_h5'));
$smarty->assign('help_p6',$this->Lang('help_p6'));
return $this->ProcessTemplate('help.tpl');
}
public function GetChangelog() {
return $this->ProcessTemplate('about.tpl');
}
public function SyntaxGenerateHeader() {
$script_includes = array('ace.js','theme-twilight.js','ext-language_tools.js');
$toolbarcss = $this->GetModuleURLPath().'/lib/css/AceCMSMS.css';
$toolbarjs = $this->GetModuleURLPath().'/lib/js/AceInitCMSMS.js';
// Setup the modes you want to support, the array key is the select box label,
// The value is the filename (mode-{FILENAME}.js)
$AceModes = json_encode(array(
'CSS' => 'css',
'Smarty' => 'smarty',
'HTML' => 'html',
'Javascript'=> 'javascript',
'JSON' => 'json',
'PHP' => 'php',
'SASS' => 'sass',
'LESS' => 'less'
));
// Get the preferences
$prefs = $this->GetCurrentAcePrefs();
// Set the width, based on the width type preferences
if ($prefs['editor_width_type'] == 'pc') {
$width = $prefs['editor_width_pc'].'%';
} else {
$width = $prefs['editor_width_px'].'px';
}
$out = '';
foreach($script_includes as $script_include) {
$out .= '<script src="'.$this->GetModuleURLPath().'/lib/Ace/src-min/'.$script_include.'"></script>';
}
$out .= <<<EOT
<script src="{$toolbarjs}"></script>
<link rel="stylesheet" type="text/css" href="{$toolbarcss}">
<script type="text/javascript">
$(window).load(function(){
$('textarea.AceEditor2').each(function(){
var originalTextArea = this;
var currentMode = originalTextArea.dataset.cmsLang;
var cssPrefMode = '{$prefs['editor_css_prefmode']}';
var editor = ace.edit($(this).get(0));
initAce(editor, originalTextArea);
initKeyBindings(editor);
addToolBar(editor, '{$this->GetModuleURLPath()}', {$AceModes}, currentMode, cssPrefMode);
editor.setTheme('ace/theme/twilight');
editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
highlightGutterLine: true,
wrap: 120,
});
editor.\$blockScrolling = Infinity;
});
aceResize();
});
</script>
<style type="text/css">
.ace_editor {
width: {$width};
height: {$prefs['editor_height_px']}px;
border: 0;
}
</style>
EOT;
return $out;
}
public function UninstallPreMessage() {
return $this->Lang('ask_uninstall');
}
// Method to save the settings in the database from the admin panel
public function SavePreference($prefname, $value) {
$db = \cms_utils::get_db();
$sql = 'UPDATE '.CMS_DB_PREFIX.'mod_ace_editor2 SET '.$prefname.' = ? WHERE id = ?';
$insert_array = array($value, 1);
$db->Execute($sql, $insert_array);
}
// Method to get all the preferences from the database when opening the preferences screen
public function GetCurrentAcePrefs() {
$db = \cms_utils::get_db();
$sql = 'SELECT * from '.CMS_DB_PREFIX.'mod_ace_editor2 WHERE id = ?';
$row = $db->GetRow($sql, array(1));
return $row;
}
}