From 6ea3720a8b57a62841ffdb63431e7a8f4276e01e Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:51:14 +0300 Subject: [PATCH] Add comments! --- app/Controllers/Api/Images/Comment.php | 67 +++++++ app/Controllers/Api/Images/CommentsLoad.php | 22 +++ app/Controllers/Api/Images/Upload.php | 2 +- app/Controllers/ApiController.php | 8 + app/Core/Routes.php | 4 +- app/Models/Comment.php | 35 ++++ views/pages/Photo.php | 199 +++++++++----------- 7 files changed, 223 insertions(+), 114 deletions(-) create mode 100644 app/Controllers/Api/Images/Comment.php create mode 100644 app/Controllers/Api/Images/CommentsLoad.php create mode 100644 app/Models/Comment.php diff --git a/app/Controllers/Api/Images/Comment.php b/app/Controllers/Api/Images/Comment.php new file mode 100644 index 0000000..7331169 --- /dev/null +++ b/app/Controllers/Api/Images/Comment.php @@ -0,0 +1,67 @@ + $_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 + ) + )); + } + } +} diff --git a/app/Controllers/Api/Images/CommentsLoad.php b/app/Controllers/Api/Images/CommentsLoad.php new file mode 100644 index 0000000..9411cc6 --- /dev/null +++ b/app/Controllers/Api/Images/CommentsLoad.php @@ -0,0 +1,22 @@ +explode('/', $_SERVER['REQUEST_URI'])[4])); + foreach ($comments as $c) { + $comm = new Comment($c); + $comm->i(); + } + } +} diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index 00cfb5f..3c4af46 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -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, diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 0545a00..9146f13 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -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(); + } } \ No newline at end of file diff --git a/app/Core/Routes.php b/app/Core/Routes.php index d4c94ab..d4774e5 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -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']); } diff --git a/app/Models/Comment.php b/app/Models/Comment.php new file mode 100644 index 0000000..3f41012 --- /dev/null +++ b/app/Models/Comment.php @@ -0,0 +1,35 @@ +c = $user_id; + } + public function i() { + $user = new User($this->c['user_id']); + echo '
+
+ '.Date::zmdate($this->c['posted_at']).'
+
+ +
'.$user->i('username').' ·
+
Фото: 1585
+
'.$this->c['body'].'
+
+
+
+1
+
+
+1 / –0
+
+
+
+
'; + } + + +} \ No newline at end of file diff --git a/views/pages/Photo.php b/views/pages/Photo.php index ec0e49d..b8c77cd 100644 --- a/views/pages/Photo.php +++ b/views/pages/Photo.php @@ -1,7 +1,7 @@ i('user_id'));

Статистика

Лицензия: BY-NC
- Опубликовано 13.07.2020 17:47 MSK
- Просмотров — 1693

- Подробная информация + Опубликовано i('timeupload')) ?>
@@ -155,37 +153,37 @@ $photouser = new \App\Models\User($photo->i('user_id'));

Оценка

-
Рейтинг:
+
Рейтинг:
-
+
- $id)); - foreach ($votespos as $ps) { - $uservote = new User($ps['user_id']); - echo ' - + $id)); + foreach ($votespos as $ps) { + $uservote = new User($ps['user_id']); + echo ' + '; - } - ?> - + } + ?> +
'.$uservote->i('username').'
' . $uservote->i('username') . ' +1
- $id)); - foreach ($votespos as $ps) { - $uservote = new User($ps['user_id']); - echo ' - + $id)); + foreach ($votespos as $ps) { + $uservote = new User($ps['user_id']); + echo ' + '; - } - ?> - + } + ?> +
'.$uservote->i('username').'
' . $uservote->i('username') . ' -1
@@ -194,9 +192,9 @@ $photouser = new \App\Models\User($photo->i('user_id')); @@ -232,106 +230,83 @@ $photouser = new \App\Models\User($photo->i('user_id'));

Комментарии · 1

-
-
- 12.08.2020 16:57 MSK
- Ссылка -
- -
Андрей Янковский · Днепр
-
Фото: 1585
-
Есть аналогичное фото в цвете:
https://smart-lab.ru/uploads/images/00/0...a3c.jpg
-
-
-
+1
-
-
+1 / –0
-
-
-
-
+
+ $id)); + foreach ($comments as $c) { + $comm = new Comment($c); + $comm->i(); + } + ?> +

Ваш комментарий

-
За обсуждение политики будет выноситься бан на 1 месяц и более.
- Вы не вошли на сайт.
Комментарии могут оставлять только зарегистрированные пользователи. +
+ + + + +
+
  Ctrl + Enter +
+
+
-
- - - - - - - - -
- -
- -
- -