Browse Source

优化语法

tags/6.2.0
xushubieli 2 years ago
parent
commit
00075f9bb7
9 changed files with 69 additions and 73 deletions
  1. +1
    -1
      src/index.php
  2. +22
    -26
      src/system/helpers/code.helper.php
  3. +34
    -34
      src/system/libraries/mail.class.php
  4. +2
    -2
      src/theme/plus/download_links_templet.htm
  5. +2
    -2
      src/theme/plus/flink-add.htm
  6. +2
    -2
      src/theme/plus/flink-list.htm
  7. +2
    -2
      src/theme/plus/heightsearch.htm
  8. +2
    -2
      src/theme/plus/recommend.htm
  9. +2
    -2
      src/theme/plus/view_msg.htm

+ 1
- 1
src/index.php View File

@@ -10,7 +10,7 @@ if (!file_exists(dirname(__FILE__).'/data/common.inc.php')) {
header('Location:install/index.php'); header('Location:install/index.php');
exit(); exit();
} }
//自动生成网页
//自动生成网页
if (isset($_GET['upcache']) || !file_exists('index.html')) { if (isset($_GET['upcache']) || !file_exists('index.html')) {
require_once(dirname(__FILE__)."/system/common.inc.php"); require_once(dirname(__FILE__)."/system/common.inc.php");
require_once DEDEINC."/archive/partview.class.php"; require_once DEDEINC."/archive/partview.class.php";


+ 22
- 26
src/system/helpers/code.helper.php View File

@@ -1,10 +1,10 @@
<?php <?php
if (!defined('DEDEINC')) exit('dedebiz'); if (!defined('DEDEINC')) exit('dedebiz');
// 允许的函数
//允许的函数
$GLOBALS['allowedCalls'] = array( $GLOBALS['allowedCalls'] = array(
// 系统
//系统
'var_dump', 'var_dump',
// 数学
//数学
'ceil', 'ceil',
'floor', 'floor',
'fmod', 'fmod',
@@ -15,7 +15,7 @@ $GLOBALS['allowedCalls'] = array(
'rand', 'rand',
'sqrt', 'sqrt',
'srand', 'srand',
// 变量
//变量
'empty', 'empty',
'floatval', 'floatval',
'intval', 'intval',
@@ -36,7 +36,7 @@ $GLOBALS['allowedCalls'] = array(
'isset', 'isset',
'strval', 'strval',
'unset', 'unset',
// 数组
//数组
'array_change_key_case', 'array_change_key_case',
'array_chunk', 'array_chunk',
'array_combine', 'array_combine',
@@ -92,7 +92,7 @@ $GLOBALS['allowedCalls'] = array(
'shuffle', 'shuffle',
'sizeof', 'sizeof',
'sort', 'sort',
// 字符串
//字符串
'json_encode', 'json_encode',
'json_decode', 'json_decode',
'json_last_error', 'json_last_error',
@@ -156,7 +156,7 @@ $GLOBALS['allowedCalls'] = array(
'ucfirst', 'ucfirst',
'ucwords', 'ucwords',
'wordwrap', 'wordwrap',
// dede内置
//dede内置
'html2text', 'html2text',
'removexss', 'removexss',
'htmlreplace', 'htmlreplace',
@@ -179,7 +179,7 @@ $GLOBALS['allowedCalls'] = array(
'gb2big5', 'gb2big5',
'litimgurls', 'litimgurls',
'split', 'split',
// 时间
//时间
'strtotime', 'strtotime',
'date', 'date',
'idate', 'idate',
@@ -228,7 +228,7 @@ $GLOBALS['allowedCalls'] = array(
'date_sunrise', 'date_sunrise',
'date_sunset', 'date_sunset',
'date_sun_info', 'date_sun_info',
// mb字符串处理
//mb字符串处理
'mb_convert_case', 'mb_convert_case',
'mb_strtoupper', 'mb_strtoupper',
'mb_strtolower', 'mb_strtolower',
@@ -288,7 +288,7 @@ $GLOBALS['allowedCalls'] = array(
'mb_ereg_search_getpos', 'mb_ereg_search_getpos',
'mb_ereg_search_setpos', 'mb_ereg_search_setpos',
); );
// 允许的语法
//允许的语法
$GLOBALS['allowedTokens'] = array( $GLOBALS['allowedTokens'] = array(
'T_AND_EQUAL', 'T_AND_EQUAL',
'T_ARRAY', 'T_ARRAY',
@@ -300,7 +300,6 @@ $GLOBALS['allowedTokens'] = array(
'T_BREAK', 'T_BREAK',
'T_CASE', 'T_CASE',
'T_CHARACTER', 'T_CHARACTER',

'T_CONCAT_EQUAL', 'T_CONCAT_EQUAL',
'T_CONSTANT_ENCAPSED_STRING', 'T_CONSTANT_ENCAPSED_STRING',
'T_CONTINUE', 'T_CONTINUE',
@@ -313,7 +312,6 @@ $GLOBALS['allowedTokens'] = array(
'T_DO', 'T_DO',
'T_DOUBLE_ARROW', 'T_DOUBLE_ARROW',
'T_DOUBLE_CAST', 'T_DOUBLE_CAST',

'T_ELSE', 'T_ELSE',
'T_ELSEIF', 'T_ELSEIF',
'T_EMPTY', 'T_EMPTY',
@@ -340,7 +338,6 @@ $GLOBALS['allowedTokens'] = array(
'T_LOGICAL_OR', 'T_LOGICAL_OR',
'T_LOGICAL_XOR', 'T_LOGICAL_XOR',
'T_MINUS_EQUAL', 'T_MINUS_EQUAL',

'T_MOD_EQUAL', 'T_MOD_EQUAL',
'T_MUL_EQUAL', 'T_MUL_EQUAL',
'T_NUM_STRING', 'T_NUM_STRING',
@@ -362,29 +359,28 @@ $GLOBALS['allowedTokens'] = array(
'T_WHITESPACE', 'T_WHITESPACE',
'T_XOR_EQUAL', 'T_XOR_EQUAL',
); );
// 禁止的表达式
//禁止的表达式
$GLOBALS['disallowedExpressions'] = array( $GLOBALS['disallowedExpressions'] = array(
'/`/', '/`/',
'/\$\W/', '/\$\W/',
'/(\]|\})\s*\(/', '/(\]|\})\s*\(/',
'/\$\w\w*\s*\(/', '/\$\w\w*\s*\(/',
); );
// 执行脚本
//执行脚本
function evalCode($code) function evalCode($code)
{ {
ob_start(); ob_start();
$code = eval('if(0){' . "\n" . $code . "\n" . '}');
$code = eval('if(0){'."\n".$code."\n".'}');
ob_end_clean(); ob_end_clean();
return $code !== false; return $code !== false;
} }
// 校验脚本
//校验脚本
function checkCode($code) function checkCode($code)
{ {
global $allowedCalls; global $allowedCalls;
global $allowedTokens; global $allowedTokens;
global $disallowedExpressions; global $disallowedExpressions;

$tokens = token_get_all('<?php ' . $code . ' ?>');
$tokens = token_get_all('<?php '.$code.' ?>');
$errors = array(); $errors = array();
$braces = 0; $braces = 0;
foreach ($tokens as $token) { foreach ($tokens as $token) {
@@ -421,13 +417,13 @@ function checkCode($code)
switch ($id) { switch ($id) {
case ('T_STRING'): case ('T_STRING'):
if (in_array(strtolower($token[1]), $allowedCalls) === false) { if (in_array(strtolower($token[1]), $allowedCalls) === false) {
$errors[$i]['name'] = 'Illegal function: ' . $token[1];
$errors[$i]['name'] = 'Illegal function: '.$token[1];
$errors[$i]['line'] = $token[2]; $errors[$i]['line'] = $token[2];
} }
break; break;
default: default:
if (in_array($id, $allowedTokens) === false) { if (in_array($id, $allowedTokens) === false) {
$errors[$i]['name'] = 'Illegal token: ' . $token[1];
$errors[$i]['name'] = 'Illegal token: '.$token[1];
$errors[$i]['line'] = $token[2]; $errors[$i]['line'] = $token[2];
} }
break; break;
@@ -439,21 +435,21 @@ function checkCode($code)
return $errors; return $errors;
} }
} }
// 错误提示
//错误提示
function htmlErrors($errors = null) function htmlErrors($errors = null)
{ {
if ($errors) { if ($errors) {
$errorsHTML = "<div style='width:98%;margin:1rem auto;color:#842029;background:#f8d7da;border-color:#842029;position:relative;padding:.75rem 1.25rem;border:1px solid transparent;border-radius:.2rem'>"; $errorsHTML = "<div style='width:98%;margin:1rem auto;color:#842029;background:#f8d7da;border-color:#842029;position:relative;padding:.75rem 1.25rem;border:1px solid transparent;border-radius:.2rem'>";
$errorsHTML .= 'PHP内嵌脚本错误:';
$errorsHTML .= '内嵌脚本缺失,请添加该函数:';
$errorsHTML .= '<dl>'; $errorsHTML .= '<dl>';
foreach ($errors as $error) { foreach ($errors as $error) {
if ($error['line']) { if ($error['line']) {
$errorsHTML .= '<dt>Line ' . $error['line'] . '</dt>';
$errorsHTML .= '<dt>Line '.$error['line'].'</dt>';
} }
$errorsHTML .= '<dd>' . $error['name'] . '</dd>';
$errorsHTML .= '<dd>'.$error['name'].'</dd>';
} }
$errorsHTML .= '</dl>'; $errorsHTML .= '</dl>';
$errorsHTML .= "</div>\r\n"; $errorsHTML .= "</div>\r\n";
echo $errorsHTML; echo $errorsHTML;
} }
}
}

+ 34
- 34
src/system/libraries/mail.class.php View File

@@ -50,16 +50,16 @@ class smtp
} }
if ($cc != "") if ($cc != "")
{ {
$header .= "Cc: " . $cc . "\r\n";
$header .= "Cc: ".$cc."\r\n";
} }
$header .= "From: $webname<" . $from . ">\r\n";
$subject = "=?" . $GLOBALS['cfg_soft_lang'] . "?B?" . base64_encode($subject) . "?=";
$header .= "Subject: " . $subject . "\r\n";
$header .= "From: $webname<".$from.">\r\n";
$subject = "=?".$GLOBALS['cfg_soft_lang']."?B?".base64_encode($subject)."?=";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers; $header .= $additional_headers;
$header .= "Date: " . date("r") . "\r\n";
$header .= "X-Mailer:By Redhat (PHP/" . phpversion() . ")\r\n";
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime()); list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <" . date("YmdHis", $sec) . "." . ($msec * 1000000) . "." . $mail_from . ">\r\n";
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec * 1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to)); $TO = explode(",", $this->strip_comment($to));
if ($cc != "") if ($cc != "")
{ {
@@ -72,20 +72,20 @@ class smtp
$sent = TRUE; $sent = TRUE;
foreach ($TO as $rcpt_to) foreach ($TO as $rcpt_to)
{ {
$headerto = "To: " . $rcpt_to . "\r\n";
$headerall = $header . $headerto;
$headerto = "To: ".$rcpt_to."\r\n";
$headerall = $header.$headerto;
$rcpt_to = $this->get_address($rcpt_to); $rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) if (!$this->smtp_sockopen($rcpt_to))
{ {
$this->log_write("Error: Cannot send email to " . $rcpt_to . "\n");
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE; $sent = FALSE;
continue; continue;
} }
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $headerall, $body)) if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $headerall, $body))
{ {
$this->log_write("E-mail has been sent to <" . $rcpt_to . ">\n");
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else { } else {
$this->log_write("Error: Cannot send email to <" . $rcpt_to . ">\n");
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE; $sent = FALSE;
} }
fclose($this->sock); fclose($this->sock);
@@ -125,11 +125,11 @@ class smtp
return $this->smtp_error("sending HELO command"); return $this->smtp_error("sending HELO command");
} }
} }
if (!$this->smtp_putcmd("MAIL", "FROM:<" . $from . ">"))
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{ {
return $this->smtp_error("sending MAIL FROM command"); return $this->smtp_error("sending MAIL FROM command");
} }
if (!$this->smtp_putcmd("RCPT", "TO:<" . $to . ">"))
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{ {
return $this->smtp_error("sending RCPT TO command"); return $this->smtp_error("sending RCPT TO command");
} }
@@ -162,15 +162,15 @@ class smtp
} }
function smtp_sockopen_relay() function smtp_sockopen_relay()
{ {
$this->log_write("Trying to " . $this->relay_host . ":" . $this->smtp_port . "\n");
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) if (!($this->sock && $this->smtp_ok()))
{ {
$this->log_write("Error: Cannot connenct to relay host " . $this->relay_host . "\n");
$this->log_write("Error: " . $errstr . " (" . $errno . ")\n");
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE; return FALSE;
} }
$this->log_write("Connected to relay host " . $this->relay_host . "\n");
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;; return TRUE;;
} }
function smtp_sockopen_mx($address) function smtp_sockopen_mx($address)
@@ -178,29 +178,29 @@ class smtp
$domain = preg_replace("/^.+@([^@]+)$/i", "\1", $address); $domain = preg_replace("/^.+@([^@]+)$/i", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) if (!@getmxrr($domain, $MXHOSTS))
{ {
$this->log_write("Error: Cannot resolve MX \"" . $domain . "\"\n");
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE; return FALSE;
} }
foreach ($MXHOSTS as $host) foreach ($MXHOSTS as $host)
{ {
$this->log_write("Trying to " . $host . ":" . $this->smtp_port . "\n");
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) if (!($this->sock && $this->smtp_ok()))
{ {
$this->log_write("Warning: Cannot connect to mx host " . $host . "\n");
$this->log_write("Error: " . $errstr . " (" . $errno . ")\n");
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue; continue;
} }
$this->log_write("Connected to mx host " . $host . "\n");
$this->log_write("Connected to mx host ".$host."\n");
return TRUE; return TRUE;
} }
$this->log_write("Error: Cannot connect to any mx hosts (" . implode(", ", $MXHOSTS) . ")\n");
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE; return FALSE;
} }
function smtp_message($header, $body) function smtp_message($header, $body)
{ {
fputs($this->sock, $header . "\r\n" . $body);
$this->smtp_debug("> " . str_replace("\r\n", "\n" . "> ", $header . "\n> " . $body . "\n> "));
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE; return TRUE;
} }
function smtp_eom() function smtp_eom()
@@ -212,12 +212,12 @@ class smtp
function smtp_ok() function smtp_ok()
{ {
$response = str_replace("\r\n", "", fgets($this->sock, 512)); $response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response . "\n");
$this->smtp_debug($response."\n");
if (!preg_match("#^[23]#", $response)) if (!preg_match("#^[23]#", $response))
{ {
fputs($this->sock, "QUIT\r\n"); fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512); fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"" . $response . "\"\n");
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@@ -230,16 +230,16 @@ class smtp
{ {
$cmd = $arg; $cmd = $arg;
} else { } else {
$cmd = $cmd . " " . $arg;
$cmd = $cmd." ".$arg;
} }
} }
fputs($this->sock, $cmd . "\r\n");
$this->smtp_debug("> " . $cmd . "\n");
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok(); return $this->smtp_ok();
} }
function smtp_error($string) function smtp_error($string)
{ {
$this->log_write("Error: Error occurred while " . $string . ".\n");
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE; return FALSE;
} }
function log_write($message) function log_write($message)
@@ -249,10 +249,10 @@ class smtp
{ {
return TRUE; return TRUE;
} }
$message = date("M d H:i:s ") . get_current_user() . "[" . getmypid() . "]: " . $message;
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{ {
$this->smtp_debug("Warning: Cannot open log file \"" . $this->log_file . "\"\n");
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;; return FALSE;;
} }
flock($fp, LOCK_EX); flock($fp, LOCK_EX);


