Add comments!

This commit is contained in:
themohooks 2024-07-05 11:51:14 +03:00
parent 38dacd9235
commit 6ea3720a8b
7 changed files with 223 additions and 114 deletions

View file

@ -0,0 +1,67 @@
<?php
namespace App\Controllers\Api\Images;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, Files, Shell};
use App\Models\Notification;
class Comment
{
private static function create($content, $id)
{
DB::query('INSERT INTO photos_comments VALUES (\'0\', :userid, :postid, :postbody, :time)', array('postid' => $_POST['id'], ':postbody' => $_POST['wtext'], ':userid' => Auth::userid(), ':time' => time()));
}
public function __construct()
{
$id = $_POST['id'];
$postbody = $_POST['wtext'];
if ((int)$id === DB::query('SELECT id FROM photos WHERE id=:id', array(':id' => $id))[0]['id']) {
$content = Json::return(
array(
'type' => 'none',
'by' => 'user'
)
);
if (strlen($postbody) < 4096 || strlen($postbody) > 1) {
if (trim($postbody) != '') {
$postbody = ltrim($postbody);
echo json_encode(
array(
'errorcode' => '0',
'error' => 0
)
);
} else {
die(json_encode(
array(
'errorcode' => '1',
'error' => 1
)
));
}
} else {
die(json_encode(
array(
'errorcode' => '1',
'error' => 1
)
));
}
self::create($content, $id);
} else {
die(json_encode(
array(
'errorcode' => '1',
'error' => 1
)
));
}
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace App\Controllers\Api\Images;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
use App\Models\{User, Vote, Comment};
class CommentsLoad
{
public function __construct()
{
$comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid'=>explode('/', $_SERVER['REQUEST_URI'])[4]));
foreach ($comments as $c) {
$comm = new Comment($c);
$comm->i();
}
}
}

View file

@ -17,7 +17,7 @@ class Upload
public static function create($postbody, $content, $exif) public static function create($postbody, $content, $exif)
{ {
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :exif, 0, :place, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'])); DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :place, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup'=>time()));
echo json_encode( echo json_encode(
array( array(
'errorcode' => 0, 'errorcode' => 0,

View file

@ -7,6 +7,8 @@ use \App\Core\Page;
use \App\Controllers\Api\{Login, Register}; use \App\Controllers\Api\{Login, Register};
use \App\Controllers\Api\Images\{Upload}; use \App\Controllers\Api\Images\{Upload};
use \App\Controllers\Api\Images\Rate as PhotoVote; use \App\Controllers\Api\Images\Rate as PhotoVote;
use \App\Controllers\Api\Images\Comment as PhotoComment;
use \App\Controllers\Api\Images\CommentsLoad as PhotoCommentLoad;
class ApiController class ApiController
{ {
@ -23,6 +25,12 @@ class ApiController
public static function photovote() { public static function photovote() {
return new PhotoVote(); return new PhotoVote();
} }
public static function photocomment() {
return new PhotoComment();
}
public static function photocommentload() {
return new PhotoCommentLoad();
}
} }

View file

@ -17,6 +17,7 @@ class Routes
Router::get('/register', 'RegisterController@i'); Router::get('/register', 'RegisterController@i');
Router::get('/photo/$id', 'PhotoController@i'); Router::get('/photo/$id', 'PhotoController@i');
Router::get('/author/$id', 'ProfileController@i'); Router::get('/author/$id', 'ProfileController@i');
Router::post('/api/login', 'ApiController@login'); Router::post('/api/login', 'ApiController@login');
Router::get('/api/photo/vote', 'ApiController@photovote'); Router::get('/api/photo/vote', 'ApiController@photovote');
Router::post('/api/register', 'ApiController@register'); Router::post('/api/register', 'ApiController@register');
@ -27,8 +28,9 @@ class Routes
if (Auth::userid() > 0) { if (Auth::userid() > 0) {
Router::get('/lk', 'ProfileController@lk'); Router::get('/lk', 'ProfileController@lk');
Router::get('/lk/upload', 'ProfileController@upload'); Router::get('/lk/upload', 'ProfileController@upload');
Router::post('/api/upload', 'ApiController@upload'); Router::post('/api/upload', 'ApiController@upload');
Router::post('/api/photo/comment', 'ApiController@photocomment');
Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload');
} else { } else {
Router::redirect('/login?return='.$_SERVER['HTTP_REFERER']); Router::redirect('/login?return='.$_SERVER['HTTP_REFERER']);
} }

35
app/Models/Comment.php Normal file
View file

@ -0,0 +1,35 @@
<?php
namespace App\Models;
use \App\Services\{DB, Date};
use \App\Models\User;
class Comment {
public $commentid;
public $c;
function __construct($user_id) {
$this->c = $user_id;
}
public function i() {
$user = new User($this->c['user_id']);
echo '<div class="s11 comment" wid="2681468">
<div style="float:right; text-align:right" class="sm">
<span class="message_date">'.Date::zmdate($this->c['posted_at']).'</span><br>
</div>
<a name="2681468"></a><a name="last"></a>
<div><b><a href="/author/'.$this->c['user_id'].'/" class="message_author">'.$user->i('username').'</a></b> &middot; </div>
<div class="rank">Фото: 1585</div>
<div class="message-text">'.$this->c['body'].'</div>
<div class="comment-votes-block">
<div class="wvote" wid="'.$this->c['id'].'">
<div class="w-rating pro">+1</div>
<div class="w-rating-ext">
<div><span class="pro">+1</span> / <span class="con">0</span></div>
</div>
</div>
</div>
</div>';
}
}

View file

@ -1,7 +1,7 @@
<?php <?php
use App\Services\{DB, Auth, Date, Json}; use App\Services\{DB, Auth, Date, Json};
use App\Models\{User, Vote}; use App\Models\{User, Vote, Comment};
$id = explode('/', $_SERVER['REQUEST_URI'])[2]; $id = explode('/', $_SERVER['REQUEST_URI'])[2];
$photo = new \App\Models\Photo($id); $photo = new \App\Models\Photo($id);
@ -144,9 +144,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<h4>Статистика</h4> <h4>Статистика</h4>
<div class="sm"> <div class="sm">
<div style="margin-bottom:10px">Лицензия: <b>BY-NC</b></div> <div style="margin-bottom:10px">Лицензия: <b>BY-NC</b></div>
Опубликовано <b>13.07.2020 17:47 MSK</b><br> Опубликовано <b><?= Date::zmdate($photo->i('timeupload')) ?></b><br>
Просмотров <b>1693</b><br><br>
<a href="/photoext.php?pid=1361063">Подробная информация</a>
</div> </div>
</div> </div>
@ -155,36 +153,36 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<h4 class="pp-item-header">Оценка</h4> <h4 class="pp-item-header">Оценка</h4>
<div class="sm"> <div class="sm">
<img class="loader" pid="1361063" src="/img/loader.png"> <img class="loader" pid="1361063" src="/img/loader.png">
<div class="rtext">Рейтинг: <b id="rating"><?=Vote::count($id)?></b></div> <div class="rtext">Рейтинг: <b id="rating"><?= Vote::count($id) ?></b></div>
<div class="star" pid="1361063"></div> <div class="star" pid="1361063"></div>
<div class="vote" pid="<?=$id?>"> <div class="vote" pid="<?= $id ?>">
<a href="#" vote="1" class="vote_btn"><span>Интересная фотография!</span></a><a href="#" vote="0" class="vote_btn"><span>Мне не&nbsp;нравится</span></a> <a href="#" vote="1" class="vote_btn"><span>Интересная фотография!</span></a><a href="#" vote="0" class="vote_btn"><span>Мне не&nbsp;нравится</span></a>
</div> </div>
<div id="votes" class="votes"> <div id="votes" class="votes">
<table class="vblock pro"> <table class="vblock pro">
<?php <?php
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=1', array(':pid'=>$id)); $votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=1', array(':pid' => $id));
foreach ($votespos as $ps) { foreach ($votespos as $ps) {
$uservote = new User($ps['user_id']); $uservote = new User($ps['user_id']);
echo ' <tr> echo ' <tr>
<td><a href="/author/'.$ps['user_id'].'/">'.$uservote->i('username').'</a></td> <td><a href="/author/' . $ps['user_id'] . '/">' . $uservote->i('username') . '</a></td>
<td class="vv">+1</td> <td class="vv">+1</td>
</tr>'; </tr>';
} }
?> ?>
</table> </table>
<table class="vblock coN"> <table class="vblock coN">
<?php <?php
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=0', array(':pid'=>$id)); $votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=0', array(':pid' => $id));
foreach ($votespos as $ps) { foreach ($votespos as $ps) {
$uservote = new User($ps['user_id']); $uservote = new User($ps['user_id']);
echo ' <tr> echo ' <tr>
<td><a href="/author/'.$ps['user_id'].'/">'.$uservote->i('username').'</a></td> <td><a href="/author/' . $ps['user_id'] . '/">' . $uservote->i('username') . '</a></td>
<td class="vv">-1</td> <td class="vv">-1</td>
</tr>'; </tr>';
} }
?> ?>
</table> </table>
</div> </div>
@ -194,9 +192,9 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<div class="p20a" id="pp-item-link"> <div class="p20a" id="pp-item-link">
<h4 style="margin-bottom:7px">Постоянная ссылка на фото</h4> <h4 style="margin-bottom:7px">Постоянная ссылка на фото</h4>
<input type="text" value="https://transphoto.org/photo/1361063/" readonly="readonly" class="pp-link" onclick="this.select()"> <input type="text" value="https://<?= $_SERVER['SERVER_NAME'] ?>/photo/<?= $id ?>/" readonly="readonly" class="pp-link" onclick="this.select()">
<script src="//yandex.st/share/share.js" charset="utf-8" async defer></script> <script src="https://yastatic.net/share2/share.js"></script>
<div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="yaru,vkontakte,facebook,twitter,odnoklassniki,moimir,lj"></div> <div class="ya-share2" data-curtain data-size="s" data-shape="round" data-services="vkontakte,odnoklassniki,telegram,twitter,whatsapp"></div>
</div> </div>
@ -232,106 +230,83 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<div class="p0" id="pp-item-comments"> <div class="p0" id="pp-item-comments">
<h4 class="pp-item-header">Комментарии<span style="font-weight:normal"> <span style="color:#aaa">&middot;</span> 1</span></h4> <h4 class="pp-item-header">Комментарии<span style="font-weight:normal"> <span style="color:#aaa">&middot;</span> 1</span></h4>
<div class="s11 comment" wid="2681468"> <div id="posts">
<div style="float:right; text-align:right" class="sm"> <?php
<span class="message_date">12.08.2020</span> 16:57 MSK<br> $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid'=>$id));
<a href="#2681468" class="cmLink dot">Ссылка</a> foreach ($comments as $c) {
</div> $comm = new Comment($c);
<a name="2681468"></a><a name="last"></a> $comm->i();
<div><b><a href="/author/533/" class="message_author">Андрей Янковский</a></b> &middot; <span class="flag"><img src="/img/r/3.gif" title="Украина"> Днепр</span></div> }
<div class="rank">Фото: 1585</div> ?>
<div class="message-text">Есть аналогичное фото в цвете:<br><a href="https://smart-lab.ru/uploads/images/00/00/16/2011/10/16/433a3c.jpg" target="_blank">https://smart-lab.ru/uploads/images/00/0...a3c.jpg</a></div> </div>
<div class="comment-votes-block">
<div class="wvote" wid="2681468">
<div class="w-rating pro">+1</div>
<div class="w-rating-ext">
<div><span class="pro">+1</span> / <span class="con">0</span></div>
</div>
</div>
</div>
</div>
<div class="cmt-write s1"> <div class="cmt-write s1">
<h4 class="pp-item-header">Ваш комментарий</h4> <h4 class="pp-item-header">Ваш комментарий</h4>
<div style="padding:0 11px 11px"> <div style="padding:0 11px 11px">
<div class="no-politics">За обсуждение политики будет выноситься бан на 1 месяц и более.</div> <form action="/comment.php" method="post" id="f1">
Вы не <a href="/login.php">вошли на сайт</a>.<br />Комментарии могут оставлять только зарегистрированные пользователи. <input type="hidden" name="sid" value="hgdl6old9r9qodmvkn1r4t7d6h">
<input type="hidden" name="last_comment_rand" value="893329610">
<input type="hidden" name="id" id="id" value="<?=$id?>">
<input type="hidden" name="subj" id="subj" value="p">
<textarea name="wtext" id="wtext"></textarea><br>
<div class="cmt-submit"><input type="submit" value="Добавить комментарий" id="sbmt">&ensp;&emsp;Ctrl + Enter
</div>
</form>
</div> </div>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
</table> </table>
</div> <script>
<table width="100%"> $(document).ready(function() {
<tr> $('#f1').submit(function(e) {
<td> e.preventDefault();
</center> $.ajax({
</td> type: "POST",
</tr> url: '/api/photo/comment',
<tr> data: $(this).serialize(),
<td id="adframe"> success: function(response) {
<!-- Yandex.RTB R-A-115118-1 --> var jsonData = JSON.parse(response);
<div id="yandex_rtb_R-A-115118-1"></div> if (jsonData.errorcode == "1") {
<script> Notify.noty('danger', 'Комментарий неккоректен');
window.yaContextCb.push(() => { //$("#result").html("<div class='alert alert-dangernew container mt-5' role='alert'>Неправильная почта или пароль!</div>");
Ya.Context.AdvManager.render({ } else if (jsonData.errorcode == "2") {
renderTo: 'yandex_rtb_R-A-115118-1', Notify.noty('warning', 'Пожалуйста, подождите...');
blockId: 'R-A-115118-1' setTimeout(function(){
}) window.location.replace(jsonData.twofaurl);
}) }, 1000);
</script> } else if (jsonData.errorcode == "0") {
</td> Notify.noty('success', 'Комментарий отправлен!');
</tr> //$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>");
<tr> $.ajax({
<td class="footer"><b><a href="/">Главная</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?pcver=0">Мобильная версия</a><br><a href="/set.php?dark=1" style="display:inline-block; padding:1px 10px; margin-top:5px; background-color:#333; color:#fff">Тёмная тема</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> type: "POST",
</div> url: "/api/photo/getcomments/<?=$id?>",
processData: false,
async: true,
success: function(r) {
$('#posts').html(r)
</td>
</tr>
</table>
<script> },
(function() { error: function(r) {
function c() { console.log(r)
var b = a.contentDocument || a.contentWindow.document; }
if (b) {
var d = b.createElement('script'); });
d.innerHTML = "window.__CF$cv$params={r:'89de09cd798e66c9',t:'MTcyMDA4NDgxNS4wMDAwMDA='};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) } else {
} Notify.noty('danger', 'Неизвестная ошибка');
}
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> </script>
</body> </div>
</html> </html>