huwhois 3 年之前
父节点
当前提交
c2acd683a3

+ 2 - 0
app/index/config/app.php

@@ -4,6 +4,8 @@
 // +----------------------------------------------------------------------
 
 return [
+    // 应用Trace
+    'app_trace'              => false,
     // html 静态化
     'html'             =>  env('www.html',false),
     // 默认分页显示数量

+ 7 - 1
app/index/controller/Base.php

@@ -69,6 +69,12 @@ abstract class Base
 
         View::assign('seo', $this->seo);
 
+        if (Env::get('app.app_env', false)) {
+            View::assign('bdtongji', $system->tongji);
+        } else {
+            View::assign('bdtongji', "");
+        }
+
         // 菜单
         $categories = Category::where('is_nav', 1)->order(['sort desc'])->select();
 
@@ -128,7 +134,7 @@ abstract class Base
                 mkdir($dir, 0755, true);
                 @file_put_contents($dir.'/index.html', "");  // 添加空html文件
             }
-            
+
             @file_put_contents($filename, $html);
         }
     }

+ 35 - 3
app/sys/controller/Article.php

@@ -13,13 +13,14 @@ namespace app\sys\controller;
 
 // 引入框架内置类
 use think\facade\View;
+use think\facade\Config;
 
 use app\common\model\Category as CategoryModel;
 use app\common\model\Article as ArticleModel;
+use app\common\service\FileService;
 
 /**
- * 文章管理  
-
+ * 文章管理控制器
  */
 class Article extends Base
 {
@@ -57,12 +58,16 @@ class Article extends Base
             }
 
             $params['content'] =  isset($params['content']) ? $params['content'] : '';
+            if ($content_type == 0) {
+                $params['content'] = $this->saveRomteImage($params['content']);
+            }
+
             try {
                 if ($params['id'] != 0) {
                     ArticleModel::update($params);
                 } else {
                     $params['userid'] = $this->getSysUser()->userid;
-                    $params['username'] = $this->getSysUser()->username;
+                    $params['username'] = $this->getSysUser()->nickname;
                     unset($params['id']);
                     ArticleModel::create($params);
                 }
@@ -90,4 +95,31 @@ class Article extends Base
             return View::fetch($template);
         }
     }
+
+    protected function saveRomteImage($content)
+    {
+        $fileService = new FileService();
+
+        $content = stripslashes ($content);
+        $img_array = [];
+        // 匹配所有远程图片
+        $pattern = '/src="(http[s]:\/\/.*)"/isU';
+        preg_match_all ($pattern,$content,$img_array);
+        
+        // 删除重复 url
+        $img_arrays = array_unique ($img_array[1]);
+
+        foreach ($img_arrays as $value) {
+            $file = $fileService->urlImg($value);
+            
+            $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
+            
+            $filename = Config::get('filesystem.disks.public.url') . '/' . str_replace('\\', '/', $savename);
+
+            // dump($filename);
+            $content = str_replace($value, $filename, $content);
+        }
+
+        return $content;
+    }
 }

+ 9 - 0
app/sys/controller/Ueditor.php

@@ -122,6 +122,15 @@ class Ueditor extends Base
                 ];
                 $fieldName = $this->config['imageFieldName'];
                 break;
