mirror of
https://github.com/WerySkok/nativegallery.git
synced 2024-12-22 16:41:17 +03:00
add site news
This commit is contained in:
parent
c04dab7da0
commit
f887b1f0a9
6 changed files with 141 additions and 33 deletions
23
app/Controllers/Api/Admin/CreateNews.php
Normal file
23
app/Controllers/Api/Admin/CreateNews.php
Normal 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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
||||
|
||||
|
|
61
views/pages/Admin/News.php
Normal file
61
views/pages/Admin/News.php
Normal 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>
|
||||
|
|
@ -61,43 +61,44 @@ use App\Models\{User, Vote, Comment};
|
|||
|
||||
<td style="vertical-align:top; padding-right:20px">
|
||||
|
||||
<h4><a href="/top30">Самые популярные за 24 часа</a></h4>
|
||||
<div>
|
||||
<?php
|
||||
$photos = DB::query('SELECT photo_id, COUNT(*) as view_count
|
||||
<h4><a href="/top30">Самые популярные за 24 часа</a></h4>
|
||||
<div>
|
||||
<?php
|
||||
$photos = DB::query('SELECT photo_id, COUNT(*) as view_count
|
||||
FROM photos_views
|
||||
WHERE time >= 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 '<a href="/photo/'.$p['id'].'" target="_blank" class="prw pop-prw">
|
||||
<img width="250" src="/api/photo/compress?url='.$p['photourl'].'">
|
||||
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 '<a href="/photo/' . $p['id'] . '" target="_blank" class="prw pop-prw">
|
||||
<img width="250" src="/api/photo/compress?url=' . $p['photourl'] . '">
|
||||
<div class="hpshade">
|
||||
<div class="eye-icon">+'.$pd['view_count'].'</div>
|
||||
<div class="eye-icon">+' . $pd['view_count'] . '</div>
|
||||
</div>
|
||||
</a>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="text-align:center; margin-bottom:20px">
|
||||
<div style="width: 250px;"></div></div>
|
||||
|
||||
<div style="text-align:center; margin-bottom:20px">
|
||||
<div style="width: 250px;"></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
<td style="vertical-align:top; width:100%; padding-top:4px">
|
||||
</td>
|
||||
<td style="vertical-align:top; width:70%; padding-top:4px">
|
||||
|
||||
|
||||
|
||||
<h4><a href="/photo/" target="_blank">Случайные фотографии</a></h4>
|
||||
<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');
|
||||
foreach ($photos as $p) {
|
||||
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'] . '")';
|
||||
echo ' <div class="prw-grid-item">
|
||||
<div class="prw-wrapper"><span style="word-spacing:-1px"><b>' . htmlspecialchars($p['place']) . '</b></span>
|
||||
<div>'.$date.'</div>
|
||||
<div>' . $date . '</div>
|
||||
</div>
|
||||
'; ?>
|
||||
<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>';
|
||||
}
|
||||
?>
|
||||
|
@ -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>
|
||||
<?php
|
||||
$online = DB::query('SELECT * FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time'=>time()));
|
||||
foreach ($online as $o) {
|
||||
echo '<a href="/author/'.$o['id'].'/">'.htmlspecialchars($o['username']).'</a>, ';
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
$online = DB::query('SELECT * FROM users WHERE online>=:time-300 ORDER BY online DESC', array(':time' => time()));
|
||||
foreach ($online as $o) {
|
||||
echo '<a href="/author/' . $o['id'] . '/">' . htmlspecialchars($o['username']) . '</a>, ';
|
||||
}
|
||||
?>
|
||||
|
||||
</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?>
|
||||
</tr>
|
||||
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Footer.php'); ?>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue