DEV: Админ-панель (каталог, 2 часть)

This commit is contained in:
Evg 2023-06-16 07:08:25 +03:00
parent 571acfcbe5
commit 8b697e6ea9
6 changed files with 58 additions and 14 deletions

View file

@ -3,8 +3,9 @@
namespace App\Controllers\Item;
use App\Controllers\Controller;
use Hleb\Constructor\Handlers\Request;
use App\Models\Item\{WebModel, UserAreaModel};
use Meta;
use Meta, Msg;
class AdminController extends Controller
{
@ -53,6 +54,8 @@ class AdminController extends Controller
public function status()
{
Request::getResources()->addBottomScript('/assets/js/catalog.js');
return $this->render(
'/item/admin/status',
[
@ -65,13 +68,26 @@ class AdminController extends Controller
public static function httpCode($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
stream_context_set_default([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$http_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$headers = get_headers($url);
return $http_code;
return (empty($headers[0])) ? 404 : substr($headers[0], 9, 3);
}
// Once a month
public static function updateStatus()
{
$items = WebModel::getForStatus();
foreach ($items as $row) {
WebModel::statusUpdate($row['item_id'], self::httpCode($row['item_url']));
}
Msg::add(__('admin.completed'), 'success');
}
}

View file

@ -373,4 +373,24 @@ class WebModel extends \Hleb\Scheme\App\Models\MainModel
return DB::run($sql, ['limit' => $limit])->fetchAll();
}
public static function getForStatus()
{
$url = DB::run("SELECT status_item_id FROM items_status WHERE status_date > CURDATE()-INTERVAL 1 WEEK")->fetchAll();
$result = [];
foreach ($url as $ind => $row) {
$result[$ind] = $row['status_item_id'];
}
$sql = "SELECT item_id, item_url FROM items WHERE item_is_deleted = 0 AND item_id NOT IN(" . implode(',', $result ?? []) . ")";
return DB::run($sql)->fetchAll();
}
public static function statusUpdate($item_id, $code)
{
return DB::run("INSERT INTO items_status(status_item_id,status_response) VALUES(:item_id,:code)", ['item_id' => $item_id, 'code' => $code]);
}
}

View file

@ -1,5 +1,5 @@
const favicon=queryAll(".add-favicon"),screenshot=queryAll(".add-screenshot");favicon.forEach(el=>el.addEventListener("click",function(e){makeRequest("/web/favicon/add",options={body:"id="+el.dataset.id})}));screenshot.forEach(el=>el.addEventListener("click",function(e){makeRequest("/web/screenshot/add",options={body:"id="+el.dataset.id})}));isIdEmpty('find-url').onclick=function(){getById('find-url').addEventListener('keydown',function(){fetchSearchUrl()})}
function fetchSearchUrl(){let url=getById("find-url").value;if(url.length<5)return;fetch("/search/web/url",{method:"POST",headers:{'Content-Type':'application/x-www-form-urlencoded'},body:"url="+url+"&_token="+token,}).then(response=>{return response.text()}).then(text=>{let obj=JSON.parse(text);let html='<div class="flex">';for(let key in obj){if(obj[key].item_id){html+='<a class="block green text-sm mt5 mb5" href="/web/website/'+obj[key].item_id+'">'+obj[key].item_url+'</a>'}
const favicon=queryAll(".add-favicon"),sturl=queryAll(".status"),screenshot=queryAll(".add-screenshot");favicon.forEach(el=>el.addEventListener("click",function(e){makeRequest("/web/favicon/add",options={body:"id="+el.dataset.id})}));screenshot.forEach(el=>el.addEventListener("click",function(e){makeRequest("/web/screenshot/add",options={body:"id="+el.dataset.id})}));isIdEmpty('find-url').onclick=function(){getById('find-url').addEventListener('keydown',function(){fetchSearchUrl()})}
sturl.forEach(el=>el.addEventListener("click",function(e){makeRequest("/web/status/update")}));function fetchSearchUrl(){let url=getById("find-url").value;if(url.length<5)return;fetch("/search/web/url",{method:"POST",headers:{'Content-Type':'application/x-www-form-urlencoded'},body:"url="+url+"&_token="+token,}).then(response=>{return response.text()}).then(text=>{let obj=JSON.parse(text);let html='<div class="flex">';for(let key in obj){if(obj[key].item_id){html+='<a class="block green text-sm mt5 mb5" href="/web/website/'+obj[key].item_id+'">'+obj[key].item_url+'</a>'}
html+='</div>'}
if(!Object.keys(obj).length==0){let items=getById("search_url");items.classList.add("block");items.innerHTML=html}
let menu=document.querySelector('.none.block');if(menu){document.onclick=function(e){if(event.target.className!='.none.block'){let items=getById("search_url");items.classList.remove("block")}}}})}

View file

@ -6,18 +6,18 @@
<div class="flex justify-between mt10 mb20">
<?= insert('/content/item/admin/menu'); ?>
<a class="btn btn-outline-primary" href="#">
<div class="status btn btn-outline-primary">
<svg class="icons text-xl">
<use xlink:href="/assets/svg/icons.svg#chart"></use>
</svg>
<?= __('web.refresh'); ?>
</a>
</div>
</div>
<div class="mb20 text-sm">
<a class="ml10 gray-600 <?php if ($day == 1) : ?> active<?php endif; ?>" href="#">404</a>
<a class="mr15 ml15 gray-600<?php if ($day == 3) : ?> active<?php endif; ?>" href="#">403</a>
<a class="gray-600<?php if ($day == 'all' || !$day) : ?> active<?php endif; ?>" href="#">@</a>
<a class="ml10 gray-600 <?php if (2 == 1) : ?> active<?php endif; ?>" href="#">404</a>
<a class="mr15 ml15 gray-600<?php if (2 == 3) : ?> active<?php endif; ?>" href="#">403</a>
<a class="gray-600<?php if (1 == 1) : ?> active<?php endif; ?>" href="#">@</a>
</div>
<?php foreach ($data['status'] as $st) : ?>

View file

@ -1,4 +1,5 @@
const favicon = queryAll(".add-favicon"),
sturl = queryAll(".status"),
screenshot = queryAll(".add-screenshot");
// Write down a Favicon
@ -18,6 +19,12 @@ isIdEmpty('find-url').onclick = function () {
});
}
// URL Status Update
sturl.forEach(el => el.addEventListener("click", function (e) {
makeRequest("/web/status/update");
}));
function fetchSearchUrl() {
let url = getById("find-url").value;
if (url.length < 5) return;

View file

@ -13,6 +13,7 @@ Route::endGroup();
Route::before('Designator', [UserData::USER_FIRST_LEVEL, '>='])->getGroup();
Route::post('/web/favicon/add')->controller('Item\ImgController@favicon');
Route::post('/web/screenshot/add')->controller('Item\ImgController@screenshot');
Route::post('/web/status/update')->controller('Item\AdminController@updateStatus');
Route::get('/web/bookmarks')->controller('Item\UserAreaController@bookmarks')->name('web.bookmarks');
Route::get('/web/my')->controller('Item\UserAreaController')->name('web.user.sites');
Route::endGroup();