增加帖子标签和升级Sql

This commit is contained in:
taoser 2021-05-27 18:09:24 +08:00
parent 95314c0f36
commit 82680460f2
14 changed files with 123 additions and 38 deletions

View File

@ -7,8 +7,8 @@
* 后台http://adm.aieok.com * 后台http://adm.aieok.com
* 账号test * 账号test
* 密码test123 * 密码test123
* 版本TaoLer 1.7.6 * 版本TaoLer 1.7.7
* 日期2021.5.25 * 日期2021.5.27
#### 项目地址 #### 项目地址

View File

@ -25,6 +25,7 @@ use think\facade\Config;
use think\facade\Log; use think\facade\Log;
use app\common\lib\ZipFile; use app\common\lib\ZipFile;
use app\common\lib\SetConf; use app\common\lib\SetConf;
use app\common\lib\SqlFile;
class Upgrade extends AdminController class Upgrade extends AdminController
{ {
@ -226,10 +227,7 @@ class Upgrade extends AdminController
if(file_exists($upSql)) if(file_exists($upSql))
{ {
$result = $this->db_update($upSql); $result = $this->db_update($upSql);
if(!$result && $result < 0) return $result;
{
return json(['code'=>-1,'msg'=>'数据库升级失败']);
}
} }
@ -342,9 +340,15 @@ class Upgrade extends AdminController
*/ */
public function db_update($file) public function db_update($file)
{ {
$sql = file_get_contents($file); $sqlf = new SqlFile();
$sqlRes = Db::execute($sql); $sql_array = $sqlf->load_sql_file($file);
return $sqlRes; foreach($sql_array as $v){
$sqlRes = Db::execute($v);
if ($sqlRes === false) {
return json(['code'=>-1,'msg'=>'数据库升级失败']);
}
}
} }

View File

@ -0,0 +1,66 @@
<?php
declare (strict_types = 1);
namespace app\common\lib;
use think\facade\Lang;
class SqlFile
{
/**
* 加载sql文件为分号分割的数组
* <br />支持存储过程和函数提取,自动过滤注释
* <br />例如: 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;
}
}

View File

@ -96,7 +96,7 @@ class Article extends Model
{ {
$artTop = Cache::get('arttop'); $artTop = Cache::get('arttop');
if (!$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) { 'cate' => function ($query) {
$query->where('delete_time', 0)->field('id,catename,ename'); $query->where('delete_time', 0)->field('id,catename,ename');
}, },
@ -121,7 +121,7 @@ class Article extends Model
{ {
$artList = Cache::get('artlist'); $artList = Cache::get('artlist');
if(!$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([ ->with([
'cate' => function($query){ 'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename'); $query->where('delete_time',0)->field('id,catename,ename');
@ -209,7 +209,7 @@ class Article extends Model
switch ($type) { switch ($type) {
//查询文章,15个分1页 //查询文章,15个分1页
case 'jie': 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){ 'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename'); $query->where('delete_time',0)->field('id,catename,ename');
}, },
@ -225,7 +225,7 @@ class Article extends Model
break; break;
case 'hot': 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){ 'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename'); $query->where('delete_time',0)->field('id,catename,ename');
}, },
@ -241,7 +241,7 @@ class Article extends Model
break; break;
case 'top': 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){ 'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename'); $query->where('delete_time',0)->field('id,catename,ename');
}, },
@ -257,7 +257,7 @@ class Article extends Model
break; break;
default: 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){ 'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename'); $query->where('delete_time',0)->field('id,catename,ename');
}, },

View File

@ -165,6 +165,11 @@ class Article extends BaseController
if (true !== $result) { if (true !== $result) {
return Msgres::error($validate->getError()); return Msgres::error($validate->getError());
} }
//判断是否插入图片
$isHasImg = strpos($data['content'],'img[');
if(is_int($isHasImg)){
$data['has_img'] = 1;
};
$article = new ArticleModel(); $article = new ArticleModel();
$result = $article->add($data); $result = $article->add($data);
if ($result == 1) { if ($result == 1) {
@ -199,9 +204,14 @@ class Article extends BaseController
$validate = new \app\common\validate\Article(); //调用验证器 $validate = new \app\common\validate\Article(); //调用验证器
$res = $validate->scene('Artadd')->check($data); //进行数据验证 $res = $validate->scene('Artadd')->check($data); //进行数据验证
if(true !==$res){ if(true !== $res){
return Msgres::error($validate->getError()); return Msgres::error($validate->getError());
} else { } else {
//判断是否插入图片
$isHasImg = strpos($data['content'],'img[');
if(is_int($isHasImg)){
$data['has_img'] = 1;
};
$result = $article->edit($data); $result = $article->edit($data);
if($result == 1) { if($result == 1) {
//删除原有缓存显示编辑后内容 //删除原有缓存显示编辑后内容

View File

@ -152,7 +152,9 @@ class User extends BaseController
//查出当前用户头像删除原头像并更新 //查出当前用户头像删除原头像并更新
$imgPath = Db::name('user')->where('id',$this->uid)->value('user_img'); $imgPath = Db::name('user')->where('id',$this->uid)->value('user_img');
unlink('.'.$imgPath); if(file_exists($imgPath)){
unlink('.'.$imgPath);
}
$result = Db::name('user') $result = Db::name('user')
->where('id',$this->uid) ->where('id',$this->uid)
->update(['user_img'=>$name_path]); ->update(['user_img'=>$name_path]);

View File

@ -64,19 +64,15 @@ function create_tables($db, $prefix = '')
//$v=$v.';'; //$v=$v.';';
//执行创建表 //执行创建表
if (substr($v, 0, 12) == 'CREATE TABLE') { if (substr($v, 0, 12) == 'CREATE TABLE') {
$res = $db->exec($v); //执行成功也返回0这里有疑问
//halt($res);
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v); $name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
$msg = "创建数据表{$name}"; $msg = "创建数据表{$name}";
$res = $db->exec($v); //执行成功也返回0这里有疑问
if ($res === false) { if ($res === false) {
echo "{$msg}失败\r\n"; echo "{$msg}失败\r\n";
} }
} elseif(substr($v, 0, 11) == 'INSERT INTO') { } 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}数据"; $msg = "插入表{$name}数据";
$res = $db->exec($v); $res = $db->exec($v);
if ($res === false) { if ($res === false) {

View File

@ -58,6 +58,7 @@ CREATE TABLE `tao_article` (
`is_top` enum('0','1') NOT NULL DEFAULT '0' COMMENT '置顶1否0', `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_hot` enum('0','1') NOT NULL DEFAULT '0' COMMENT '推荐1否0',
`is_reply` enum('1','0') NOT NULL DEFAULT '1' COMMENT '0禁评1可评', `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 '浏览量', `pv` int(11) NOT NULL DEFAULT '0' COMMENT '浏览量',
`jie` enum('1','0') NOT NULL DEFAULT '0' COMMENT '0未结1已结', `jie` enum('1','0') NOT NULL DEFAULT '0' COMMENT '0未结1已结',
`upzip` varchar(70) DEFAULT NULL COMMENT '文章附件', `upzip` varchar(70) DEFAULT NULL COMMENT '文章附件',
@ -73,12 +74,12 @@ CREATE TABLE `tao_article` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `user_id` (`user_id`) USING BTREE COMMENT '文章的用户索引', KEY `user_id` (`user_id`) USING BTREE COMMENT '文章的用户索引',
KEY `cate_id` (`cate_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 -- 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 -- Table structure for tao_auth_group

View File

@ -7,7 +7,7 @@ return [
//应用名,此项不可更改 //应用名,此项不可更改
'appname' => 'TaoLer', 'appname' => 'TaoLer',
//版本配置 //版本配置
'version' => '1.7.4', 'version' => '1.7.6',
//加盐 //加盐
'salt' => 'taoler', 'salt' => 'taoler',
//数据库备份目录 //数据库备份目录

View File

@ -680,7 +680,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'imgcom'],
var uid = layui.cache.user.uid; var uid = layui.cache.user.uid;
if(uid == -1){ if(uid == -1){
console.log(uid); console.log(uid);
layer.msg('请登录再评论', {icon: 6}, function(){ layer.msg('请登录再签到', {icon: 6}, function(){
location.href = login; location.href = login;
}) })
return false; return false;

View File

@ -1 +1 @@
/version /*

View File

@ -36,12 +36,14 @@
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i> <i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
{/if} {/if}
</a> </a>
<span>{$art.create_time|date='Y-m-d'}</span> <span>
{$art.create_time|date='Y-m-d'}
{$art.has_img ?= ' <i class="layui-icon layui-icon-picture" style=" color: #5FB878;"></i>'}
{$art.upzip ?= ' <i class="layui-icon layui-icon-file-b" style="color: #009688;" title="附件"></i>'}
</span>
<span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span> <span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span>
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if} {if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums"> <span class="fly-list-nums">
{notempty name="$art.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i> {$art.comments_count} <i class="iconfont icon-pinglun1" title="回答"></i> {$art.comments_count}
</span> </span>
</div> </div>

View File

@ -17,17 +17,19 @@
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i> <i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
{/if} {/if}
</a> </a>
<span>{$art.create_time|date='Y-m-d'}</span> <span>
{$art.create_time|date='Y-m-d'}
{$art.has_img ?= ' <i class="layui-icon layui-icon-picture" style="color: #5FB878;"></i>'}
{$art.upzip ?= ' <i class="layui-icon layui-icon-file-b" style="color: #009688;" title="附件"></i>'}
</span>
<span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span> <span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span>
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if} {if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums"> <span class="fly-list-nums">
{notempty name="$art.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i>{$art.comments_count} <i class="iconfont icon-pinglun1" title="回答"></i>{$art.comments_count}
</span> </span>
</div> </div>
<div class="fly-list-badge"> <div class="fly-list-badge">
{if ($art.is_top == 1)} <span class="layui-badge layui-bg-black" >{:lang('top')}</span> {/if}
{if ($art.is_hot == 1)} <span class="layui-badge layui-bg-red">{:lang('hot')}</span> {/if} {if ($art.is_hot == 1)} <span class="layui-badge layui-bg-red">{:lang('hot')}</span> {/if}
</div> </div>
</li> </li>

View File

@ -15,16 +15,18 @@
<i class="layui-badge fly-badge-vip">vip{$top.user.vip}</i> <i class="layui-badge fly-badge-vip">vip{$top.user.vip}</i>
{/if} {/if}
</a> </a>
<span>{$top.create_time|date='Y-m-d'}</span> <span>
{$top.create_time|date='Y-m-d'}
{$top.has_img ?= ' <i class="layui-icon layui-icon-picture" style=" color: #5FB878;"></i>'}
{$top.upzip ?= ' <i class="layui-icon layui-icon-file-b" style="color: #009688;" title="附件"></i>'}
</span>
<span class=" layui-hide-xs" title="浏览"> <i class="iconfont" title="浏览">&#xe60b;</i> {$top.pv} </span> <span class=" layui-hide-xs" title="浏览"> <i class="iconfont" title="浏览">&#xe60b;</i> {$top.pv} </span>
{if ($top.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if} {if ($top.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums"> <span class="fly-list-nums">
{notempty name="$top.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i> {$top.comments_count} <i class="iconfont icon-pinglun1" title="回答"></i> {$top.comments_count}
</span> </span>
</div> </div>
<div class="fly-list-badge"> <div class="fly-list-badge">
{if ($top.is_top == 1)} <span class="layui-badge layui-bg-black" >{:lang('top')}</span> {/if} {if ($top.is_top == 1)} <span class="layui-badge layui-bg-black" >{:lang('top')}</span> {/if}
{if ($top.is_hot == 1)} <span class="layui-badge layui-bg-red">{:lang('hot')}</span> {/if}
</div> </div>
</li> </li>