middleware('throttle:3,1')->only('mix'); } else { // $this->middleware('throttle:15,1'); } } public function client($sType = false) { $r = $this->view('client', $sType); return $r; } public function fn() { $r = $this->view('freenode'); return $r; } public function mix() { $r = $this->view('mix'); return $r; } public function view($sType = false, $sTypeSub = false) { $oAntiXss = new AntiXSS(); $sType = $oAntiXss->xss_clean($sType); $sTypeSub = $oAntiXss->xss_clean($sTypeSub); $iPageNo = $oAntiXss->xss_clean(request('pageNo')); $bIsAjax = $oAntiXss->xss_clean(request('isAjax')); $iTagId = $oAntiXss->xss_clean(request('tag')); $sSearch = $oAntiXss->xss_clean(request('search')); $iPageNo = $iPageNo ? $iPageNo : 1; $bIsAjax = $bIsAjax ? $bIsAjax : false; $iTagId = $iTagId ? $iTagId : 0; $iLimit = 10; $iStart = $iLimit * $iPageNo - $iLimit; $oQuery = ArticleList::query(); $sMenu = "main"; if (!$sSearch && !$iTagId) { if ($sType == 'client') { $sMenu = "client"; if ($sTypeSub) { $oQuery->where("type", $sTypeSub); } else { $oQuery->whereIn("type", ['ios','mac','win','linux','android']); } } else if ($sType == "freenode") { $sMenu = "freenode"; $oQuery->where("type", "=", "node"); } } if ($iTagId) { $oQuery->where('tags', 'like', '%['.$iTagId.']%'); } if ($sSearch) { $oQuery->where('title', 'like', '%'.$sSearch.'%'); } // dd($oQuery->toSql(), $oQuery->getBindings()); $aArticleList = $oQuery->orderBy('code', 'desc')->skip($iStart)->take($iLimit)->get()->toArray(); foreach ($aArticleList as &$row) { $sTimeLost = Time::Lost(time(), strtotime($row['created_at'])); $row['time_lost'] = $sTimeLost; $row['created_at'] = date('n月j日', strtotime($row['created_at'])); if ($row['type'] == 'node') { $row['typeStr'] = '免费节点'; $row['pathBase'] = '/fn/'; } else if (in_array($row['type'], ['ios','mac','win','linux','android'])) { $row['typeStr'] = $row['type'].'客户端'; $row['pathBase'] = '/client/'; } } $aTagMap = Tags::all()->toArray(); if ($bIsAjax) { echo json_encode($aArticleList);exit; } else { // 第二页之后是ajax if ($iPageNo > 1) { $sViewPath = "article/listAjax"; } else { $sViewPath = 'article/list'; } return view($sViewPath, [ 'sAppName' => env('APP_NAME'), 'aList' => $aArticleList, 'aTag' => @$aTagMap[$iTagId-1], 'search' => $sSearch, 'sMenu' => $sMenu, 'sType' => $sType, 'sTypeSub' => $sTypeSub, // 'sSiteCode' => env('site_code'), ]); } } }