Procházet zdrojové kódy

代码美化

tags/6.5.6
叙述、别离 před 4 dny
rodič
revize
2cac82fd53
6 změnil soubory, kde provedl 23 přidání a 47 odebrání
  1. +0
    -1
      src/admin/article_edit.php
  2. +1
    -1
      src/system/archive/searchview.class.php
  3. +20
    -41
      src/system/common.func.php
  4. +0
    -2
      src/system/common.inc.php
  5. +1
    -1
      src/system/helpers/channelunit.helper.php
  6. +1
    -1
      src/system/taglib/infolink.lib.php

+ 0
- 1
src/admin/article_edit.php Zobrazit soubor

@@ -75,7 +75,6 @@ if ($dopost != 'save') {
$senddate = GetMkTime($senddate);
$sortrank = AddDay($pubdate, $sortup);
$ismake = $ishtml == 0 ? -1 : 0;
$title = dede_htmlspecialchars(cn_substrR($title, $cfg_title_maxlen));
$shorttitle = cn_substrR($shorttitle, 255);
$color = cn_substrR($color, 7);


+ 1
- 1
src/system/archive/searchview.class.php Zobrazit soubor

@@ -357,7 +357,7 @@ class SearchView
$this->AddTable = "#@__archives";
}
$cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql;
// var_dump($cquery);
//var_dump($cquery);
$hascode = md5($cquery);
$row = $this->dsql->GetOne("SELECT * FROM `#@__arccache` WHERE `md5hash`='".$hascode."' ");
$uptime = time();


+ 20
- 41
src/system/common.func.php Zobrazit soubor

@@ -702,108 +702,87 @@ function DedeSearchAPIURL($action, $parms=array())

return $finalUrl;
}

function ConvertMysqlToSqlite($mysqlQuery) {
// 移除 CHARACTER SET COLLATE
//移除CHARACTER SET和COLLATE
$query = preg_replace('/character set \S+/i', '', $mysqlQuery);
$query = preg_replace('/collate \S+/i', '', $query);
// 移除 unsigned 关键字
//移除unsigned关键字
$query = str_replace('unsigned', '', $query);
// 替换 MySQL 的整数类型为 SQLite 的 INTEGER
//替换MySQL的整数类型为SQLite的INTEGER
$query = preg_replace('/\b(TINY|SMALL|MEDIUM|BIG)?INT\(\d+\)/i', 'INTEGER', $query);
// 替换 AUTO_INCREMENT 为 PRIMARY KEY AUTOINCREMENT (仅适用于 INTEGER 类型)
//替换AUTO_INCREMENT为PRIMARY KEY AUTOINCREMENT (仅适用于INTEGER类型)
$query = preg_replace('/\bINTEGER\s+NOT NULL\s+PRIMARY KEY AUTOINCREMENT/i', 'INTEGER PRIMARY KEY AUTOINCREMENT', $query);
$query = preg_replace('/\bAUTO_INCREMENT\b/i', '', $query);
// 移除 MySQL 特有的 ENGINE、CHARSET、COLLATE、TYPE 选项
//移除MySQL特有的ENGINE、CHARSET、COLLATE、TYPE选项
$query = preg_replace('/ENGINE=\S+/i', '', $query);
$query = preg_replace('/DEFAULT CHARSET=\S+/i', '', $query);
$query = preg_replace('/COLLATE=\S+/i', '', $query);
$query = preg_replace('/TYPE=MyISAM;/i', '', $query);
// 移除 COMMENT 语法(SQLite 不支持)
//移除COMMENT语法(SQLite不支持)
$query = preg_replace('/COMMENT\s+\'[^\']*\'/i', '', $query);
// 移除 KEY 和 UNIQUE KEY 定义(SQLite 会自动管理索引),同时处理 USING BTREE
//移除KEY和UNIQUE KEY定义(SQLite会自动管理索引),同时处理USING BTREE
$query = preg_replace('/,?\s*KEY\s+\S+\s*\([^)]*\)\s*(USING BTREE)?/i', '', $query);
$query = preg_replace('/,?\s*UNIQUE KEY\s+\S+\s*\([^)]*\)\s*(USING BTREE)?/i', '', $query);
// 移除不完整的 UNIQUE 定义
//移除不完整的UNIQUE定义
$query = preg_replace('/,?\s*UNIQUE\s*(?!\()/', '', $query);
// 替换 ENUM 和 SET 为 TEXT
//替换ENUM和SET为TEXT
$query = preg_replace('/\b(ENUM|SET)\([^)]*\)/i', 'TEXT', $query);
// 替换 MEDIUMTEXT 为 TEXT
//替换MEDIUMTEXT为TEXT
$query = preg_replace('/\bMEDIUMTEXT\b/i', 'TEXT', $query);
// 处理 DEFAULT CURRENT_TIMESTAMP
//处理DEFAULT CURRENT_TIMESTAMP
$query = preg_replace('/DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP/i', 'DEFAULT CURRENT_TIMESTAMP', $query);
// 处理 DEFAULT 值
//处理DEFAULT值
$query = preg_replace('/DEFAULT\s+\'([^\']+)\'/i', 'DEFAULT "$1"', $query);
// 处理 PRIMARY KEY 只能用于 INTEGER
//处理PRIMARY KEY只能用于INTEGER
if (preg_match('/PRIMARY KEY \(`(\w+)`\)/', $query, $matches)) {
$primaryKeyColumn = $matches[1];
$query = preg_replace('/,?\s*PRIMARY KEY\s*\(`' . $primaryKeyColumn . '`\)/i', '', $query);
$query = preg_replace('/(`' . $primaryKeyColumn . '`\s+INTEGER)/i', '$1 PRIMARY KEY', $query);
}
// 处理 CONCAT 替换为 SQLite 兼容形式
//处理CONCAT替换为SQLite兼容形式
if (preg_match('/CONCAT\(([^)]*?)\)/i', $query, $matches)) {
$query = preg_replace('/CONCAT\(([^)]*?)\)/i', str_replace(",", "||", $matches[1]), $query);
$query = str_replace("'||'", "','", $query);
}
// 修正 FIND_IN_SET 替换
//修正FIND_IN_SET替换
$query = preg_replace("/FIND_IN_SET\('([\w]+)', arc.flag\)>0/i", "(',' || arc.flag || ',') LIKE '%,\\1,%'", $query);
$query = preg_replace("/FIND_IN_SET\('([\w]+)', arc.flag\)<1/i", "(',' || arc.flag || ',') NOT LIKE '%,\\1,%'", $query);

// 修正 FIND_IN_SET 替换(允许列名包含点号)
//修正FIND_IN_SET替换(允许列名包含点号)
$query = preg_replace_callback(
"/FIND_IN_SET\s*\(\s*'([^']+)'\s*,\s*([a-zA-Z0-9_`\.]+)\s*\)/i",
function ($matches) {
// 返回 SQLite 兼容的 LIKE 语法
//返回SQLite兼容的LIKE语法
return "(',' || " . $matches[2] . " || ',' LIKE '%," . $matches[1] . ",%')";
},
$query
);
// 替换 FIELD 函数为 CASE 表达式
//替换FIELD函数为CASE表达式
$query = preg_replace_callback(
'/\bFIELD\s*\(\s*([^,]+)\s*,\s*((?:\'[^\']+\'|`[^`]+`|[^),]+(?:,\s*)?)+)\s*\)/i',
function ($matches) {
$field = trim($matches[1]);
$values = trim($matches[2]);
// 更精确分割值列表(支持带引号、反引号及无空格分隔的数值)
//更精确分割值列表(支持带引号、反引号及无空格分隔的数值)
preg_match_all('/\'[^\']+\'|`[^`]+`|\d+|\w+/', $values, $valueParts);
$cases = [];
$position = 1;
foreach ($valueParts[0] as $value) {
$cases[] = "WHEN $field = $value THEN $position";
$position++;
}
return "(CASE " . implode(' ', $cases) . " ELSE 0 END)";
},
$query
);
// 新增的转换逻辑
//新增的转换逻辑
$query = preg_replace("/SHOW fields FROM `([\w]+)`/i", "PRAGMA table_info('\\1') ", $query);
$query = preg_replace("/SHOW CREATE TABLE `([\w]+)`/i", "SELECT 0,sql FROM sqlite_master WHERE name='\\1'; ", $query);
$query = preg_replace("/Show Tables/i", "SELECT name FROM sqlite_master WHERE type = \"table\"", $query);
$query = str_replace("\'", "\"", $query);
$query = str_replace('\t\n', "", $query);
$query = str_ireplace('rand', 'RANDOM', $query);
return trim($query);
}

