update photoext

This commit is contained in:
themohooks 2024-07-21 01:29:59 +03:00
parent b6c6580b96
commit d69509ad83
2 changed files with 45 additions and 105 deletions

View file

@ -1,11 +1,14 @@
<?php <?php
namespace App\Controllers\Api\Images; namespace App\Controllers\Api\Images;
use \App\Services\{Auth, DB}; use \App\Services\{Auth, DB};
class Stats { class Stats
{
public function __construct() { public function __construct()
{
$imageWidth = 1000; $imageWidth = 1000;
$imageHeight = 700; $imageHeight = 700;
$image = imagecreatetruecolor($imageWidth, $imageHeight); $image = imagecreatetruecolor($imageWidth, $imageHeight);
@ -17,51 +20,47 @@ class Stats {
imagefill($image, 0, 0, $backgroundColor); imagefill($image, 0, 0, $backgroundColor);
$data = [ $results = DB::query("SELECT DATE_FORMAT(FROM_UNIXTIME(time), '%d.%m.%Y') AS date, COUNT(*) AS views FROM photos_views WHERE photo_id = :photo_id AND time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY)) GROUP BY DATE_FORMAT(FROM_UNIXTIME(time), '%d.%m.%Y') ORDER BY date ASC;", array(':photo_id' => $_GET['id']));
"22.06.2024" => 0,
"23.06.2024" => 0,
"24.06.2024" => 0, $data = [];
"25.06.2024" => 0, $period = new \DatePeriod(
"26.06.2024" => 0, new \DateTime('-30 days'),
"27.06.2024" => 0, new \DateInterval('P1D'),
"28.06.2024" => 0, new \DateTime('tomorrow')
"29.06.2024" => 0, );
"30.06.2024" => 0,
"01.07.2024" => 0, foreach ($period as $date) {
"02.07.2024" => 0, $formattedDate = $date->format('d.m.Y');
"03.07.2024" => 0, $data[$formattedDate] = 0;
"04.07.2024" => 0, }
"05.07.2024" => 0,
"06.07.2024" => 0, foreach ($results as $result) {
"07.07.2024" => 0, $date = $result['date'];
"08.07.2024" => 0, if (isset($data[$date])) {
"09.07.2024" => 0, $data[$date] = $result['views'];
"10.07.2024" => 0, }
"11.07.2024" => 0, }
"12.07.2024" => 0,
"13.07.2024" => 0,
"14.07.2024" => 0,
"15.07.2024" => 292,
"16.07.2024" => 292,
"17.07.2024" => 154,
"18.07.2024" => 892,
"19.07.2024" => 606,
"20.07.2024" => 0010,
"21.07.2024" => 0
];
$barWidth = 20; $barWidth = 20;
$barSpacing = 10; $barSpacing = 10;
$maxBarHeight = $imageHeight - 110; $maxBarHeight = $imageHeight - 110;
$maxValue = max($data); $maxValue = max($data);
if ($maxValue === 0) {
$maxValue = 1;
}
$x = 50; $x = 50;
foreach ($data as $date => $value) { foreach ($data as $date => $value) {
$barHeight = ($value / $maxValue) * $maxBarHeight; $barHeight = ($value / $maxValue) * $maxBarHeight;
$y = $imageHeight - 70 - $barHeight; $y = $imageHeight - 70 - $barHeight;
imagefilledrectangle($image, $x, $y, $x + $barWidth, $imageHeight - 70, $barColor); imagefilledrectangle($image, $x, $y, $x + $barWidth, $imageHeight - 70, $barColor);
imagettftext($image, 13, 0, $x + 2, $y - 10, $textColor, $_SERVER['DOCUMENT_ROOT'].'/static/TTCommons-Medium.ttf', $value); imagettftext($image, 13, 0, $x + 2, $y - 10, $textColor, $_SERVER['DOCUMENT_ROOT'] . '/static/TTCommons-Medium.ttf', $value);
imagettftext($image, 10, 90, $x + 15, $imageHeight - 0, $textColor, $_SERVER['DOCUMENT_ROOT'].'/static/TTCommons-Medium.ttf', $date); // Rotated date imagettftext($image, 10, 90, $x + 15, $imageHeight - 0, $textColor, $_SERVER['DOCUMENT_ROOT'] . '/static/TTCommons-Medium.ttf', $date); // Rotated date
$x += $barWidth + $barSpacing; $x += $barWidth + $barSpacing;
} }
@ -71,7 +70,5 @@ class Stats {
header('Content-Type: image/png'); header('Content-Type: image/png');
imagepng($image); imagepng($image);
imagedestroy($image); imagedestroy($image);
} }
} }
?>

View file

@ -61,70 +61,13 @@ $photo = new \App\Models\Photo($_GET['id']);
</center> </center>
</td> </td>
</tr> </tr>
<tr> <tr>
<td id="adframe"> <?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?>
<!-- Yandex.RTB R-A-115118-1 --> </tr>
<div id="yandex_rtb_R-A-115118-1"></div>
<script>
window.yaContextCb.push(() => {
Ya.Context.AdvManager.render({
renderTo: 'yandex_rtb_R-A-115118-1',
blockId: 'R-A-115118-1'
})
})
</script>
</td>
</tr>
<tr>
<td class="footer"><b><a href="/">Главная</a> &nbsp; &nbsp; <a href="/lk/">Личный кабинет</a> &nbsp; &nbsp; <a href="https://forum.transphoto.org">Форум</a> &nbsp; &nbsp; <a href="/rules/">Правила</a> &nbsp; &nbsp; <a href="/admin/">Редколлегия</a></b><br>
<a href="/set.php?dark=0" style="display:inline-block; padding:1px 10px; margin-top:5px; background-color:#ddd; color:#333">Светлая тема</a>
<div class="sitecopy">&copy; Администрация ТрансФото и авторы материалов, 2002—2024<br>Использование фотографий и иных материалов, опубликованных на сайте, допускается только с разрешения их авторов.</div>
<div style="margin:15px 0">
<noindex>
<!-- Yandex.Metrika informer -->
<a href="https://metrika.yandex.ru/stat/?id=73971775&amp;from=informer" target="_blank" rel="nofollow"><img src="https://informer.yandex.ru/informer/73971775/3_0_DDDDDDFF_DDDDDDFF_0_pageviews" style="width:88px; height:31px; border:0;" alt="Яндекс.Метрика" title="Яндекс.Метрика: данные за сегодня (просмотры, визиты и уникальные посетители)" class="ym-advanced-informer" data-cid="73971775" data-lang="ru" /></a>
<!-- /Yandex.Metrika informer -->
</noindex>
</div>
</td>
</tr>
</table> </table>
<script>
(function() {
function c() {
var b = a.contentDocument || a.contentWindow.document;
if (b) {
var d = b.createElement('script');
d.innerHTML = "window.__CF$cv$params={r:'8a660706db3f005f',t:'MTcyMTUxMDc2NC4wMDAwMDA='};var a=document.createElement('script');a.nonce='';a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";
b.getElementsByTagName('head')[0].appendChild(d)
}
}
if (document.body) {
var a = document.createElement('iframe');
a.height = 1;
a.width = 1;
a.style.position = 'absolute';
a.style.top = 0;
a.style.left = 0;
a.style.border = 'none';
a.style.visibility = 'hidden';
document.body.appendChild(a);
if ('loading' !== document.readyState) c();
else if (window.addEventListener) document.addEventListener('DOMContentLoaded', c);
else {
var e = document.onreadystatechange || function() {};
document.onreadystatechange = function(b) {
e(b);
'loading' !== document.readyState && (document.onreadystatechange = e, c())
}
}
}
})();
</script>
</body> </body>
</html> </html>