Merge branch 'dev'

This commit is contained in:
Knah Tsaeb 2024-03-22 13:49:01 +01:00
commit 06656d4142
11 changed files with 118 additions and 25 deletions

View file

@ -169,6 +169,7 @@ See LICENSE file for more detail.
- [W3c](https://www.w3schools.com/w3css/) for w3.css - [W3c](https://www.w3schools.com/w3css/) for w3.css
- [Fork Awesome](https://forkaweso.me/Fork-Awesome/) for icon - [Fork Awesome](https://forkaweso.me/Fork-Awesome/) for icon
- [Iconify.design](https://icon-sets.iconify.design/iconamoon/star-off/) for default favicon
- [embed/embed](https://github.com/oscarotero/Embed) for embed (fav and og) - [embed/embed](https://github.com/oscarotero/Embed) for embed (fav and og)
- [hassankhan/config](https://github.com/hassankhan/config) for config (config mananger) - [hassankhan/config](https://github.com/hassankhan/config) for config (config mananger)
- [chrome-php/chrome](https://github.com/chrome-php/chrome) for chrome-php (wrapper for chrome dev-tool) - [chrome-php/chrome](https://github.com/chrome-php/chrome) for chrome-php (wrapper for chrome dev-tool)

View file

@ -7,6 +7,7 @@ if (session_status() === PHP_SESSION_NONE) {
} }
use App\DataBase\DataBase; use App\DataBase\DataBase;
use App\Utils\DeleteGen;
use App\Utils\Page; use App\Utils\Page;
use App\Utils\ShowImg; use App\Utils\ShowImg;
use Noodlehaus\Config; use Noodlehaus\Config;
@ -22,6 +23,7 @@ class Backend {
private $conf; private $conf;
private $title = 'Settings'; private $title = 'Settings';
private $passwordRequired = false; private $passwordRequired = false;
private $search = null;
/** /**
* Handles the index action for the controller. * Handles the index action for the controller.
@ -65,6 +67,13 @@ class Backend {
exit(); exit();
} }
if (!empty($params->deleteGen)) {
$deleteGen = new DeleteGen();
$deleteGen->deleteGen($params->deleteGen);
$reset = new DataBase();
$reset->reset($params->deleteGen);
}
$this->conf = $conf; $this->conf = $conf;
$this->params = $params; $this->params = $params;
@ -107,6 +116,15 @@ class Backend {
* @return void * @return void
*/ */
private function showInfos() { private function showInfos() {
if (!empty($this->params->search)) {
$search = htmlspecialchars(trim($this->params->search));
if (!empty($search)) {
$this->search = $search;
} else {
$this->search = null;
}
}
if (!empty($this->params->start)) { if (!empty($this->params->start)) {
$this->start = $this->params->start; $this->start = $this->params->start;
} }
@ -116,21 +134,23 @@ class Backend {
} }
$conx = new DataBase(); $conx = new DataBase();
$genList = $conx->getList($this->start, $this->end); $genList = $conx->getList($this->start, $this->end, $this->search);
$total = $conx->getTotal(); $total = $conx->getTotal();
$inError = $conx->getInError(); $inError = $conx->getInError();
$inQueue = $this->getInQueue(); $inQueue = $this->getInQueue();
$start = $this->start; $start = $this->start;
$max = $this->max; $max = $this->max;
$next = $start + $max; $next = $start + $max;
$previous = $start - ($max); $previous = $start - ($max);
$search = $this->search;
if (count($genList) < $this->max) { if (count($genList) < $this->max) {
$next = $start; $next = $start;
} }
if ($previous < 0) { if ($previous < 0) {
$previous = 0; $previous = null;
} }
require __DIR__ . '/../../tpl/infos.php'; require __DIR__ . '/../../tpl/infos.php';

View file

@ -3,6 +3,6 @@ namespace App\Controllers;
class GenHmac { class GenHmac {
function index($params, $conf) { function index($params, $conf) {
echo hash_hmac('sha1', $params->url, $conf['key']); echo hash_hmac('sha1', $params->url, $conf->key);
} }
} }

View file

@ -192,6 +192,38 @@ class DataBase {
]); ]);
} }
/**
* Reset .
*
* This method prepares an SQL UPDATE statement using the provided parameters, and
* executes it to update a record in the "soshot" table in the database.
*
* @param string $update The value to update in the type column of the record.
*
* @return void
*/
public function reset(string $id) {
$resetParam = [];
$updateParams = $this->params;
unset($updateParams['id'], $updateParams['url'], $updateParams['created']);
foreach ($updateParams as $key => $value) {
$resetParam[] = $key . ' = null';
}
$strUpdateParam = implode(',', $resetParam);
$stmt = $this->db->prepare("UPDATE soshot
SET $strUpdateParam
WHERE id=:id;");
$result = $stmt->execute([
':id' => $id
]);
}
/** /**
* Checks if a record with the given ID exists in the database. * Checks if a record with the given ID exists in the database.
* *
@ -264,8 +296,12 @@ class DataBase {
* *
* @return array An array of objects representing the records in the "soshot" table. * @return array An array of objects representing the records in the "soshot" table.
*/ */
public function getList(int $start, int $end) { public function getList(int $start, int $end, string $search = null) {
$stmt = $this->db->prepare("SELECT * FROM soshot ORDER BY created DESC limit :start, :end;"); if ($search != null) {
$stmt = $this->db->prepare("SELECT * FROM soshot WHERE url like '%$search%' ORDER BY created DESC limit :start, :end;");
} else {
$stmt = $this->db->prepare("SELECT * FROM soshot ORDER BY created DESC limit :start, :end;");
}
$stmt->execute(array(':start' => $start, ':end' => $end)); $stmt->execute(array(':start' => $start, ':end' => $end));
$result = $stmt->fetchAll(PDO::FETCH_OBJ); $result = $stmt->fetchAll(PDO::FETCH_OBJ);
return $result; return $result;

View file

@ -33,18 +33,18 @@ class GetFav extends GetThumb {
if (!is_null($info->favicon)) { if (!is_null($info->favicon)) {
if (!$favicon = @file_get_contents($info->favicon)) { if (!$favicon = @file_get_contents($info->favicon)) {
copy(__DIR__ . '/../../src/images/error_fav.' . $this->fileFormat, $this->demande->requestImg); copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
$this->db->addUpdate(2, $this->type); $this->db->addUpdate(2, $this->type);
return true; return true;
} }
} elseif (!is_null($info->icon)) { } elseif (!is_null($info->icon)) {
if (!$favicon = @file_get_contents($info->icon)) { if (!$favicon = @file_get_contents($info->icon)) {
copy(__DIR__ . '/../../src/images/error_fav.' . $this->fileFormat, $this->demande->requestImg); copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
$this->db->addUpdate(2, $this->type); $this->db->addUpdate(2, $this->type);
return true; return true;
} }
} else { } else {
copy(__DIR__ . '/../../src/images/error_fav.' . $this->fileFormat, $this->demande->requestImg); copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
$this->db->addUpdate(2, $this->type); $this->db->addUpdate(2, $this->type);
return true; return true;
} }
@ -95,7 +95,6 @@ class GetFav extends GetThumb {
if (!file_exists($this->requestImg) && $this->type === 'fav') { if (!file_exists($this->requestImg) && $this->type === 'fav') {
$this->makeFavicon(); $this->makeFavicon();
} }
//echo '<img src="data:image/png;base64,'.base64_encode(file_get_contents($this->requestImg)).'">';
header("Content-type: image/$this->fileFormat"); header("Content-type: image/$this->fileFormat");
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
echo file_get_contents($this->requestImg); echo file_get_contents($this->requestImg);

18
app/Utils/DeleteGen.php Normal file
View file

@ -0,0 +1,18 @@
<?php
namespace App\Utils;
class DeleteGen {
function deleteGen(string $hashFile) {
$dir = __DIR__ . '/../../cache/img/' . substr($hashFile, 0, 4) . '/';
if (is_dir($dir)) {
$listFile = glob($dir . '*');
foreach ($listFile as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
}
}

View file

@ -17,7 +17,7 @@ class ShowImg {
echo file_get_contents($img); echo file_get_contents($img);
} else { } else {
// todo not gen // todo not gen
echo file_get_contents(__DIR__ . '/../../src/images/error_thumb.png'); echo file_get_contents(__DIR__ . '/../../src/images/hd_generation_in_progress.jpg');
} }
exit(); exit();
} }

View file

@ -99,6 +99,10 @@ form label {
width: 48%; width: 48%;
} }
.zoom {
cursor: zoom-in;
}
@media (max-width:768px) { @media (max-width:768px) {
#mySidebar { #mySidebar {

View file

@ -36,7 +36,7 @@ $router = new Router();
$router->addRoute(['/', '/index.php', '/index'], 'App\Controllers\Home', 'GET'); $router->addRoute(['/', '/index.php', '/index'], 'App\Controllers\Home', 'GET');
$router->addRoute('/api', 'App\Controllers\Result', 'GET'); $router->addRoute('/api', 'App\Controllers\Result', 'GET');
$router->addRoute('/hmac', 'App\Controllers\GenHmac', 'GET'); $router->addRoute('/hmac', 'App\Controllers\GenHmac', 'GET');
//$router->addRoute('/debug', 'App\Bin\ThumbShoter', 'GET'); $router->addRoute('/debug', 'App\Bin\ThumbShoter', 'GET');
$router->addRoute('/backend', 'App\Controllers\Backend', 'GET'); $router->addRoute('/backend', 'App\Controllers\Backend', 'GET');
$router->addRoute('/logout', 'App\Controllers\Logout', 'GET'); $router->addRoute('/logout', 'App\Controllers\Logout', 'GET');

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -3,7 +3,6 @@
use App\Utils\ConvertStatus; use App\Utils\ConvertStatus;
use App\Utils\Domains; use App\Utils\Domains;
//require_once 'nav.php';
?> ?>
<div class="w3-row soshot-main w3-margin-bottom"> <div class="w3-row soshot-main w3-margin-bottom">
<div class="w3-container"> <div class="w3-container">
@ -15,6 +14,11 @@ use App\Utils\Domains;
<li>Error : <?= $inError; ?></li> <li>Error : <?= $inError; ?></li>
</ul> </ul>
<form>
<input type="text" name="search" value="<?= $search; ?>">
<input type="submit" value="Rechercher">
</form>
<table class="w3-table-all w3-hoverable"> <table class="w3-table-all w3-hoverable">
<thead> <thead>
<tr> <tr>
@ -33,7 +37,14 @@ use App\Utils\Domains;
<tbody> <tbody>
<?php foreach ($genList as $value) : ?> <?php foreach ($genList as $value) : ?>
<tr> <tr>
<td><a href="#" class="linkDetail" data-hmac="<?= $value->id; ?>" data-href="<?= $value->url; ?>"><?= Domains::getDomain($value->url); ?></a></td> <td>
<span class="w3-left ">
<a href="#" class="linkDetail" data-hmac="<?= $value->id; ?>" data-href="<?= $value->url; ?>"><?= Domains::getDomain($value->url); ?></a>
</span>
<span class="w3-right" style="width:40px">
<a href="?page=infos&deleteGen=<?= $value->id; ?>"><i class="fa fa-trash-o w3-text-red" aria-hidden="true"></i></a>
</span>
</td>
<td><?= $value->created; ?></td> <td><?= $value->created; ?></td>
<td><?= ConvertStatus::convertToIcon($value->complete); ?></td> <td><?= ConvertStatus::convertToIcon($value->complete); ?></td>
<td><?= ConvertStatus::convertToIcon($value->full); ?></td> <td><?= ConvertStatus::convertToIcon($value->full); ?></td>
@ -50,8 +61,12 @@ use App\Utils\Domains;
<div class="w3-center w3-margin-top"> <div class="w3-center w3-margin-top">
<div class="w3-bar"> <div class="w3-bar">
<a href="?page=infos&start=<?= $previous; ?>" class="w3-teal w3-button">&laquo; Previous</a> <?php if ($start > 0) : ?>
<a href="?page=infos&start=<?= $next; ?>" class="w3-teal w3-button">Next &raquo; </a> <a href="?page=infos&start=<?= $previous; ?>" class="w3-teal w3-button">&laquo; Previous</a>
<?php endif; ?>
<?php if ($next != $start) :; ?>
<a href="?page=infos&start=<?= $next; ?>" class="w3-teal w3-button">Next &raquo; </a>
<?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
@ -59,17 +74,17 @@ use App\Utils\Domains;
<div id="detail" class="w3-modal"> <div id="detail" class="w3-modal">
<div class="w3-modal-content w3-animate-opacity"> <div class="w3-modal-content w3-animate-opacity">
<div class="w3-container"> <div class="w3-container">
<span onclick="document.getElementById('detail').style.display='none'" class="w3-button w3-display-topright">&times;</span> <span onclick="document.getElementById('detail').style.display='none'" class="w3-button w3-display-topright w3-xxlarge">&times;</span>
<p> <p>
<img src="" id="fav" height="32px"> <img src="" id="fav" height="32px">
<a href="" id="titlePreview" target="_blanck"></a> <a href="" id="titlePreview" target="_blanck"></a>
</p> </p>
<img class="w3-border w3c-margin" src="" id="complete" width="45%"> <img class="w3-border w3c-margin zoom" src="" id="complete" width="45%" onclick="fullNewtab(this.src);">
<img class="w3-border w3c-margin" src="" id="full" width="35%"> <img class="w3-border w3c-margin zoom" src="" id="full" width="35%" onclick="fullNewtab(this.src);">
<img class="w3-border w3c-margin" src="" id="hd" width="30%"> <img class="w3-border w3c-margin zoom" src="" id="hd" width="30%" onclick="fullNewtab(this.src);">
<img class="w3-border w3c-margin" src="" id="og" width="25%"> <img class="w3-border w3c-margin zoom" src="" id="og" width="25%" onclick="fullNewtab(this.src);">
<img class="w3-border w3c-margin" src="" id="nhd" width="20%"> <img class="w3-border w3c-margin zoom" src="" id="nhd" width="20%" onclick="fullNewtab(this.src);">
<img class="w3-border w3c-margin" src="" id="thumb" width="15%"> <img class="w3-border w3c-margin zoom" src="" id="thumb" width="15%" onclick="fullNewtab(this.src);">
</div> </div>
</div> </div>
</div> </div>
@ -127,8 +142,8 @@ use App\Utils\Domains;
}); });
}); });
function showDetail(el) { function fullNewtab(imgSrc) {
window.open(imgSrc);
} }
// Get the modal // Get the modal