Skip to content

Commit

Permalink
Updated COM_handleEval to return more informatio about errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eSilverStrike committed Mar 15, 2020
1 parent 9c77da7 commit 831ac06
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions public_html/lib-common.php
Expand Up @@ -9164,16 +9164,18 @@ function COM_getInstallDir()
*
* @param string $code
* @param int $type 1 = PHP, 2 = HTML
* @param string $code
* @return string $embeddedPHP Code is embedded within content (like HTML)
* @param string $embeddedPHP Code is embedded within content (like HTML)
* @return array
*/
function COM_handleEval($code, $type = 1, $embeddedPHP = false)
{
global $LANG01;

$type = (int) $type;
$errorMessage = '';
$phpErrorMsg = '';
$output = '';
$retarray = [];

if ($embeddedPHP && strpos($code, '?>') !== 0) {
$code = '?>' . $code . '<?php ';
Expand All @@ -9193,7 +9195,8 @@ function COM_handleEval($code, $type = 1, $embeddedPHP = false)
try {
$output = eval($code);
} catch (ParseError $e) {
COM_errorLog(__FUNCTION__ . ': ' . $e->getMessage());
$phpErrorMsg = $e->getMessage();
COM_errorLog(__FUNCTION__ . ': ' . $phpErrorMsg);
$errorMessage = $LANG01[144];
}
}
Expand All @@ -9202,7 +9205,16 @@ function COM_handleEval($code, $type = 1, $embeddedPHP = false)
$output = ob_get_clean();
}

return empty($errorMessage) ? $output : $errorMessage;
if (empty($errorMessage)) {
$retarray = ['success' => true,
'output' => $output];
} else {
$retarray = ['success' => false,
'output' => $LANG01[144],
'error' => $phpErrorMsg];
}

return $retarray;
}

// Check and see if any plugins (or custom functions)
Expand Down

0 comments on commit 831ac06

Please sign in to comment.