+ 2
- 2
src/theme/plus/download_links_templet.htm View File

@@ -15,7 +15,7 @@
</style> </style>
</head> </head>
<body> <body>
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="sp-title"> <div class="sp-title">
<h2>文件:<a href="<?php echo $arcurl; ?>"><?php echo $title; ?></a></h2> <h2>文件:<a href="<?php echo $arcurl; ?>"><?php echo $title; ?></a></h2>
@@ -32,6 +32,6 @@
</div> </div>
</div> </div>
<div class="advancedsearch"></div> <div class="advancedsearch"></div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

+ 2
- 2
src/theme/plus/flink-add.htm View File

@@ -10,7 +10,7 @@
<script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script> <script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script>
</head> </head>
<body class="flinkpage"> <body class="flinkpage">
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="sp-title"> <div class="sp-title">
<nav class="navbar navbar-expand-lg"> <nav class="navbar navbar-expand-lg">
@@ -81,6 +81,6 @@
</form> </form>
</div> </div>
</div> </div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

+ 2
- 2
src/theme/plus/flink-list.htm View File

@@ -10,7 +10,7 @@
<script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script> <script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script>
</head> </head>
<body class="flinkpage"> <body class="flinkpage">
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="sp-title"> <div class="sp-title">
<nav class="navbar navbar-expand-lg"> <nav class="navbar navbar-expand-lg">
@@ -49,6 +49,6 @@
</ul> </ul>
</div> </div>
</div> </div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

