增加帖子标签和升级Sql
This commit is contained in:
parent
95314c0f36
commit
82680460f2
@ -7,8 +7,8 @@
|
||||
* 后台:http://adm.aieok.com
|
||||
* 账号:test
|
||||
* 密码:test123
|
||||
* 版本:TaoLer 1.7.6
|
||||
* 日期:2021.5.25
|
||||
* 版本:TaoLer 1.7.7
|
||||
* 日期:2021.5.27
|
||||
|
||||
#### 项目地址
|
||||
|
||||
|
@ -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'=>'数据库升级失败']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
66
app/common/lib/SqlFile.php
Normal file
66
app/common/lib/SqlFile.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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');
|
||||
},
|
||||
|
@ -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) {
|
||||
@ -202,6 +207,11 @@ class Article extends BaseController
|
||||
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) {
|
||||
//删除原有缓存显示编辑后内容
|
||||
|
@ -152,7 +152,9 @@ class User extends BaseController
|
||||
|
||||
//查出当前用户头像删除原头像并更新
|
||||
$imgPath = Db::name('user')->where('id',$this->uid)->value('user_img');
|
||||
if(file_exists($imgPath)){
|
||||
unlink('.'.$imgPath);
|
||||
}
|
||||
$result = Db::name('user')
|
||||
->where('id',$this->uid)
|
||||
->update(['user_img'=>$name_path]);
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -7,7 +7,7 @@ return [
|
||||
//应用名,此项不可更改
|
||||
'appname' => 'TaoLer',
|
||||
//版本配置
|
||||
'version' => '1.7.4',
|
||||
'version' => '1.7.6',
|
||||
//加盐
|
||||
'salt' => 'taoler',
|
||||
//数据库备份目录
|
||||
|
@ -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;
|
||||
|
2
public/storage/.gitignore
vendored
2
public/storage/.gitignore
vendored
@ -1 +1 @@
|
||||
/version
|
||||
/*
|
@ -36,12 +36,14 @@
|
||||
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
|
||||
{/if}
|
||||
</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="浏览"></i> {$art.pv}</span>
|
||||
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
|
||||
<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}
|
||||
</span>
|
||||
</div>
|
||||
|
@ -17,17 +17,19 @@
|
||||
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
|
||||
{/if}
|
||||
</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="浏览"></i> {$art.pv}</span>
|
||||
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
|
||||
|
||||
<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}
|
||||
</span>
|
||||
</div>
|
||||
<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}
|
||||
</div>
|
||||
</li>
|
@ -15,16 +15,18 @@
|
||||
<i class="layui-badge fly-badge-vip">vip{$top.user.vip}</i>
|
||||
{/if}
|
||||
</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="浏览"></i> {$top.pv} </span>
|
||||
{if ($top.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
|
||||
<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}
|
||||
</span>
|
||||
</div>
|
||||
<div class="fly-list-badge">
|
||||
{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>
|
||||
</li>
|
Loading…
Reference in New Issue
Block a user