favorite photos

This commit is contained in:
themohooks 2024-10-06 01:26:58 +03:00
parent f1dfb96864
commit 2995940e76
8 changed files with 275 additions and 113 deletions

View file

@ -0,0 +1,25 @@
<?php
namespace App\Controllers\Api\Images;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
use App\Models\{User, Vote};
class Favorite
{
public function __construct()
{
$postId = explode('/', $_SERVER['REQUEST_URI'])[3];
if (DB::query('SELECT * FROM photos_favorite WHERE photo_id = :id AND user_id=:uid', ['id' => $postId, ':uid'=>Auth::userid()])) {
DB::query('DELETE FROM photos_favorite WHERE photo_id = :id AND user_id=:uid', ['id' => $postId, ':uid'=>Auth::userid()]);
echo 0;
} else {
DB::query('INSERT INTO photos_favorite (photo_id, user_id) VALUES (:id, :uid)', ['id' => $postId, ':uid'=>Auth::userid()]);
echo 1;
}
}
}

View file

@ -11,6 +11,7 @@ use \App\Controllers\Api\Images\Rate as PhotoVote;
use \App\Controllers\Api\Images\Compress as PhotoCompress; use \App\Controllers\Api\Images\Compress as PhotoCompress;
use \App\Controllers\Api\Images\CheckAll as PhotoCheckAll; use \App\Controllers\Api\Images\CheckAll as PhotoCheckAll;
use \App\Controllers\Api\Images\LoadRecent as PhotoLoadRecent; use \App\Controllers\Api\Images\LoadRecent as PhotoLoadRecent;
use \App\Controllers\Api\Images\Favorite as PhotoFavorite;
use \App\Controllers\Api\Images\Stats as PhotoStats; use \App\Controllers\Api\Images\Stats as PhotoStats;
use \App\Controllers\Api\Images\Comments\Create as PhotoComment; use \App\Controllers\Api\Images\Comments\Create as PhotoComment;
use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit; use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit;
@ -37,6 +38,9 @@ class ApiController
public static function photovote() { public static function photovote() {
return new PhotoVote(); return new PhotoVote();
} }
public static function photofavorite() {
return new PhotoFavorite();
}
public static function photocomment() { public static function photocomment() {
return new PhotoComment(); return new PhotoComment();
} }

View file