+ 2
- 2
src/theme/plus/heightsearch.htm View File

@@ -9,7 +9,7 @@
<link rel="stylesheet" href="<?php echo $cfg_cmsurl; ?>/static/web/css/style.css"> <link rel="stylesheet" href="<?php echo $cfg_cmsurl; ?>/static/web/css/style.css">
</head> </head>
<body class="flinkpage"> <body class="flinkpage">
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="formbox mt-3"> <div class="formbox mt-3">
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#cccccc" class='table'> <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#cccccc" class='table'>
@@ -101,6 +101,6 @@
<br> <br>
</div> </div>
</div> </div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

+ 2
- 2
src/theme/plus/recommend.htm View File

@@ -9,7 +9,7 @@
<link rel="stylesheet" href="<?php echo $cfg_cmsurl; ?>/static/web/css/style.css"> <link rel="stylesheet" href="<?php echo $cfg_cmsurl; ?>/static/web/css/style.css">
</head> </head>
<body class="flinkpage"> <body class="flinkpage">
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="sp-title mt-3">推荐:<?php echo $title; ?></div> <div class="sp-title mt-3">推荐:<?php echo $title; ?></div>
<div class="formbox"> <div class="formbox">
@@ -42,6 +42,6 @@
</form> </form>
</div> </div>
</div> </div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

+ 2
- 2
src/theme/plus/view_msg.htm View File

@@ -10,7 +10,7 @@
<script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script> <script src="<?php echo $cfg_cmsurl; ?>/static/web/js/jquery.min.js"></script>
</head> </head>
<body class="flinkpage"> <body class="flinkpage">
<?php include("plus_header.htm") ; ?>
<?php include("plus_header.htm"); ?>
<div class="container"> <div class="container">
<div class="sp-title"> <div class="sp-title">
<span class="more"> <span class="more">
@@ -43,6 +43,6 @@
<br> <br>
</div> </div>
</div> </div>
<?php include("plus_footer.htm") ; ?>
<?php include("plus_footer.htm"); ?>
</body> </body>
</html> </html>

Loading…
Cancel
Save