Skip to content
Permalink
Browse files
Merge pull request #757 from SmoKE585/alpha
Редактор кода с подсветкой ошибок
  • Loading branch information
sergejey committed Jun 3, 2020
2 parents 2c333c7 + ee7767a commit 97f413d1f5255ce4c41d5c77b466065f96289164
Showing 7 changed files with 87 additions and 53 deletions.
@@ -7,6 +7,7 @@
}
.CodeMirror-foldgutter {
width: .7em;
background: #868686 !important;
}
.CodeMirror-foldgutter-open,
.CodeMirror-foldgutter-folded {
@@ -3,7 +3,9 @@
.CodeMirror {
/* Set height, width, borders, and global font properties here */
font-family: monospace;
height: 300px;
max-height: 20000px;
border: 2px solid #f7f7f7;
border-radius: 5px;
color: black;
direction: ltr;
}
@@ -25,20 +27,21 @@

.CodeMirror-gutters {
border-right: 1px solid #ddd;
background-color: #f7f7f7;
background-color: #868686;
white-space: nowrap;
}
.CodeMirror-linenumbers {}
.CodeMirror-linenumber {
padding: 0 3px 0 5px;
min-width: 20px;
text-align: right;
color: #999;
white-space: nowrap;
min-width: 20px;
text-align: right;
color: #fff;
white-space: nowrap;
background: #868686 !important;
}

.CodeMirror-guttermarker { color: black; }
.CodeMirror-guttermarker-subtle { color: #999; }
.CodeMirror-guttermarker-subtle { color: #FFEB3B; }

/* CURSOR */

@@ -16,41 +16,34 @@
*/
function php_syntax_error($code)
{
if (isItPythonCode($code)) {
return python_syntax_error($code);
} else {
$code .= "\n echo 'zzz';";
$code = '<?php ' . $code . '?>';
//echo DOC_ROOT;exit;
$fileName = md5(time() . rand(0, 10000)) . '.php';
$filePath = DOC_ROOT . '/cms/cached/' . $fileName;
SaveFile($filePath, $code);
if (substr(php_uname(), 0, 7) == "Windows") {
if (defined('PATH_TO_PHP')) {
$cmd = PATH_TO_PHP . ' -l ' . $filePath;
} else {
$cmd = DOC_ROOT . '/../server/php/php -l ' . $filePath;
}
} else {
$cmd = 'php -l ' . $filePath;
}
exec($cmd, $out);
unlink($filePath);
if (preg_match('/no syntax errors detected/is', $out[0]))
{
return false;
}
elseif (!trim(implode("\n", $out)))
{
return false;
}
else
{
$res = implode("\n", $out);
$res = preg_replace('/Errors parsing.+/is', '', $res);
if (isItPythonCode($code)) {
return python_syntax_error($code);
} else {
$code .= "\n echo 'welldone';";
$code = '<?php ' . $code . '?>';

return trim($res) . "\n";
}
}
$fileName = md5(time() . rand(0, 10000)) . '.php';
$filePath = DOC_ROOT . '/cms/cached/' . $fileName;
SaveFile($filePath, $code);
if (substr(php_uname(), 0, 7) == "Windows") {
if (defined('PATH_TO_PHP')) {
$cmd = PATH_TO_PHP . ' -l ' . $filePath;
} else {
$cmd = DOC_ROOT . '/../server/php/php -l ' . $filePath;
}
} else {
$cmd = 'php -l ' . $filePath.' 2>&1';
}
exec($cmd, $out);
unlink($filePath);
$res = implode("\n", $out);

if(preg_match("/\.php on line \b/i", $res))

return trim($res) . "\n";
if (preg_match("/welldone\b/i", $res)) {
return false;
}
}
}

@@ -62,10 +62,14 @@
//echo $content;
$errors=php_syntax_error($code);
if ($errors) {
$out['ERR_CODE']=1;
$out['ERRORS']=nl2br($errors);
$ok=0;
}
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18))-2;
$out['ERR_CODE'] = 1;
$errorStr = explode('PHP Parse error: ', str_replace("'", '', strip_tags(nl2br($errors))));
$errorStr = explode('Errors parsing', $errorStr[1]);
$errorStr = explode(' in ', $errorStr[0]);
$out['ERRORS'] = $errorStr[0];
$ok = 0;
}
}

//UPDATING RECORD
@@ -42,10 +42,17 @@

