add site news

This commit is contained in:
themohooks 2024-07-21 17:22:27 +03:00
parent c04dab7da0
commit f887b1f0a9
6 changed files with 141 additions and 33 deletions

View file

@ -0,0 +1,23 @@
<?php
namespace App\Controllers\Api\Admin;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
use App\Models\{User, Vote, Photo};
class CreateNews
{
public function __construct()
{
DB::query('INSERT INTO news VALUES (\'0\', :body, :time)', array(':body' => $_POST['body'], ':time' => time()));
echo json_encode(
array(
'errorcode' => 0,
'error' => 0
)
);
}
}

View file

@ -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();
}
}

View file

@ -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');

View file

@ -58,6 +58,10 @@ body {
<i class="bx bx-camera nav__icon"></i>
<span class="nav__name">Фотографии</span>
</a>
<a href="/admin?type=News" class="nav__link">
<i class="bx bx-news nav__icon"></i>
<span class="nav__name">Новости сайта</span>
</a>

View file

@ -0,0 +1,61 @@
<?php
use \App\Services\{Auth, DB, Date};
use \App\Models\User;
//$userprofile = new User(explode('/', $_SERVER['REQUEST_URI'])[2]);
?>
<h1><b>Новости сайта</b></h1>
<a data-bs-toggle="modal" data-bs-target="#createNewsModal" href="#" class="btn btn-primary">Создать</a>
<div class="modal fade" id="createNewsModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel"><b>Создать новость</b></h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="body" class="form-label">Содержание</label>
<textarea class="form-control" id="body" name="body" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<a type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</a>
<a href="#" onclick="createNews(); return false;" data-bs-dismiss="modal" class="btn btn-primary">Создать</a>
</div>
</div>
</div>
</div>
<?php
$news = DB::query('SELECT * FROM news ORDER BY id');
foreach ($news as $n) {
echo '<div class="card"><div class="card-body">'.Date::zmdate($n['time']).'<br>'.$n['body'].'</div></div>';
}
?>
<script>
function photoAction(photo_id, decline_reason, mod) {
$.ajax({
type: "GET",
url: '/api/admin/createnews',
data: {
body: $('#body').val()
},
success: function(response) {
$('#pht'+photo_id).remove();
Notify.noty('success', 'OK!');
//$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>");
}
});
}
</script>

View file

@ -87,12 +87,13 @@ foreach ($photos as $pd) {
<div style="text-align:center; margin-bottom:20px">
<div style="width: 250px;"></div></div>
<div style="width: 250px;"></div>
</div>
</td>
<td style="vertical-align:top; width:100%; padding-top:4px">
<td style="vertical-align:top; width:70%; padding-top:4px">
<h4><a href="/photo/" target="_blank">Случайные фотографии</a></h4>
@ -161,6 +162,20 @@ foreach ($photos as $pd) {
</div>
</td>
<td style="padding-left:20px; width:254px; vertical-align:top">
<h4>Новости сайта</h4>
<div class="sm" style="margin-bottom:15px; line-height:13px; white-space:normal">
<?php
$news = DB::query('SELECT * FROM news ORDER BY id DESC LIMIT 10');
foreach ($news as $n) {
echo '<div class="ix-news-item"><b>'.Date::zmdate($n['time']).'</b>
<div class="break-links" style="padding-top:3px">'.$n['body'].'</div>
</div>';
}
?>
</div>
</td>
</tr>
</table>
</td>