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\Images\Comments\Rate as PhotoCommentVote;
use \App\Controllers\Api\Profile\Update as ProfileUpdate; use \App\Controllers\Api\Profile\Update as ProfileUpdate;
use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility; use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility;
use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews;
class ApiController class ApiController
{ {
@ -59,6 +60,9 @@ class ApiController
public static function photostats() { public static function photostats() {
return new PhotoStats(); return new PhotoStats();
} }
public static function admincreatenews() {
return new AdminCreateNews();
}
} }

View file

@ -55,6 +55,7 @@ class Routes
if ($user->i('admin') > 0) { if ($user->i('admin') > 0) {
Router::any('/admin', 'AdminController@index'); Router::any('/admin', 'AdminController@index');
Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis'); Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis');
Router::any('/api/admin/createnews', 'ApiController@admincreatenews');
} }
Router::get('/logout', 'MainController@logout'); Router::get('/logout', 'MainController@logout');
Router::get('/404', 'ExceptionRegister@notfound'); Router::get('/404', 'ExceptionRegister@notfound');

View file

@ -58,6 +58,10 @@ body {
<i class="bx bx-camera nav__icon"></i> <i class="bx bx-camera nav__icon"></i>
<span class="nav__name">Фотографии</span> <span class="nav__name">Фотографии</span>
</a> </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

@ -61,43 +61,44 @@ use App\Models\{User, Vote, Comment};
<td style="vertical-align:top; padding-right:20px"> <td style="vertical-align:top; padding-right:20px">
<h4><a href="/top30">Самые популярные за 24 часа</a></h4> <h4><a href="/top30">Самые популярные за 24 часа</a></h4>
<div> <div>
<?php <?php
$photos = DB::query('SELECT photo_id, COUNT(*) as view_count $photos = DB::query('SELECT photo_id, COUNT(*) as view_count
FROM photos_views FROM photos_views
WHERE time >= UNIX_TIMESTAMP(NOW()) - 86400 WHERE time >= UNIX_TIMESTAMP(NOW()) - 86400
GROUP BY photo_id GROUP BY photo_id
ORDER BY view_count DESC ORDER BY view_count DESC
LIMIT 10;'); LIMIT 10;');
foreach ($photos as $pd) { foreach ($photos as $pd) {
$photo = DB::query('SELECT * FROM photos WHERE id=:id', array(':id'=>$pd['photo_id'])); $photo = DB::query('SELECT * FROM photos WHERE id=:id', array(':id' => $pd['photo_id']));
foreach ($photo as $p) { foreach ($photo as $p) {
$author = new User($p['user_id']); $author = new User($p['user_id']);
echo '<a href="/photo/'.$p['id'].'" target="_blank" class="prw pop-prw"> echo '<a href="/photo/' . $p['id'] . '" target="_blank" class="prw pop-prw">
<img width="250" src="/api/photo/compress?url='.$p['photourl'].'"> <img width="250" src="/api/photo/compress?url=' . $p['photourl'] . '">
<div class="hpshade"> <div class="hpshade">
<div class="eye-icon">+'.$pd['view_count'].'</div> <div class="eye-icon">+' . $pd['view_count'] . '</div>
</div> </div>
</a>'; </a>';
} }
} }
?> ?>
</div> </div>
<div style="text-align:center; margin-bottom:20px"> <div style="text-align:center; margin-bottom:20px">
<div style="width: 250px;"></div></div> <div style="width: 250px;"></div>
</div>
</td> </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> <h4><a href="/photo/" target="_blank">Случайные фотографии</a></h4>
<div id="random-photos" class="ix-photos ix-photos-oneline"> <div id="random-photos" class="ix-photos ix-photos-oneline">
<?php <?php
$photos = DB::query('SELECT * FROM photos WHERE moderated=1 ORDER BY RAND() DESC LIMIT 7'); $photos = DB::query('SELECT * FROM photos WHERE moderated=1 ORDER BY RAND() DESC LIMIT 7');
foreach ($photos as $p) { foreach ($photos as $p) {
if ($p['posted_at'] === 943909200 || Date::zmdate($p['posted_at']) === '30 ноября 1999 в 00:00') { if ($p['posted_at'] === 943909200 || Date::zmdate($p['posted_at']) === '30 ноября 1999 в 00:00') {
@ -108,11 +109,11 @@ foreach ($photos as $pd) {
$bck = 'background-image:url("/api/photo/compress?url=' . $p['photourl'] . '")'; $bck = 'background-image:url("/api/photo/compress?url=' . $p['photourl'] . '")';
echo ' <div class="prw-grid-item"> echo ' <div class="prw-grid-item">
<div class="prw-wrapper"><span style="word-spacing:-1px"><b>' . htmlspecialchars($p['place']) . '</b></span> <div class="prw-wrapper"><span style="word-spacing:-1px"><b>' . htmlspecialchars($p['place']) . '</b></span>
<div>'.$date.'</div> <div>' . $date . '</div>
</div> </div>
'; ?> '; ?>
<a href="/photo/<?= $p['id'] ?>" target="_blank" class="prw-animate" style='background-image:url("/api/photo/compress?url=<?= $p['photourl'] ?>")'></a> <a href="/photo/<?= $p['id'] ?>" target="_blank" class="prw-animate" style='background-image:url("/api/photo/compress?url=<?= $p['photourl'] ?>")'></a>
<?php echo ' <?php echo '
</div>'; </div>';
} }
?> ?>
@ -150,24 +151,38 @@ foreach ($photos as $pd) {
<h4>Сейчас на сайте (<?=DB::query('SELECT COUNT(*) FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time'=>time()))[0]['COUNT(*)']?>)</h4> <h4>Сейчас на сайте (<?= DB::query('SELECT COUNT(*) FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time' => time()))[0]['COUNT(*)'] ?>)</h4>
<div> <div>
<?php <?php
$online = DB::query('SELECT * FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time'=>time())); $online = DB::query('SELECT * FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time' => time()));
foreach ($online as $o) { foreach ($online as $o) {
echo '<a href="/author/'.$o['id'].'/">'.htmlspecialchars($o['username']).'</a>, '; echo '<a href="/author/' . $o['id'] . '/">' . htmlspecialchars($o['username']) . '</a>, ';
} }
?> ?>
</div> </div>
</td> </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> </tr>
</table> </table>
</td> </td>
</tr> </tr>
<tr> <tr>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?> <?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?>
</tr> </tr>
</table> </table>