| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\controller;
- use app\model\dynasty\DynastyAuthor;
- use app\model\dynasty\DynastyCategory;
- use QL\QueryList;
- use support\Request;
- class IndexController
- {
- public function index(Request $request)
- {
- $ql = QueryList::getInstance()->get("https://www.gushiji.cc/gushi/ed7378.html")->rules([
- "data" => [".shicicontent","text"],
- "tags" => [".relatedCategory>ul>li>a","texts"],
- "notes" => [".shici-content","texts"],
- ])->query()->getData(function ($item,$key){
- foreach ($item['notes'] as $k=>$v){
- if ($k == 0) {
- $note = splitTransAndNote($v);
- } else {
- $note = $v;
- }
- $item['notes'][$k] = $note;
- }
- return $item;
- });
- $resp = $ql->all();
- return json($resp);
- }
- protected function getPoem()
- {
- $ql = QueryList::getInstance()->get("https://www.gushiji.cc/dianji/")->rules([
- // "name" => ['.gushi-info>h3','texts'],
- // "link" => ['.gushi-info>h3>a','attrs(href)'],
- "name" => ['.gushi-info>.cipai>ul>li','texts'],
- "link" => ['.gushi-info>.cipai>ul>li>a','attrs(href)'],
- ])->query()->getData(function ($item,$key){
- foreach ($item['link'] as $k=>$v){
- $link = explode("/",$v);
- $item['link'][$k] = $link[2]??'';
- }
- return $item;
- });
- $resp = $ql->all();
- foreach ($resp['name'] as $k=>$v){
- $cate = (new DynastyAuthor)->where("pinyin",$resp['link'][$k])->findOrEmpty();
- if ($cate->isEmpty()){
- $cate->insertGetId([
- "pinyin" => $resp['link'][$k],
- "name" => $v,
- "type" => 2,
- "initial" => strtoupper(substr($resp['link'][$k], 0, 1)),
- ]);
- } else {
- $cate->insertGetId([
- "pinyin" => $resp['link'][$k],
- "name" => $v,
- "type" => 2,
- "initial" => strtoupper(substr($resp['link'][$k], 0, 1)),
- ]);
- }
- }
- return json($resp);
- }
- protected function getAuthor()
- {
- $ql = QueryList::getInstance()->get("https://www.gushiji.cc/shiren/")->rules([
- "name" => ['.simple-people>li','texts'],
- "link" => ['.simple-people>li>a','attrs(href)'],
- "avatar" => ['.simple-people>li>a>img','attrs(src)'],
- "page" => ['#pagenum>li.info','text'],
- ])->query()->getData(function ($item,$key){
- foreach ($item['avatar'] as $k=>$v){
- if (empty($v)){
- $v = "/skin/images/nopicture.jpg";
- }
- $item['avatar'][$k] = "https://www.gushiji.cc".$v;
- }
- foreach ($item['link'] as $k=>$v){
- $link = explode("/",$v);
- $item['link'][$k] = $link[2]??'';
- }
- $poem = [];
- foreach ($item['name'] as $k=>$v){
- preg_match('/([^()()]+)[((](\d+)[))]/u', $v, $match);
- $item['name'][$k] = $match[1]??'';
- $poem[$k] = $match[2]??0;
- }
- preg_match_all('/\d+/', $item['page'], $matches);
- $item['page'] = $matches[0][0] ?? 0;
- $item['total'] = $matches[0][1] ?? 0;
- $item['poem'] = $poem;
- return $item;
- });
- return $ql->all();
- }
- public function view(Request $request)
- {
- return view('index/view', ['name' => 'webman']);
- }
- public function json(Request $request)
- {
- return json(['code' => 0, 'msg' => 'ok']);
- }
- }
|