Index.php 2.0 KB
<?php

namespace App\Http\Controllers\V2;

use App\Fun;
use Illuminate\Support\Facades\View;

/**
 * 第二版的控制器
 * @author:dc
 * @time 2022/12/28 9:26
 * Class Index
 * @package App\Http\Controllers\V2
 */
class Index extends Base
{


    /**
     * 首页
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author:dc
     * @time 2022/11/16 9:06
     */
    public function home()
    {

        return view('v2/home');
    }


    /**
     * 博客
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author:dc
     * @time 2022/12/28 10:13
     */
    public function blog()
    {

        $lists  =   $this->getData('blog');
        if(!empty($lists['links'])){
            foreach ($lists['links'] as &$link){
                preg_match("/page=(\d+)/i",$link['url'],$p);
                $link['page'] = $p[1]??0;
            }
        }
        return view('v2/blog/lists',[
            'lists' =>  $lists
        ]);
    }

    /**
     * 博客详情
     * @param $id
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author:dc
     * @time 2022/12/28 10:13
     */
    public function blog_info($id){

        $data  =   $this->getData('blog/'.$id,['prev'=>1,'next'=>1,'correlation'=>1]);

        if(!$data){
            Fun::abort();
        }

        return view('v2/blog/info',[
            'data' =>  $data
        ]);
    }



    /**
     * 单页
     * @param $key
     * @author:dc
     * @time 2022/12/28 16:59
     */
    public function page($key){
        $page = $this->getData('page',['urlkey'=>$key]);

        if(!$page){
            Fun::abort();
        }

        $page['show_html'] = str_replace('<title></title>','<title>'.$page['title'].'</title>',$page['show_html']);

        return response($page['show_html'],200,['Content-Type'=>'text/html;charset=urt-8;']);
    }





}