huwhois 4 months ago
parent
commit
60e3b1da32
8 changed files with 303 additions and 1 deletions
  1. 90 0
      app/controller/Novel.php
  2. 74 0
      app/model/Novel.php
  3. 30 0
      app/model/NovelData.php
  4. 3 1
      route/app.php
  5. 21 0
      view/novel/index.html
  6. 21 0
      view/novel/nlist.html
  7. 29 0
      view/novel/read.html
  8. 35 0
      view/novellayout.html

+ 90 - 0
app/controller/Novel.php

@@ -0,0 +1,90 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * +----------------------------------------------------------------------
+ * 文章控制制器
+ * @author huwhis@163.com
+ * @version   0.0.6
+ * +----------------------------------------------------------------------
+ */
+namespace app\controller;
+
+// 引入框架内置类
+use think\facade\View;
+use think\exception\HttpException;
+use think\App;
+
+use app\model\Novel as NovelModel;
+use app\model\NovelData;
+use app\utils\ParsedownUtils;
+
+/**
+ * 文章
+ */
+class Novel extends Base
+{
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $eng = View::engine();
+
+        $eng->layout('novellayout');
+    }
+
+    public function index()
+    {
+        $params = $this->app->request->param();
+
+        $list = NovelModel::queryPage($params);
+
+        View::assign('list', $list);
+
+        return View::fetch();
+    }
+
+    public function nlist($id = 0)
+    {        
+        $novel = NovelModel::find($id);
+
+        if (!$novel) {
+            throw new HttpException(404, '页面不存在');
+        }
+
+        // $params = $this->app->request->param();
+
+        $list = NovelData::where('n_id', $id)->field('id,n_id,title')->paginate(20);
+        
+        View::assign('list', $list);
+        
+        View::assign(['id'=>$id,'name'=>$novel->name]);
+
+        return View::fetch();
+    }
+
+    /**
+     * 阅读文章
+     */
+    public function read($nid = null,$id = null)
+    {
+        $data = NovelData::find($id);
+
+        if (!$data) {
+            throw new HttpException(404, '页面不存在');
+        }
+
+        $prev_next = NovelData::getNextPrev($id, $data->n_id);
+
+        View::assign('nid', $nid);
+        View::assign('data', $data);
+        View::assign('prev_next', $prev_next);
+
+        $this->seo['title'] = $data->title;
+        $this->seo['key'] = "ceshi";
+        $this->seo['des'] = "ceshi";
+        View::assign('seo',  $this->seo);
+
+        return View::fetch();
+    }
+}

+ 74 - 0
app/model/Novel.php

@@ -0,0 +1,74 @@
+<?php
+
+declare(strict_types=1);
+
+namespace app\model;
+
+use think\exception\HttpException;
+
+use app\model\Base;
+use think\facade\Config;
+
+class Novel extends Base
+{
+    protected $pk = 'id';
+
+    protected $schema = [
+        "id"        => "integer",
+        "name"      => "varchar",
+        "path"      => "varchar",
+        "size"      => "varchar",
+        "md5_file"   => "varchar",
+        "is_show"   => "int",
+        "is_import"   => "int",
+        "create_time" => "int",
+        "update_time" => "int"
+    ];
+
+    public static function queryPage($params)
+    {
+        $limit = empty($params['limit']) ? Config::get('app.page_size', 20) : (int)$params['limit'];
+        
+        $order = ['id desc'];
+
+        $list = self::where('is_show',1)
+            ->field('id,name,create_time')
+            ->order($order)->paginate(['list_rows'=>$limit, 'query' => $params]);
+        // halt(self::getLastSql());
+
+        return $list;
+    }
+
+    public static function getNextPrev($id, $cid = null)
+    {
+        $whereP = [];
+        $whereN = [];
+
+        // $whereP[] = ['status', '=', 1];
+        // $whereN[] = ['status', '=', 1];
+        
+        if ($cid) {
+            $whereP[] = ['cid', '=', $cid];
+            $whereN[] = ['cid', '=', $cid];
+        }
+
+        $whereP[] = ['id', ">", $id];
+        $whereN[] = ['id', "<", $id];
+
+        $data_P = self::where($whereP)->order("id desc")->limit(1)->find();
+        $data_N = self::where($whereN)->order("id desc")->limit(1)->find();
+
+        return ['prev' => $data_P, 'next' => $data_N];
+    }
+
+    public static function createTimeArchive($limit = 0)
+    {
+        if ($limit == 0) {
+            $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->select();
+        } else {
+            $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->limit($limit)->select();
+        }
+
+        return $timeList;
+    }
+}

+ 30 - 0
app/model/NovelData.php

@@ -0,0 +1,30 @@
+<?php
+namespace app\model;
+
+class NovelData extends \think\Model
+{
+    protected $pk = 'id';
+
+    public static function getNextPrev($id, $nid = null)
+    {
+        $whereP = [];
+        $whereN = [];
+
+        // $whereP[] = ['status', '=', 1];
+        // $whereN[] = ['status', '=', 1];
+        
+        if ($nid) {
+            $whereP[] = ['n_id', '=', $nid];
+            $whereN[] = ['n_id', '=', $nid];
+        }
+
+        $whereP[] = ['id', "<", $id];
+        $whereN[] = ['id', ">", $id];
+
+        $data_P = self::where($whereP)->order("id asc")->limit(1)->find();
+        $data_N = self::where($whereN)->order("id asc")->limit(1)->find();
+
+        return ['prev' => $data_P, 'next' => $data_N];
+    }
+
+}

