From f887b1f0a9069aaf46a7e52420adc43df9f28dea Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Sun, 21 Jul 2024 17:22:27 +0300 Subject: [PATCH] add site news --- app/Controllers/Api/Admin/CreateNews.php | 23 +++++++ app/Controllers/ApiController.php | 4 ++ app/Core/Routes.php | 1 + views/components/AdminSidebar.php | 4 ++ views/pages/Admin/News.php | 61 ++++++++++++++++++ views/pages/Main.php | 81 ++++++++++++++---------- 6 files changed, 141 insertions(+), 33 deletions(-) create mode 100644 app/Controllers/Api/Admin/CreateNews.php create mode 100644 views/pages/Admin/News.php diff --git a/app/Controllers/Api/Admin/CreateNews.php b/app/Controllers/Api/Admin/CreateNews.php new file mode 100644 index 0000000..b44e5d1 --- /dev/null +++ b/app/Controllers/Api/Admin/CreateNews.php @@ -0,0 +1,23 @@ + $_POST['body'], ':time' => time())); + echo json_encode( + array( + 'errorcode' => 0, + 'error' => 0 + ) + ); + } +} diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 7da966f..2f74dec 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -16,6 +16,7 @@ use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad; use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote; use \App\Controllers\Api\Profile\Update as ProfileUpdate; use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility; +use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews; class ApiController { @@ -59,6 +60,9 @@ class ApiController public static function photostats() { return new PhotoStats(); } + public static function admincreatenews() { + return new AdminCreateNews(); + } } \ No newline at end of file diff --git a/app/Core/Routes.php b/app/Core/Routes.php index b20d0ba..97cf220 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -55,6 +55,7 @@ class Routes if ($user->i('admin') > 0) { Router::any('/admin', 'AdminController@index'); Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis'); + Router::any('/api/admin/createnews', 'ApiController@admincreatenews'); } Router::get('/logout', 'MainController@logout'); Router::get('/404', 'ExceptionRegister@notfound'); diff --git a/views/components/AdminSidebar.php b/views/components/AdminSidebar.php index 8201f38..2865f54 100644 --- a/views/components/AdminSidebar.php +++ b/views/components/AdminSidebar.php @@ -58,6 +58,10 @@ body { Фотографии + + + Новости сайта + diff --git a/views/pages/Admin/News.php b/views/pages/Admin/News.php new file mode 100644 index 0000000..ebcfa81 --- /dev/null +++ b/views/pages/Admin/News.php @@ -0,0 +1,61 @@ + + + +

Новости сайта

+Создать + + +
'.Date::zmdate($n['time']).'
'.$n['body'].'
'; +} +?> + + + \ No newline at end of file diff --git a/views/pages/Main.php b/views/pages/Main.php index 873dcd6..d6a8960 100644 --- a/views/pages/Main.php +++ b/views/pages/Main.php @@ -61,43 +61,44 @@ use App\Models\{User, Vote, Comment}; -

Самые популярные за 24 часа

-
- Самые популярные за 24 часа +
+ = UNIX_TIMESTAMP(NOW()) - 86400 GROUP BY photo_id ORDER BY view_count DESC LIMIT 10;'); -foreach ($photos as $pd) { - $photo = DB::query('SELECT * FROM photos WHERE id=:id', array(':id'=>$pd['photo_id'])); - foreach ($photo as $p) { - $author = new User($p['user_id']); - echo ' - + foreach ($photos as $pd) { + $photo = DB::query('SELECT * FROM photos WHERE id=:id', array(':id' => $pd['photo_id'])); + foreach ($photo as $p) { + $author = new User($p['user_id']); + echo ' +
-
+'.$pd['view_count'].'
+
+' . $pd['view_count'] . '
'; - } -} - ?> -
+ } + } + ?> +
- -
-
+ +
+
+
- - + + + -

Случайные фотографии

-
' . htmlspecialchars($p['place']) . ' -
'.$date.'
+
' . $date . '
'; ?> ")'> - '; } ?> @@ -150,24 +151,38 @@ foreach ($photos as $pd) { -

Сейчас на сайте (=:time-300 ORDER BY online DESC', array(':time'=>time()))[0]['COUNT(*)']?>)

+

Сейчас на сайте (=:time-300 ORDER BY online DESC', array(':time' => time()))[0]['COUNT(*)'] ?>)

- =:time-300 ORDER BY online DESC', array(':time'=>time())); - foreach ($online as $o) { - echo ''.htmlspecialchars($o['username']).', '; - } - ?> + =:time-300 ORDER BY online DESC', array(':time' => time())); + foreach ($online as $o) { + echo '' . htmlspecialchars($o['username']) . ', '; + } + ?>
+ + +

Новости сайта

+
+ '.Date::zmdate($n['time']).' + +
'; + } + ?> +
+ - - + +