-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·274 lines (246 loc) · 8.85 KB
/
index.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of YASH3, a plugin for DotClear2.
# Forked by (c) Gnieark https://blog-du-grouik.tinad.fr 2016
# licensed as GPL V2
#
# Original dev is: Yash Copyright (c) 2008 Pep and contributors. All rights
# reserved.
#
# This plugin 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 plugin 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 plugin; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
if (!defined('DC_CONTEXT_ADMIN')) { exit; }
// Setting default parameters if missing configuration
$core->blog->settings->addNamespace('yash3');
if (is_null($core->blog->settings->yash3->yash3_active)) {
try {
// Default state is active if the comments are configured to allow wiki syntax
$core->blog->settings->yash3->put('yash3_active',false,'boolean',true);
$core->blog->settings->yash3->put('yash3_theme','Default','string',true);
$core->blog->settings->yash3->put('yash3_custom_css','','string',true);
$core->blog->triggerBlog();
http::redirect($p_url);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
// Getting current parameters
$active = (boolean)$core->blog->settings->yash3->yash3_active;
$theme = (string)$core->blog->settings->yash3->yash3_theme;
$customCss = (string)$core->blog->settings->yash3->yash3_custom_css;
if (!empty($_REQUEST['popup'])) {
$yash3_brushes = array(
'plain' => __('Plain Text'),
'applescript' => __('AppleScript'),
'as3' => __('ActionScript3'),
'bash' => __('Bash/shell'),
'cf' => __('ColdFusion'),
'csharp' => __('C#'),
'cpp' => __('C/C++'),
'css' => __('CSS'),
'delphi' => __('Delphi'),
'diff' => __('Diff/Patch'),
'erl' => __('Erlang'),
'groovy' => __('Groovy'),
'haxe' => __('Haxe'),
'js' => __('Javascript/JSON'),
'java' => __('Java'),
'jfx' => __('JavaFX'),
'pl' => __('Perl'),
'php' => __('PHP'),
'ps' => __('PowerShell'),
'python' => __('Python'),
'ruby' => __('Ruby'),
'sass' => __('SASS'),
'scala' => __('Scala'),
'sql' => __('SQL'),
'tap' => __('Tap'),
'ts' => __('TypeScript'),
'vb' => __('Visual Basic'),
'xml' => __('XML/XSLT/XHTML/HTML'),
'yaml' => __('Yaml')
);
echo
'<html>'.
'<head>'.
'<title>'.__('YASH - Syntax Selector').'</title>'.
dcPage::jsLoad(urldecode(dcPage::getPF('yash3/js/popup.js')),$core->getVersion('yash3')).
'</head>'.
'<body>'.
'<h2>'.__('YASH - Syntax Selector').'</h2>'.
'<form id="yash3-form" action="'.$p_url.'&popup=1" method="get">'.
'<p><label>'.__('Select the primary syntax of your code snippet.').
form::combo('syntax',array_flip($yash3_brushes)).'</label></p>'.
'<p><a id="yash3-cancel" class="button" href="#">'.__('Cancel').'</a> - '.
'<strong><a id="yash3-ok" class="button" href="#">'.__('Ok').'</a></strong></p>'.
'</form>'.
'</body>'.
'</html>';
return;
}
// Saving new configuration
if (!empty($_POST['saveconfig'])) {
try
{
$core->blog->settings->addNameSpace('yash3');
$active = (empty($_POST['active'])) ? false : true;
$theme = (empty($_POST['theme'])) ? 'Default' : $_POST['theme'];
$customCss = (empty($_POST['customCss'])) ? '' : $_POST['customCss'];
$core->blog->settings->yash3->put('yash3_active',$active,'boolean');
$core->blog->settings->yash3->put('yash3_theme',$theme,'string');
$core->blog->settings->yash3->put('yash3_custom_css',$customCss,'string');
$new_concat_version = (integer)$core->blog->settings->yash3->yash3_concat_version + 1;
$cssPreviousFileRealPath = path::real(DC_VAR)."/yash3/".
$core->blog->id."/".
$core->blog->settings->yash3->yash3_concat_version.
".css";
$cssFutureFileRealPath = path::real(DC_VAR)."/yash3/".
$core->blog->id."/".
((integer)$core->blog->settings->yash3->yash3_concat_version + 1).
".css";
$jsPreviousFileRealPath = path::real(DC_VAR)."/yash3/".
$core->blog->id."/".
$core->blog->settings->yash3->yash3_concat_version.
".js";
$jsFutureFileRealPath = path::real(DC_VAR)."/yash3/".
$core->blog->id."/".
((integer)$core->blog->settings->yash3->yash3_concat_version + 1).
".js";
if(!is_dir(dirname($jsFutureFileRealPath))){
//probably the first use of the plugin, the pach does no exists. create it:
files::makeDir(dirname($jsFutureFileRealPath),true);
}
//Generate the CSS concatened
if(file_exists($cssPreviousFileRealPath)){
//delete It
unlink($cssPreviousFileRealPath);
}
$custom_css = $core->blog->settings->yash3->yash3_custom_css;
if (!empty($custom_css)) {
$fContent = $custom_css;
}
else {
$theme = (string)$core->blog->settings->yash3->yash3_theme;
if ($theme == '') {
$fContent = file_get_contents(dirname(__FILE__)."/syntaxhighlighter/css/shThemeDefault.css");
} else {
$fContent = file_get_contents(dirname(__FILE__)."/syntaxhighlighter/css/shTheme".$theme.".css");
}
}
$fContent = file_get_contents(dirname(__FILE__)."/syntaxhighlighter/css/shCore.css")."\n".
$fContent;
// Remove comments
$fContent = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $fContent);
// Remove space after colons
$fContent = str_replace(': ', ':', $fContent);
// Remove whitespace
$fContent = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $fContent);
//create the file
file_put_contents( $cssFutureFileRealPath, $fContent );
//Generate the JS
if(file_exists($jsPreviousFileRealPath)){
//delete It
unlink($jsPreviousFileRealPath);
}
include_once(dirname(__FILE__).'/inc/yash3JSMinifier.php');
$fContent = yash3JSMinifier::minify(
file_get_contents(dirname(__FILE__)."/syntaxhighlighter/js/shCore.js").
file_get_contents(dirname(__FILE__)."/syntaxhighlighter/js/shAutoloader.js").
"\n var yash3_path=\"".$core->blog->getPF('yash3/syntaxhighlighter/js/')."\";\n".
file_get_contents(dirname(__FILE__)."/js/public.js")
);
//write the file
file_put_contents($jsFutureFileRealPath,$fContent);
//update concat version
$core->blog->settings->yash3->put('yash3_concat_version',$new_concat_version,'integer');
$core->blog->triggerBlog();
dcPage::addSuccessNotice(__('Configuration successfully updated.'));
http::redirect($p_url);
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
}
?>
<html>
<head>
<title><?php echo __('YASH3'); ?></title>
<script type="text/javascript">
//I hate jquery
$(document).ready(function(){
$("#theme").change(function(){;
$(this).find("option:selected").each(function(){
if($(this).attr("value")=="Custom"){
$("#pcustomcss").show();
}else{
$("#pcustomcss").hide();
}
});
}).change();
});
</script>
</head>
<body>
<?php
echo dcPage::breadcrumb(
array(
html::escapeHTML($core->blog->name) => '',
__('YASH3') => ''
));
echo dcPage::notices();
$combo_theme = array(
__('Default') => 'Default',
__('Custom css') => 'Custom',
__('Django') => 'Django',
__('Eclipse') => 'Eclipse',
__('Emacs') => 'Emacs',
__('Fade to gray') => 'FadeToGrey',
__('Material') => 'Material',
__('MD Ultra') => 'MDUltra',
__('Midnight') => 'Midnight',
__('RDark') => 'RDark',
__('Solarized Dark') => 'SolarizedDark',
__('Solarized Light') => 'SolarizedLight',
__('Tomorrow Night') => 'TomorrowNight'
);
?>
<div id="yash3_options">
<form method="post" action="<?php http::getSelfURI(); ?>">
<p>
<?php echo form::checkbox('active', 1, $active); ?>
<label class="classic" for="active"> <?php echo __('Enable YASH');?></label>
</p>
<h3><?php echo __('Options'); ?></h3>
<p class="field"><label for="theme" class="classic"><?php echo __('Theme:'); ?> </label>
<?php echo form::combo('theme',$combo_theme,$theme); ?>
</p>
<p class="field" id="pcustomcss">
<label for="custom_css" class="classic"><?php echo __('Use custom CSS:') ; ?> </label>
<?php echo form::textarea('customCss',80,20, $customCss); ?>
</p>
<p class="info">
<?php echo __('You can use a custom CSS. Select custom CSS and paste it on the textarea'); ?>
</p>
<p><input type="hidden" name="p" value="yash3" />
<?php echo $core->formNonce(); ?>
<input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" />
</p>
</form>
</div>
</body>
</html>