ADD: Лента активности, чат (первая часть)
This commit is contained in:
parent
95dba4245b
commit
f919d184d6
11 changed files with 224 additions and 7 deletions
91
app/Controllers/FlowController.php
Normal file
91
app/Controllers/FlowController.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use App\Models\FlowModel;
|
||||
use Hleb\Constructor\Handlers\Request;
|
||||
use Base;
|
||||
|
||||
class FlowController extends \MainController
|
||||
{
|
||||
// Страница потока (flow_action_id):
|
||||
// 1 - add post
|
||||
// 2 - add comment
|
||||
// 3 - up post
|
||||
// 4 - up comment
|
||||
// 5 - chat
|
||||
public function index()
|
||||
{
|
||||
$account = \Request::getSession('account');
|
||||
$user_id = $account ? $account['user_id'] : 0;
|
||||
|
||||
$flows = FlowModel::getFlowAll();
|
||||
|
||||
$result = Array();
|
||||
foreach($flows as $ind => $row){
|
||||
|
||||
if(!$row['avatar']) {
|
||||
$row['avatar'] = 'noavatar.png';
|
||||
}
|
||||
|
||||
$row['avatar'] = $row['avatar'];
|
||||
$row['flow_pubdate'] = Base::ru_date($row['flow_pubdate']);
|
||||
$result[$ind] = $row;
|
||||
|
||||
}
|
||||
|
||||
$uid = Base::getUid();
|
||||
$data = [
|
||||
'h1' => lang('Flow'),
|
||||
'title' => lang('Flow'). ' | ' . $GLOBALS['conf']['sitename'],
|
||||
'description' => 'Лента потока, активности на сайте ' . $GLOBALS['conf']['sitename'],
|
||||
];
|
||||
|
||||
return view("flow/index", ['data' => $data, 'uid' => $uid, 'flows' => $result]);
|
||||
}
|
||||
|
||||
// Добавим чат
|
||||
public function chatAdd()
|
||||
{
|
||||
$account = \Request::getSession('account');
|
||||
$user_id = $account ? $account['user_id'] : 0;
|
||||
$flow_ip = \Request::getRemoteAddress();
|
||||
$chat_content = \Request::getPost('flow');
|
||||
|
||||
// Проверяем длину тела
|
||||
if (Base::getStrlen($chat_content) < 6 || Base::getStrlen($chat_content) > 500)
|
||||
{
|
||||
Base::addMsg('Длина поста должна быть от 6 до 500 знаков', 'error');
|
||||
redirect('/flow');
|
||||
return true;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'flow_action_id' => 5,
|
||||
'flow_content' => $chat_content,
|
||||
'flow_user_id' => $user_id,
|
||||
'flow_ip' => $flow_ip,
|
||||
];
|
||||
|
||||
// Записываем пост
|
||||
FlowModel::FlowChatAdd($data);
|
||||
|
||||
redirect('/flow');
|
||||
}
|
||||
|
||||
// Удаляем / восстанавливаем
|
||||
public function deleteFlow()
|
||||
{
|
||||
// Доступ только персоналу
|
||||
$account = \Request::getSession('account');
|
||||
if ($account['trust_level'] != 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$flow_id = \Request::getPostInt('flow_id');
|
||||
|
||||
FlowModel::FlowDelete($post_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,7 @@ return [
|
|||
'Edit' => 'Изменить',
|
||||
'Website' => 'Источник',
|
||||
'Invites' => 'Инвайты',
|
||||
'Flow' => 'Поток',
|
||||
'ed' => 'ред',
|
||||
'Yes' => 'Да',
|
||||
'No' => 'Нет',
|
||||
|
|
50
app/Models/FlowModel.php
Normal file
50
app/Models/FlowModel.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use XdORM\XD;
|
||||
|
||||
class FlowModel extends \MainModel
|
||||
{
|
||||
public static function getFlowAll()
|
||||
{
|
||||
|
||||
$q = XD::select('*')->from(['flow_log']);
|
||||
$query = $q->leftJoin(['users'])->on(['id'], '=', ['flow_user_id'])
|
||||
->where(['flow_is_delete'], '=', 0)
|
||||
->orderBy(['flow_id'])->desc()->limit(15);
|
||||
|
||||
$result = $query->getSelect();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Добавляем пост из чата
|
||||
public static function FlowChatAdd($data)
|
||||
{
|
||||
XD::insertInto(['flow_log'], '(',
|
||||
['flow_action_id'], ',',
|
||||
['flow_content'], ',',
|
||||
['flow_user_id'], ',',
|
||||
['flow_ip'], ')')->values( '(',
|
||||
|
||||
XD::setList([
|
||||
$data['flow_action_id'],
|
||||
$data['flow_content'],
|
||||
$data['flow_user_id'],
|
||||
$data['flow_ip']]), ')' )->run();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Удаляем / восстанавливаем
|
||||
public static function FlowDelete($flow_id)
|
||||
{
|
||||
if(self::isThePostDeleted($flow_id) == 1) {
|
||||
XD::update(['flow_log'])->set(['flow_is_delete'], '=', 0)->where(['flow_id'], '=', $flow_id)->run();
|
||||
} else {
|
||||
XD::update(['flow_log'])->set(['flow_is_delete'], '=', 1)->where(['flow_id'], '=', $flow_id)->run();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -284,7 +284,6 @@ class PostModel extends \MainModel
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// Частота размещения постов участника
|
||||
|
|
|
@ -426,7 +426,7 @@ ALTER TABLE `invitation`
|
|||
CREATE TABLE `flow_log` (
|
||||
`flow_id` int(11) NOT NULL,
|
||||
`flow_action_id` int(11) NOT NULL,
|
||||
`flow_pubdate` datetime NOT NULL,
|
||||
`flow_pubdate` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`flow_user_id` int(11) NOT NULL,
|
||||
`flow_on_user_id` int(11) NOT NULL,
|
||||
`flow_content` text NOT NULL,
|
||||
|
@ -434,7 +434,9 @@ CREATE TABLE `flow_log` (
|
|||
`flow_target_id` int(11) DEFAULT NULL,
|
||||
`flow_about` varchar(255) DEFAULT NULL,
|
||||
`flow_space_id` int(11) NOT NULL,
|
||||
`flow_tl` int(11) NOT NULL
|
||||
`flow_tl` int(11) NOT NULL,
|
||||
`flow_ip` varchar(12) DEFAULT NULL,
|
||||
`flow_is_delete` tinyint(1) NOT NULL DEFAULT 0
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
ALTER TABLE `flow_log`
|
||||
|
|
17
public/assets/css/flow.css
Normal file
17
public/assets/css/flow.css
Normal file
|
@ -0,0 +1,17 @@
|
|||
#add_flow {
|
||||
display: flex;
|
||||
}
|
||||
.add-flow {
|
||||
bottom: 30px;
|
||||
position: fixed;
|
||||
width: 60%;
|
||||
}
|
||||
textarea {
|
||||
width: 70%;
|
||||
}
|
||||
.add-flow-butt {
|
||||
margin: 10px;
|
||||
}
|
||||
@media (max-width: 720px){
|
||||
|
||||
}
|
18
resources/views/flow/flow-form.php
Normal file
18
resources/views/flow/flow-form.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<div class="add-flow">
|
||||
<?php if (!$uid['id'] > 0) : ?>
|
||||
<div id="add_flow">
|
||||
<textarea rows="1" disabled="disabled" placeholder="<?= lang('no-auth-comm'); ?>." id="flow"></textarea>
|
||||
<div class="add-flow-butt">
|
||||
<input type="button" value="<?= lang('Comment'); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<form id="add_flow" action="/flow/add" accept-charset="UTF-8" method="post">
|
||||
<?= csrf_field() ?>
|
||||
<textarea rows="1" placeholder="<?= lang('write-something'); ?>..." name="flow" id="flow"></textarea>
|
||||
<div class="add-flow-butt">
|
||||
<input type="submit" name="commit" value="<?= lang('Comment'); ?>" class="comment-post">
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
36
resources/views/flow/index.php
Normal file
36
resources/views/flow/index.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php include TEMPLATE_DIR . '/header.php'; ?>
|
||||
<?php include TEMPLATE_DIR . '/menu.php'; ?>
|
||||
<meta http-equiv="Refresh" content="15" />
|
||||
<link rel="stylesheet" href="/assets/css/flow.css">
|
||||
<main class="info">
|
||||
<div class="left-ots flow">
|
||||
<h1><?= $data['h1']; ?></h1>
|
||||
|
||||
<?php if (!empty($flows)) { ?>
|
||||
|
||||
<?php foreach ($flows as $flow) { ?>
|
||||
|
||||
<div class="comm-header">
|
||||
<img class="ava" src="/uploads/avatar/small/<?= $flow['avatar']; ?>">
|
||||
<span class="user">
|
||||
<a href="/u/<?= $flow['login']; ?>"><?= $flow['login']; ?></a>
|
||||
</span>
|
||||
<span class="date">
|
||||
<?= $flow['flow_pubdate']; ?>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<?= $flow['flow_content']; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php } else { ?>
|
||||
|
||||
<div class="no-content"><?= lang('no-post'); ?>...</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php include TEMPLATE_DIR . '/flow/flow-form.php'; ?>
|
||||
</div>
|
||||
</main>
|
||||
<?php include TEMPLATE_DIR . '/footer.php'; ?>
|
|
@ -40,7 +40,7 @@
|
|||
<li class="nav no-mob">
|
||||
<h1 class="space">
|
||||
<div class="space-color space_<?= $space_info['space_color'] ?>"></div>
|
||||
<a href="/s/<?= $space_info['space_slug']; ?>">
|
||||
<a class="space-u" href="/s/<?= $space_info['space_slug']; ?>">
|
||||
<?= $space_info['space_name']; ?>
|
||||
</a>
|
||||
</h1>
|
||||
|
|
|
@ -60,9 +60,7 @@
|
|||
|
||||
<?php } else { ?>
|
||||
|
||||
<h3>Нет постов (в разработке)</h3>
|
||||
|
||||
<p>К сожалению поcтов по данному пространству нет...</p>
|
||||
<div class="no-content"><?= lang('no-post'); ?>...</div>
|
||||
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
|
|
@ -37,6 +37,8 @@ Route::before('Authorization@noAuth')->getGroup();
|
|||
|
||||
Route::get('/logout')->controller('AuthController@logout');
|
||||
|
||||
Route::type('post')->protect()->get('/flow/add')->controller('FlowController@chatAdd');
|
||||
|
||||
// Добавление комментария / удаление
|
||||
Route::type('post')->get('/comments/editform')->controller('CommentController@editform');
|
||||
Route::type('post')->protect()->get('/comment/edit')->controller('CommentController@editComment');
|
||||
|
@ -111,6 +113,9 @@ Route::get('/threads/{login}')->controller('CommentController@userComments')->wh
|
|||
// Страница постов участника
|
||||
Route::get('/newest/{login}')->controller('PostController@userPosts')->where(['login' => '[A-Za-z0-9]+']);
|
||||
|
||||
// Поток
|
||||
Route::get('/flow')->controller('FlowController');
|
||||
|
||||
// Все комментарии
|
||||
Route::get('/comments')->controller('CommentController');
|
||||
|
||||
|
|
Loading…
Reference in a new issue