//自定义函数接口
if (file_exists(DEDEINC.'/extend.func.php')) {
require_once(DEDEINC.'/extend.func.php');


+ 0
- 2
src/system/common.inc.php Zobrazit soubor

@@ -112,11 +112,9 @@ $isUrlOpen = @ini_get("allow_url_fopen");
if (!file_exists(DEDEDATA."/config.cache.inc.php") && !defined('DEDE_CLITOOLS')) {
die('DedeBIZ初始化失败,确保系统正确被安装');
}

if (file_exists(DEDEDATA."/config.cache.inc.php")) {
require_once(DEDEDATA."/config.cache.inc.php");
}

//Session保存路径
$sessSaveHandler = @ini_get("session.save_handler");
if ($sessSaveHandler !== "files") {


+ 1
- 1
src/system/helpers/channelunit.helper.php Zobrazit soubor

@@ -97,7 +97,7 @@ if (!function_exists('GetFileUrl')) {
if (!function_exists('GetFileNewName')) {
function GetFileNewName($aid, $typeid, $timetag, $title, $ismake = 0, $rank = 0, $namerule = '', $typedir = '', $money = 0, $filename = '')
{
global $cfg_arc_dirname,$cfg_rewrite;
global $cfg_arc_dirname, $cfg_rewrite;
$articlename = GetFileName($aid, $typeid, $timetag, $title, $ismake, $rank, $namerule, $typedir, $money, $filename);
if (preg_match("/\?/", $articlename)) {
return $articlename;


+ 1
- 1
src/system/taglib/infolink.lib.php Zobrazit soubor

@@ -32,7 +32,7 @@ function lib_infolink(&$ctag, &$refObj)
$cmspath = ((empty($cfg_cmspath) || !preg_match("#\/$#", $cfg_cmspath)) ? $cfg_cmspath.'/' : $cfg_cmspath);
$baseurl = preg_replace("#\/$#", '', $cfg_mainsite).$cmspath;
$smalltypes = '';
if($baseurl == "/") $baseurl = "";
if ($baseurl == "/") $baseurl = "";
if (!empty($refObj->TypeLink->TypeInfos['smalltypes'])) {
$smalltypes = explode(',', $refObj->TypeLink->TypeInfos['smalltypes']);
}


Načítá se…
Zrušit
Uložit