@ -57,6 +57,11 @@ class MainController
{ {
Page::set('Feed'); Page::set('Feed');
}
public static function fav()
{
Page::set('Fav');
} }
public static function favauthors() public static function favauthors()
{ {

View file

@ -46,9 +46,12 @@ class Routes
Router::get('/search', 'SearchController@i'); Router::get('/search', 'SearchController@i');
Router::get('/fav', 'MainController@fav');
Router::post('/api/upload', 'ApiController@upload'); Router::post('/api/upload', 'ApiController@upload');
Router::post('/api/profile/update', 'ApiController@updateprofile'); Router::post('/api/profile/update', 'ApiController@updateprofile');
Router::post('/api/photo/comment', 'ApiController@photocomment'); Router::post('/api/photo/comment', 'ApiController@photocomment');
Router::get('/api/photo/$id/favorite', 'ApiController@photofavorite');
Router::get('/api/subscribe', 'ApiController@subscribeuser'); Router::get('/api/subscribe', 'ApiController@subscribeuser');
Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload'); Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload');
Router::get('/api/photo/vote', 'ApiController@photovote'); Router::get('/api/photo/vote', 'ApiController@photovote');

View file

@ -209,11 +209,14 @@ $(document).ready(function()
// Избранное // Избранное
$('#favLink').click(function() $('#favLink').click(function()
{ {
const url = window.location.pathname;
const segments = url.split('/');
const id = segments[segments.length - 1];
var faved = parseInt($(this).attr('faved')); var faved = parseInt($(this).attr('faved'));
$(this).html(_text[faved ? 'P_ADDFAV' : 'P_DELFAV']).attr('faved', faved ? 0 : 1); $(this).html(faved ? 'Добавить фото в Избранное' : 'Удалить фото из Избранного').attr('faved', faved ? 0 : 1);
if (!faved && subscr_fav) $('.toggle').attr('class', 'toggle on'); if (!faved) $('.toggle').attr('class', 'toggle on');
$.get('/api.php', { action: 'fav-photo', pid : pid }, function (r) { if (r != 0 && r != 1) alert(r); }).fail(function(jx) { if (jx.responseText != '') alert(jx.responseText); }); $.get('/api/photo/'+id+'/favorite', function (r) { if (r != 0 && r != 1) alert(r); }).fail(function(jx) { if (jx.responseText != '') alert(jx.responseText); });
return false; return false;
}); });

View file

@ -108,7 +108,7 @@ if ($noncheckedimgs > 0) {
<li><a href="/lk/ticket.php" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-question-circle"></i></span><span class="mm-label">Мои заявки</span></a></li> <li><a href="/lk/ticket.php" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-question-circle"></i></span><span class="mm-label">Мои заявки</span></a></li>
<li><a href="/lk/profile" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-cog"></i></span><span class="mm-label">Настройки профиля</span></a></li> <li><a href="/lk/profile" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-cog"></i></span><span class="mm-label">Настройки профиля</span></a></li>
<li><a href="/search?id=<?=Auth::userid()?>" class="mm-item"><span class="mm-icon"><i class="far fa-sm fa-fw fa-images"></i></span><span class="mm-label">Мои фотографии</span></a></li> <li><a href="/search?id=<?=Auth::userid()?>" class="mm-item"><span class="mm-icon"><i class="far fa-sm fa-fw fa-images"></i></span><span class="mm-label">Мои фотографии</span></a></li>
<li><a href="/fav.php" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-star"></i></span><span class="mm-label">Избранные снимки</span></a></li> <li><a href="/fav" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-star"></i></span><span class="mm-label">Избранные снимки</span></a></li>
<li><a href="/logout" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-sign-out-alt"></i></span><span class="mm-label">Выход</span></a></li> <li><a href="/logout" class="mm-item"><span class="mm-icon"><i class="fas fa-sm fa-fw fa-sign-out-alt"></i></span><span class="mm-label">Выход</span></a></li>
</ul> </ul>
</div> </div>

99
views/pages/Fav.php Normal file
View file

@ -0,0 +1,99 @@
<?php
use App\Services\{DB, Auth, Date, Json};
use App\Models\{User, Vote, Comment, Photo};
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/LoadHead.php'); ?>
</head>
<style>
.ix-country {
padding-top: 3px;
white-space: nowrap;
font-family: var(--narrow-font);
font-size: 18px;
}
.ix-country>a>b {
border-bottom: dotted 1px;
}
.ix-cities {
padding: 5px 0 15px 15px;
}
.ix-arrow {
display: inline-block;
width: 9px;
height: 9px;
background: url("/img/arrow_blue.png") no-repeat;
transition: transform .1s ease-out;
position: relative;
top: -1px;
}
.ix-arrow.ix-arrow-expanded {
transform: rotate(90deg);
}
</style>
</head>
<body>
<div id="backgr"></div>
<table class="tmain">
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Navbar.php'); ?>
<tr>
<td class="main">
<h1>Избранные фотографии</h1>
<?php
$photos = DB::query('SELECT * FROM photos_favorite WHERE user_id=:uid ORDER BY id DESC LIMIT 100', array(':uid'=>Auth::userid()));
foreach ($photos as $p) {
$photo = new Photo($p['photo_id']);
$user = new User($p['user_id']);
echo ' <div class="p20p" style="padding:0 5px">
<table>
<tr>
<td class="pb_photo" id="p2017137"><a href="/photo/'.$photo->i('id').'" target="_blank" class="prw"><img class="f" src="/api/photo/compress?url=' . $photo->i('photourl') . '" alt="598 КБ">
<div class="hpshade">
<div class="eye-icon">'.DB::query('SELECT COUNT(*) FROM photos_views WHERE photo_id=:id', array(':id'=>$photo->i('id')))[0]['COUNT(*)'].'</div>
</div>
</a></td>
<td class="pb_descr">
<p>'.htmlspecialchars($photo->i('postbody')).'</p>
<p><b class="pw-place">'.htmlspecialchars($photo->i('place')).'</b></p>
<p class="sm"><b>'.Date::zmdate($photo->i('posted_at')).'</b><br>Автор: <a href="/author/'.$photo->i('user_id').'/">'.$user->i('username').'</a></p>
</td>
</tr>
</table>
</div><br>';
}
?>
<div id="scroll_anchor"></div>
</td>
</tr>
<tr>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?>
</tr>
</table>
</body>
</html>

View file

@ -27,7 +27,6 @@ if ($photo->i('id') !== null) {
DB::query('INSERT INTO photos_views VALUES (\'0\', :uid, :pid, :time)', array(':uid' => Auth::userid(), ':pid' => $id, ':time' => time())); DB::query('INSERT INTO photos_views VALUES (\'0\', :uid, :pid, :time)', array(':uid' => Auth::userid(), ':pid' => $id, ':time' => time()));
} }
} }
} }
?> ?>
@ -204,7 +203,23 @@ if ($photo->i('id') !== null) {
<a href="/photoext?id=<?= $id ?>">Подробная информация</a> <a href="/photoext?id=<?= $id ?>">Подробная информация</a>
</div> </div>
</div> </div>
<div class="p0" id="pp-item-tools">
<h4 class="pp-item-header">Инструменты</h4>
<div class="pp-item-body" style="margin:7px 5px">
<div class="sm">
<?php
if (DB::query('SELECT user_id FROM photos_favorite WHERE photo_id=:pid AND user_id=:uid', array(':uid'=>Auth::userid(), ':pid'=>$id))) {
$fav = 1;
$textfav = 'Удалить фото из Избранного';
} else {
$fav = 0;
$textfav = 'Добавить фото в Избранное';
}
?>
<a class="tool-link" href="#" id="favLink" faved="<?=$fav?>"><?=$textfav?></a>
</div>
</div>
</div>
<?php if ($photo->i('moderated') === 1) { ?> <?php if ($photo->i('moderated') === 1) { ?>
<div class="p20a" id="pp-item-vote"> <div class="p20a" id="pp-item-vote">
<h4 class="pp-item-header">Оценка</h4> <h4 class="pp-item-header">Оценка</h4>
@ -412,12 +427,18 @@ if ($photo->i('id') !== null) {
success: function(response) { success: function(response) {
var jsonData = JSON.parse(response); var jsonData = JSON.parse(response);
if (jsonData.errorcode == "1") { if (jsonData.errorcode == "1") {
$('#statusSend').css({display: 'block', color: 'red'}); $('#statusSend').css({
display: 'block',
color: 'red'
});
$('#statusSend').text('Комментарий некорректен'); $('#statusSend').text('Комментарий некорректен');
//Notify.noty('danger', 'Комментарий неккоректен'); //Notify.noty('danger', 'Комментарий неккоректен');
//$("#result").html("<div class='alert alert-dangernew container mt-5' role='alert'>Неправильная почта или пароль!</div>"); //$("#result").html("<div class='alert alert-dangernew container mt-5' role='alert'>Неправильная почта или пароль!</div>");
} else if (jsonData.errorcode == "2") { } else if (jsonData.errorcode == "2") {
$('#statusSend').css({display: 'block', color: 'yellow'}); $('#statusSend').css({
display: 'block',
color: 'yellow'
});
$('#statusSend').text('Пожалуйста, подождите...'); $('#statusSend').text('Пожалуйста, подождите...');
//Notify.noty('warning', 'Пожалуйста, подождите...'); //Notify.noty('warning', 'Пожалуйста, подождите...');
setTimeout(function() { setTimeout(function() {
@ -425,7 +446,10 @@ if ($photo->i('id') !== null) {
}, 1000); }, 1000);
} else if (jsonData.errorcode == "0") { } else if (jsonData.errorcode == "0") {
$('#wtext').val(''); $('#wtext').val('');
$('#statusSend').css({display: 'block', color: 'green'}); $('#statusSend').css({
display: 'block',
color: 'green'
});
$('#statusSend').text('Комментарий отправлен!'); $('#statusSend').text('Комментарий отправлен!');
//Notify.noty('success', 'Комментарий отправлен!'); //Notify.noty('success', 'Комментарий отправлен!');
//$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>"); //$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>");
@ -468,7 +492,6 @@ if ($photo->i('id') !== null) {
$('#err').html(content); $('#err').html(content);
$('#err .p20').slideDown(500); $('#err .p20').slideDown(500);
} }
</script> </script>
</div> </div>