if ($rec['CODE'] != '') {
//echo $content;

$errors = php_syntax_error($rec['CODE']);

if ($errors) {
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18))-2;
$out['ERR_CODE'] = 1;
$out['ERRORS'] = nl2br($errors);
$errorStr = explode('PHP Parse error: ', str_replace("'", '', strip_tags(nl2br($errors))));
$errorStr = explode('Errors parsing', $errorStr[1]);
$errorStr = explode(' in ', $errorStr[0]);
//var_dump($errorStr);
$out['ERRORS'] = $errorStr[0];
$ok = 0;
}
}
@@ -8,27 +8,41 @@
[#if OK#]
<div class="alert alert-success"><#LANG_DATA_SAVED#></div>
[#endif OK#]

[#if ERR#]
<div class="alert alert-danger"><#LANG_FILLOUT_REQURED#></div>
<script>
$(window).load(function() {
find = $('div pre.CodeMirror-line:eq([#ERR_LINE#])');
find.attr('style', 'background: #f2dede;');
find.attr('id', 'errorline');

var newElems = $("<div class='hintError' style='border-top: 1px solid red;font-weight: bold;font-style: italic;'>Ошибка компилятора -> [#ERRORS#]</div>");

$('div pre.CodeMirror-line:eq([#ERR_LINE#])').append(newElems);

location.href='#errorline';
});
</script>
[#endif ERR#]

<div class="form-group ">
<label class="col-lg-4 control-label"><#LANG_TITLE#>:<font color="red">*</font><#LANG_HCB#>title<#LANG_HCE#></label>
<div class="col-lg-5"><input type="text" class="form-control [#if ERR_TITLE#]alert-danger[#endif#]" name="title" value="[#TITLE#]" required="true"></div>
<div class="col-lg-8"><input type="text" class="form-control [#if ERR_TITLE#]alert-danger[#endif#]" name="title" value="[#TITLE#]" required="true"></div>
</div>


<div class="form-group ">
<label class="col-lg-4 control-label"><#LANG_DESCRIPTION#><#LANG_HCB#>description<#LANG_HCE#></label>
<div class="col-lg-5">
<div class="col-lg-8">
<textarea name="description" id="description" rows=3 cols=100 class="form-control">[#DESCRIPTION#]</textarea>
</div>
</div>

[#if ID!=""#]
<div class="form-group ">
<label class="col-lg-4 control-label"><#LANG_CODE#><#LANG_HCB#>code<#LANG_HCE#></label>
<div class="col-lg-5">
<div class="col-lg-8">


<input type="radio" name="run_type" value="script"[#if SCRIPT_ID!="0"#] checked[#endif#] onClick="$('#code_option').hide();"> <#LANG_SCRIPT#>:
@@ -59,7 +73,7 @@
<div class="form-group">
<label class="col-lg-4 control-label"></label>

<div class="col-lg-5">
<div class="col-lg-8">
<#LANG_CALL_PARENT_METHOD#>:
<#LANG_HCB#>parent_method<#LANG_HCE#>
<br>
@@ -75,7 +89,7 @@


<div class="form-group">
<div class="col-lg-offset-1 col-lg-5">
<div class="col-lg-offset-1 col-lg-8">

[#if ID!=""#]
<input class="btn btn-default btn-primary" type="submit" name="subm" value="<#LANG_SUBMIT#>">
@@ -25,9 +25,21 @@
[#endif OK#]
[#if ERR#]
<div class="alert alert-danger"><#LANG_FILLOUT_REQURED#></div>
<script>
$(window).load(function() {
find = $('div pre.CodeMirror-line:eq([#ERR_LINE#])');
find.attr('style', 'background: #f2dede;');
find.attr('id', 'errorline');

var newElems = $("<div class='hintError' style='border-top: 1px solid red;font-weight: bold;font-style: italic;'>Ошибка компилятора -> [#ERRORS#]</div>");

$('div pre.CodeMirror-line:eq([#ERR_LINE#])').append(newElems);

location.href='#errorline';
});
</script>
[#endif ERR#]


<div class="form-group ">
<label class="col-lg-4 control-label"><#LANG_TITLE#>:<font color="red">*</font><#LANG_HCB#>title<#LANG_HCE#></label>
<div class="col-lg-8"><input type="text" class="form-control [#if ERR_TITLE#]alert-danger[#endif#]" name="title" value="[#TITLE#]" required="true"></div>

0 comments on commit 97f413d

Please sign in to comment.