+ 3 - 1
route/app.php

@@ -30,12 +30,14 @@ Route::get('/about', 'index/about')->append(['_aside' => true]);
 Route::get('/guest_book', 'index/guestBook');
 Route::post('/save_guest_book', 'index/saveGuestBook');
 
+Route::get('/time', 'article/time');
 Route::get('/search', 'article/search');
 Route::get('/tag/:name', 'article/tag');
 Route::get('/<year>-<month>', 'article/archive');
 Route::get('/:id', 'article/read');
 Route::post('/dolike', 'article/dolike');
-
+Route::get('/novel/:nid/:id', 'novel/read');
+Route::get('/novel/:id', 'novel/nlist');
 $categoryList = Cache::get('category_list');
 
 if (!$categoryList) {

+ 21 - 0
view/novel/index.html

@@ -0,0 +1,21 @@
+<div class="box">
+  <div class="place">
+  </div>
+  <div class="blank"></div>
+  <div class="blogs">
+    {foreach $list as $val}
+    <div class="bloglist">
+      <h2><a href="/novel/{$val.id}.html" title="{$val.name}">{$val.name}</a></h2>
+      <div class="bloginfo">
+      </div>
+    </div>
+    {/foreach}
+    {lt name="list->count()" value="$list->listRows()"}
+    <p style="text-align: center;">全都给你了, 没有更多啦(╥╯^╰╥).</p>
+    {/lt}
+    <div class="page">
+      {$list|raw}
+    </div>
+  </div>
+  {include file="aside"}
+</div>

+ 21 - 0
view/novel/nlist.html

@@ -0,0 +1,21 @@
+<article>
+  <div class="timebox">
+    <div class="bloglist">
+      <h2><a href="/novel/{$id}.html" title="{$name}">{$name}</a></h2>
+      <div class="bloginfo">
+        <ul>
+          <li class="author"><a href="/novel.html">返回首页</a></li>
+        </ul>
+      </div>
+    </div>
+    <ul>
+      {foreach $list as $val}
+      <li><span>{//$val.create_time|date="Y-m-d"}</span><i><a href="/novel/{$val.n_id}/{$val.id}.html"
+            title="{$val.title}">{$val.title}</a></i></li>
+      {/foreach}
+    </ul>
+  </div>
+  <div class="page">
+    {$list|raw}
+  </div>
+</article>

+ 29 - 0
view/novel/read.html

@@ -0,0 +1,29 @@
+<div class="box">
+  <div class="blank"></div>
+  <div class="infosbox">
+    <div class="newsview">
+      <h3 class="news_title">{$data.title}</h3>
+      <div class="bloginfo">
+        <ul>
+          <li class="author"><a href="/novel/{$data.n_id}.html"> 目录 </a></li>
+          <li class="timer"><a href="/novel.html"> 返回列表 </a></li>
+        </ul>
+      </div>
+      <div class="news_about"><strong>简介</strong>{//$data.summary}</div>
+      <div class="news_con" id="preview">
+        {$data.content|raw}
+      </div>
+    </div>
+    <div class="nextinfo">
+      {notempty name="prev_next.prev"}
+      <p>上一篇:<a href="/novel/{$data.n_id}/{$prev_next['prev']['id']}" title="{$prev_next.prev.title}">{$prev_next.prev.title}</a></p>
+      {/notempty}
+      <p><a href="/novel.html">返回目录</a></p>
+      {notempty name="prev_next.next"}
+      <p>下一篇:<a
+          href="/novel/{$data.n_id}//{$prev_next['next']['id']}"
+          title="{$prev_next.next.title}">{$prev_next.next.title}</a></p>
+      {/notempty}
+    </div>
+  </div>
+</div>

+ 35 - 0
view/novellayout.html

@@ -0,0 +1,35 @@
+<!doctype html>
+<html lang="zh-cn">
+
+<head>
+  <meta charset="utf-8">
+  <title>{$seo['title']}</title>
+  <meta name="keywords" content="{$seo['key']}" />
+  <meta name="description" content="{$seo['des']}" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <link href="/static/css/index.css" rel="stylesheet">
+  <script type="text/javascript" src="/static/plugins/jquery/1.9.1/jquery.min.js"></script>
+</head>
+
+<body>
+  <header>
+    <div class="logo"><a href="{:url('/index')}">huwhois的自留地</a></div>
+    <nav>
+      <ul id="starlist">
+        <li><a href="{:url('/novel')}">首页</a></li>
+      </ul>
+    </nav>
+  </header>
+
+  {__CONTENT__}
+
+  <div class="blank"></div>
+
+  <footer>
+    <p>Power by <a href="mailto:{: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>