diff --git a/README.md b/README.md
index 1d1654d..8149ac8 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,8 @@
* 后台:http://adm.aieok.com
* 账号:test
* 密码:test123
- * 版本:TaoLer 1.7.6
- * 日期:2021.5.25
+ * 版本:TaoLer 1.7.7
+ * 日期:2021.5.27
#### 项目地址
diff --git a/app/admin/controller/Upgrade.php b/app/admin/controller/Upgrade.php
index bf579da..5396e00 100644
--- a/app/admin/controller/Upgrade.php
+++ b/app/admin/controller/Upgrade.php
@@ -25,6 +25,7 @@ use think\facade\Config;
use think\facade\Log;
use app\common\lib\ZipFile;
use app\common\lib\SetConf;
+use app\common\lib\SqlFile;
class Upgrade extends AdminController
{
@@ -226,10 +227,7 @@ class Upgrade extends AdminController
if(file_exists($upSql))
{
$result = $this->db_update($upSql);
- if(!$result && $result < 0)
- {
- return json(['code'=>-1,'msg'=>'数据库升级失败']);
- }
+ return $result;
}
@@ -342,9 +340,15 @@ class Upgrade extends AdminController
*/
public function db_update($file)
{
- $sql = file_get_contents($file);
- $sqlRes = Db::execute($sql);
- return $sqlRes;
+ $sqlf = new SqlFile();
+ $sql_array = $sqlf->load_sql_file($file);
+ foreach($sql_array as $v){
+ $sqlRes = Db::execute($v);
+ if ($sqlRes === false) {
+ return json(['code'=>-1,'msg'=>'数据库升级失败']);
+ }
+ }
+
}
diff --git a/app/common/lib/SqlFile.php b/app/common/lib/SqlFile.php
new file mode 100644
index 0000000..adf1411
--- /dev/null
+++ b/app/common/lib/SqlFile.php
@@ -0,0 +1,66 @@
+支持存储过程和函数提取,自动过滤注释
+ *
例如: var_export(load_sql_file('mysql_routing_example/fn_cdr_parse_accountcode.sql'));
+ * @param string $path 文件路径
+ * @return boolean|array
+ * @since 1.0 <2015-5-27> SoChishun Added.
+ */
+ public function load_sql_file($path, $fn_splitor = ';;') {
+ if (!file_exists($path)) {
+ return false;
+ }
+ $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+ $aout = false;
+ $str = '';
+ $skip = false;
+ $fn = false;
+ foreach ($lines as $line) {
+ $line = trim($line);
+ // 过滤注释
+ if (!$line || 0 === strpos($line, '--') || 0 === strpos($line, '*') || 0 === strpos($line, '/*') || (false !== strpos($line, '*/') && strlen($line) == (strpos($line, '*/') + 2))) {
+ if (!$skip && 0 === strpos($line, '/*')) {
+ $skip = true;
+ }
+ if ($skip && false !== strpos($line, '*/') && strlen($line) == (strpos($line, '*/') + 2)) {
+ $skip = false;
+ }
+ continue;
+ }
+ if ($skip) {
+ continue;
+ }
+ // 提取存储过程和函数
+ if (0 === strpos($line, 'DELIMITER ' . $fn_splitor)) {
+ $fn = true;
+ continue;
+ }
+ if (0 === strpos($line, 'DELIMITER ;')) {
+ $fn = false;
+ $aout[] = $str;
+ $str = '';
+ continue;
+ }
+ if ($fn) {
+ $str .= $line . ' ';
+ continue;
+ }
+ // 提取普通语句
+ $str .= $line;
+ if (false !== strpos($line, ';') && strlen($line) == (strpos($line, ';') + 1)) {
+ $aout[] = $str;
+ $str = '';
+ }
+ }
+ return $aout;
+ }
+}
diff --git a/app/common/model/Article.php b/app/common/model/Article.php
index 58df97c..2f69138 100644
--- a/app/common/model/Article.php
+++ b/app/common/model/Article.php
@@ -96,7 +96,7 @@ class Article extends Model
{
$artTop = Cache::get('arttop');
if (!$artTop) {
- $artTop = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,pv,jie,upzip')->where(['is_top' => 1, 'status' => 1, 'delete_time' => 0])->with([
+ $artTop = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,pv,jie,upzip,has_img')->where(['is_top' => 1, 'status' => 1, 'delete_time' => 0])->with([
'cate' => function ($query) {
$query->where('delete_time', 0)->field('id,catename,ename');
},
@@ -121,7 +121,7 @@ class Article extends Model
{
$artList = Cache::get('artlist');
if(!$artList){
- $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_hot,pv,jie,upzip')
+ $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_hot,pv,jie,upzip,has_img')
->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
@@ -209,7 +209,7 @@ class Article extends Model
switch ($type) {
//查询文章,15个分1页
case 'jie':
- $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
+ $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip,has_img')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@@ -225,7 +225,7 @@ class Article extends Model
break;
case 'hot':
- $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
+ $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip,has_img')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@@ -241,7 +241,7 @@ class Article extends Model
break;
case 'top':
- $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
+ $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip,has_img')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@@ -257,7 +257,7 @@ class Article extends Model
break;
default:
- $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
+ $artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip,has_img')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php
index 4c10b90..3bb1cd7 100644
--- a/app/index/controller/Article.php
+++ b/app/index/controller/Article.php
@@ -165,6 +165,11 @@ class Article extends BaseController
if (true !== $result) {
return Msgres::error($validate->getError());
}
+ //判断是否插入图片
+ $isHasImg = strpos($data['content'],'img[');
+ if(is_int($isHasImg)){
+ $data['has_img'] = 1;
+ };
$article = new ArticleModel();
$result = $article->add($data);
if ($result == 1) {
@@ -199,9 +204,14 @@ class Article extends BaseController
$validate = new \app\common\validate\Article(); //调用验证器
$res = $validate->scene('Artadd')->check($data); //进行数据验证
- if(true !==$res){
+ if(true !== $res){
return Msgres::error($validate->getError());
} else {
+ //判断是否插入图片
+ $isHasImg = strpos($data['content'],'img[');
+ if(is_int($isHasImg)){
+ $data['has_img'] = 1;
+ };
$result = $article->edit($data);
if($result == 1) {
//删除原有缓存显示编辑后内容
diff --git a/app/index/controller/User.php b/app/index/controller/User.php
index 1e1cdc5..3448274 100644
--- a/app/index/controller/User.php
+++ b/app/index/controller/User.php
@@ -152,7 +152,9 @@ class User extends BaseController
//查出当前用户头像删除原头像并更新
$imgPath = Db::name('user')->where('id',$this->uid)->value('user_img');
- unlink('.'.$imgPath);
+ if(file_exists($imgPath)){
+ unlink('.'.$imgPath);
+ }
$result = Db::name('user')
->where('id',$this->uid)
->update(['user_img'=>$name_path]);
diff --git a/app/install/common.php b/app/install/common.php
index 30554c9..a9efc3e 100644
--- a/app/install/common.php
+++ b/app/install/common.php
@@ -64,19 +64,15 @@ function create_tables($db, $prefix = '')
//$v=$v.';';
//执行创建表
if (substr($v, 0, 12) == 'CREATE TABLE') {
- $res = $db->exec($v); //?执行成功也返回0,这里有疑问
- //halt($res);
-
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
$msg = "创建数据表{$name}";
-
-
+ $res = $db->exec($v); //?执行成功也返回0,这里有疑问
if ($res === false) {
echo "{$msg}失败\r\n";
}
} elseif(substr($v, 0, 11) == 'INSERT INTO') {
//执行插入数据
- $name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
+ $name = preg_replace("/^INSERT INTO `(\w+)` .*/s", "\\1", $v);
$msg = "插入表{$name}数据";
$res = $db->exec($v);
if ($res === false) {
diff --git a/app/install/data/taoler.sql b/app/install/data/taoler.sql
index 3961df3..e1f2d12 100644
--- a/app/install/data/taoler.sql
+++ b/app/install/data/taoler.sql
@@ -58,6 +58,7 @@ CREATE TABLE `tao_article` (
`is_top` enum('0','1') NOT NULL DEFAULT '0' COMMENT '置顶1否0',
`is_hot` enum('0','1') NOT NULL DEFAULT '0' COMMENT '推荐1否0',
`is_reply` enum('1','0') NOT NULL DEFAULT '1' COMMENT '0禁评1可评',
+ `has_img` enum('1','0') NOT NULL DEFAULT '0' COMMENT '1有图0无图',
`pv` int(11) NOT NULL DEFAULT '0' COMMENT '浏览量',
`jie` enum('1','0') NOT NULL DEFAULT '0' COMMENT '0未结1已结',
`upzip` varchar(70) DEFAULT NULL COMMENT '文章附件',
@@ -73,12 +74,12 @@ CREATE TABLE `tao_article` (
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`) USING BTREE COMMENT '文章的用户索引',
KEY `cate_id` (`cate_id`) USING BTREE COMMENT '文章分类索引'
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tao_article
-- ----------------------------
-INSERT INTO `tao_article` VALUES ('1', 'Fly Template 社区模版', '[quote]\r\n 你们认为layui官方Fly Template 社区模版怎么样?\r\n[/quote]\r\n你喜欢吗?\r\n很多人都说比较喜欢,我个人认为不错的,这个板子非常喜欢,我看到有一些人做了开发,可惜的是都没有很好的维护,有的漏洞比较多,不完善,很美好的一个板子,但没有长久 的更新,非常的可惜。\r\n如果用别人的不好用,那我就做一个出来吧。喜欢的人多关注,适当时候放出来大家一起用。\r\n关于详情页的内容解析\r\n该模板自带一个特定语法的编辑器,当你把内容存储到数据库后,在页面读取后浏览,会发现诸如“表情、代码、图片”等无法解析,这是因为需要对该内容进行一次转义,通常来说这是在服务端完成的,但鉴于简单化,你还可以直接在前端去解析,在模板的detail.html中,我们已经把相关的代码写好了,你只需打开注释即可(在代码的最下面)。当然,如果觉得编辑器无法满足你的需求,你也可以把该编辑器换成别的HTML编辑器或MarkDown编辑器。', '1', '1', '1', '0', '0', '1', '12', '0', null, '0', null, '0', null, null, null, '1546698225', '1577772362', '0');
+INSERT INTO `tao_article` VALUES ('1', 'Fly Template 社区模版', '[quote]\r\n 你们认为layui官方Fly Template 社区模版怎么样?\r\n[/quote]\r\n你喜欢吗?\r\n很多人都说比较喜欢,我个人认为不错的,这个板子非常喜欢,我看到有一些人做了开发,可惜的是都没有很好的维护,有的漏洞比较多,不完善,很美好的一个板子,但没有长久 的更新,非常的可惜。\r\n如果用别人的不好用,那我就做一个出来吧。喜欢的人多关注,适当时候放出来大家一起用。\r\n关于详情页的内容解析\r\n该模板自带一个特定语法的编辑器,当你把内容存储到数据库后,在页面读取后浏览,会发现诸如“表情、代码、图片”等无法解析,这是因为需要对该内容进行一次转义,通常来说这是在服务端完成的,但鉴于简单化,你还可以直接在前端去解析,在模板的detail.html中,我们已经把相关的代码写好了,你只需打开注释即可(在代码的最下面)。当然,如果觉得编辑器无法满足你的需求,你也可以把该编辑器换成别的HTML编辑器或MarkDown编辑器。', '1', '1', '1', '0', '0', '1', '0', '0', '0', null, '0', null, '0', null, null, null, '1546698225', '1577772362', '0');
-- ----------------------------
-- Table structure for tao_auth_group
diff --git a/config/taoler.php b/config/taoler.php
index 18c8b34..6c53618 100644
--- a/config/taoler.php
+++ b/config/taoler.php
@@ -7,7 +7,7 @@ return [
//应用名,此项不可更改
'appname' => 'TaoLer',
//版本配置
- 'version' => '1.7.4',
+ 'version' => '1.7.6',
//加盐
'salt' => 'taoler',
//数据库备份目录
diff --git a/public/static/res/mods/index.js b/public/static/res/mods/index.js
index 4f7813a..8a974ac 100644
--- a/public/static/res/mods/index.js
+++ b/public/static/res/mods/index.js
@@ -680,7 +680,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'imgcom'],
var uid = layui.cache.user.uid;
if(uid == -1){
console.log(uid);
- layer.msg('请登录再评论', {icon: 6}, function(){
+ layer.msg('请登录再签到', {icon: 6}, function(){
location.href = login;
})
return false;
diff --git a/public/storage/.gitignore b/public/storage/.gitignore
index ef9d3be..22e8364 100644
--- a/public/storage/.gitignore
+++ b/public/storage/.gitignore
@@ -1 +1 @@
-/version
\ No newline at end of file
+/*
\ No newline at end of file
diff --git a/view/taoler/index/article/cate.html b/view/taoler/index/article/cate.html
index 5d7be15..8c08122 100644
--- a/view/taoler/index/article/cate.html
+++ b/view/taoler/index/article/cate.html
@@ -36,12 +36,14 @@
vip{$art.user.vip}
{/if}
- {$art.create_time|date='Y-m-d'}
-
+
+ {$art.create_time|date='Y-m-d'}
+ {$art.has_img ?= ' '}
+ {$art.upzip ?= ' '}
+
{if ($art.jie == 1)} {/if}
- {notempty name="$art.upzip"}{/notempty}
{$art.comments_count}
diff --git a/view/taoler/index/public/index-forumlist.html b/view/taoler/index/public/index-forumlist.html
index f9b0df8..382b944 100644
--- a/view/taoler/index/public/index-forumlist.html
+++ b/view/taoler/index/public/index-forumlist.html
@@ -17,17 +17,19 @@
vip{$art.user.vip}
{/if}
- {$art.create_time|date='Y-m-d'}
+
+ {$art.create_time|date='Y-m-d'}
+ {$art.has_img ?= ' '}
+ {$art.upzip ?= ' '}
+
{if ($art.jie == 1)} {/if}
- {notempty name="$art.upzip"}{/notempty}
{$art.comments_count}