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)
{
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(
array(
'errorcode' => 0,

View file

@ -7,6 +7,8 @@ use \App\Core\Page;
use \App\Controllers\Api\{Login, Register};
use \App\Controllers\Api\Images\{Upload};
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
{
@ -23,6 +25,12 @@ class ApiController
public static function 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('/photo/$id', 'PhotoController@i');
Router::get('/author/$id', 'ProfileController@i');
Router::post('/api/login', 'ApiController@login');
Router::get('/api/photo/vote', 'ApiController@photovote');
Router::post('/api/register', 'ApiController@register');
@ -27,8 +28,9 @@ class Routes
if (Auth::userid() > 0) {
Router::get('/lk', 'ProfileController@lk');
Router::get('/lk/upload', 'ProfileController@upload');
Router::post('/api/upload', 'ApiController@upload');
Router::post('/api/photo/comment', 'ApiController@photocomment');
Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload');
} else {
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
use App\Services\{DB, Auth, Date, Json};
use App\Models\{User, Vote};
use App\Models\{User, Vote, Comment};
$id = explode('/', $_SERVER['REQUEST_URI'])[2];
$photo = new \App\Models\Photo($id);
@ -144,9 +144,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<h4>Статистика</h4>
<div class="sm">
<div style="margin-bottom:10px">Лицензия: <b>BY-NC</b></div>
Опубликовано <b>13.07.2020 17:47 MSK</b><br>
Просмотров <b>1693</b><br><br>
<a href="/photoext.php?pid=1361063">Подробная информация</a>
Опубликовано <b><?= Date::zmdate($photo->i('timeupload')) ?></b><br>
</div>
</div>
@ -194,9 +192,9 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<div class="p20a" id="pp-item-link">
<h4 style="margin-bottom:7px">Постоянная ссылка на фото</h4>
<input type="text" value="https://transphoto.org/photo/1361063/" readonly="readonly" class="pp-link" onclick="this.select()">
<script src="//yandex.st/share/share.js" charset="utf-8" async defer></script>
<div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="yaru,vkontakte,facebook,twitter,odnoklassniki,moimir,lj"></div>
<input type="text" value="https://<?= $_SERVER['SERVER_NAME'] ?>/photo/<?= $id ?>/" readonly="readonly" class="pp-link" onclick="this.select()">
<script src="https://yastatic.net/share2/share.js"></script>
<div class="ya-share2" data-curtain data-size="s" data-shape="round" data-services="vkontakte,odnoklassniki,telegram,twitter,whatsapp"></div>
</div>
@ -232,106 +230,83 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<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>
<div class="s11 comment" wid="2681468">
<div style="float:right; text-align:right" class="sm">
<span class="message_date">12.08.2020</span> 16:57 MSK<br>
<a href="#2681468" class="cmLink dot">Ссылка</a>
</div>
<a name="2681468"></a><a name="last"></a>
<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 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 id="posts">
<?php
$comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid'=>$id));
foreach ($comments as $c) {
$comm = new Comment($c);
$comm->i();
}
?>
</div>
<div class="cmt-write s1">
<h4 class="pp-item-header">Ваш комментарий</h4>
<div style="padding:0 11px 11px">
<div class="no-politics">За обсуждение политики будет выноситься бан на 1 месяц и более.</div>
Вы не <a href="/login.php">вошли на сайт</a>.<br />Комментарии могут оставлять только зарегистрированные пользователи.
<form action="/comment.php" method="post" id="f1">
<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>
</td>
</tr>
</table>
</div>
<table width="100%">
<tr>
<td>
</center>
</td>
</tr>
<tr>
<td id="adframe">
<!-- Yandex.RTB R-A-115118-1 -->
<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'
})
})
$(document).ready(function() {
$('#f1').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '/api/photo/comment',
data: $(this).serialize(),
success: function(response) {
var jsonData = JSON.parse(response);
if (jsonData.errorcode == "1") {
Notify.noty('danger', 'Комментарий неккоректен');
//$("#result").html("<div class='alert alert-dangernew container mt-5' role='alert'>Неправильная почта или пароль!</div>");
} else if (jsonData.errorcode == "2") {
Notify.noty('warning', 'Пожалуйста, подождите...');
setTimeout(function(){
window.location.replace(jsonData.twofaurl);
}, 1000);
} else if (jsonData.errorcode == "0") {
Notify.noty('success', 'Комментарий отправлен!');
//$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>");
$.ajax({
type: "POST",
url: "/api/photo/getcomments/<?=$id?>",
processData: false,
async: true,
success: function(r) {
$('#posts').html(r)
},
error: function(r) {
console.log(r)
}
});
} else {
Notify.noty('danger', 'Неизвестная ошибка');
}
}
});
});
});
</script>
</td>
</tr>
<tr>
<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>
</div>
</td>
</tr>
</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:'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)
}
}
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>
</html>