+            case 'uploadurlimage':
+                $uploadconfig = [
+                    "pathFormat" => $this->config['imagePathFormat'],
+                    "maxSize" => $this->config['imageMaxSize'],
+                    "allowFiles" => $this->config['imageAllowFiles']
+                ];
+                $fieldName = $this->config['imageFieldName'];
+                $base64 = "uploadurlimage";
+                break;
             case 'uploadscrawl':
                 $uploadconfig = array(
                     "pathFormat" => $this->config['scrawlPathFormat'],

+ 1 - 1
config/session.php

@@ -13,7 +13,7 @@ return [
     // 存储连接标识 当type使用cache的时候有效
     'store'          => null,
     // 过期时间
-    'expire'         => 1440,
+    'expire'         => 60*60*4,
     // 前缀
     'prefix'         => '',
 ];

+ 3 - 3
view/index/aside.html

@@ -8,7 +8,7 @@
     <h2>最近更新</h2>
     <ul>
       {foreach $last_lists as $value}
-      <li><a href="/index/{$value.create_time|date='Y/m/d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+      <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
       {/foreach}
     </ul>
   </div>
@@ -16,7 +16,7 @@
     <h2>点击排行</h2>
     <ul>
       {foreach $hits_lists as $value}
-      <li><a href="/index/{$value.create_time|date='Y/m/d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+      <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
       {/foreach}
     </ul>
   </div>
@@ -24,7 +24,7 @@
     <h2>博文推荐</h2>
     <ul>
       {foreach $top_lists as $value}
-      <li><a href="/index/{$value.create_time|date='Y/m/d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+      <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
       {/foreach}
     </ul>
   </div>

+ 1 - 0
view/index/layout.html

@@ -32,6 +32,7 @@
     <p>Power by <a href="{:env('domain.email')}" target="_blank">{:env('domain.email')}</a> </p>
     <p>备案号:<a href="https://beian.miit.gov.cn/" style="color:blue">{:env('domain.icp')} </a></p>
   </footer>
+  {$bdtongji|raw}
 </body>
 
 </html>

+ 2 - 3
view/sys/article/index.html

@@ -27,8 +27,7 @@
                 {/foreach}
             </select>
         </span>
-        <span class="r">共有数据:<strong id="total">{$list->total()}</strong>
-            条</span>
+        <span class="r">共有数据:<strong id="total">{$list->total()}</strong>条</span>
     </div>
     <div id="edatalist">
         <table class="table table-border table-bordered table-bg">
@@ -37,7 +36,7 @@
                     <th width="25px;">
                         <input type="checkbox" name="allcheck" value="">
                     </th>
-                    <th width="80px;">ID</th>
+                    <th width="60px;">ID</th>
                     <th style="min-width: 260px;">标题</th>
                     <th width="240px;">栏目</th>
                     <th width="160px;">发布者</th>

+ 24 - 6
view/sys/article/save.html

@@ -101,7 +101,7 @@
         <div class="row cl">
             <label class="form-label col-xs-1 col-sm-1"></label>
             <div class="formControls col-xs-11 col-sm-10">
-                <div id="editor" type="text/plain" style="width:100%;height:400px;" name="content">{$data.content|raw}</div>
+                <script id="editor" type="text/plain" style="width:100%;height:400px;">{$data.content|raw}</script>
             </div>
         </div>
         <div class="row cl">
@@ -128,14 +128,24 @@
     </form>
 </article>
 
-{include file="article/ueditor" /}
 
 <!--请在下方写此页面业务相关的脚本-->
 <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/jquery.validate.js"></script>
 <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/messages_zh.js"></script>
 <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/validate-methods.js"></script>
+<script type="text/javascript" src="/static/plugins/ueditor/1.4.3/ueditor.config.js"></script>
+<script type="text/javascript" src="/static/plugins/ueditor/1.4.3/ueditor.all.js"></script>
+<script type="text/javascript" src="/static/plugins/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
 
 <script type="text/javascript">
+    $(function () {
+        //实例化编辑器   
+        var ue = UE.getEditor('editor', {
+            autoHeightEnabled: false,
+            textarea: "content",
+        });
+    })
+
     function validator(params) {
         return $("#form-save").validate({
             debug: true,
@@ -143,13 +153,13 @@
                 title: {
                     required: true,
                 }
-                ,summary: {
+                , summary: {
                     maxlength: 500,
                 }
-                ,sort: {
+                , sort: {
                     max: 99
                 }
-                ,cid : {
+                , cid: {
                     required: true
                 }
             },
@@ -157,13 +167,21 @@
                 title: {
                     required: "标题不能为空"
                 }
-                ,cid: {
+                , cid: {
                     required: "栏目不能为空"
                 }
             }
         });
     }
 
+    $("#form-button-save").click(function () {
+        if (!validator().form()) {
+            return false
+        }
+
+        $("#form-save")[0].submit();
+    })
+
     //添加标题图
     function addTitlePic() {
         layer.open({

+ 5 - 2
view/sys/index/index.html

@@ -1,5 +1,3 @@
-
-
 <article class="cl pd-20">
     {if $indexTips}
     <div class="row">
@@ -229,6 +227,11 @@
         }, 'json');
     }
 
+    function  reflushIndex() {
+        $.get('/?force=true');
+        $.get('/index/index?force=true');
+    }
+
     function makeHtmlFile(url) {
         $.post('/sys/index/makehtmlfile',{'url': url}, function (res) {
             console.log(res);