From e8be354a1f0a76bcbe506ff7598f49b8704a0efc Mon Sep 17 00:00:00 2001
From: rsgrinko
Date: Mon, 24 Jul 2023 18:17:59 +0300
Subject: [PATCH] =?UTF-8?q?[*]=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?=
=?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D1=82=D0=B8=D0=BB=D1=8C=20=D0=B4=D0=B8?=
=?UTF-8?q?=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
assets/css/style.css | 71 ++++++++-
core/lib/Core/App.class.php | 20 ++-
core/lib/Core/Models/Dialog.class.php | 29 +++-
core/lib/Core/Models/User.class.php | 5 +-
core/routes.php | 2 +
phpcmd.php | 202 --------------------------
templates/dialog.twig | 165 ++++++---------------
templates/dialogs.twig | 129 ++++------------
8 files changed, 196 insertions(+), 427 deletions(-)
delete mode 100644 phpcmd.php
diff --git a/assets/css/style.css b/assets/css/style.css
index a8115f6..1636fce 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -128,4 +128,73 @@ body {
}
.table tbody tr:nth-child(even){
background: #F7F7F7;
-}
\ No newline at end of file
+}
+
+
+.main textarea {
+ width: 100%;
+ resize: vertical;
+ padding: 15px;
+ height: 150px;
+ border: 1px solid #00abff;
+ margin-bottom: 10px;
+}
+
+.main .w100 {
+ width: 100%;
+}
+.main .button {
+ background: #00abff;
+ color: white;
+ border: 0;
+ padding: 10px;
+ cursor: pointer;
+}
+
+.main .button:hover {
+ background: #0085c7;
+}
+
+.main .messageBox {
+ display: flex;
+ flex-direction: column;
+}
+
+.main .messageBox .message {
+ width: 300px;
+ padding: 20px 10px;
+ position: relative;
+ background: #eee;
+ border-radius: 3px;
+ margin-bottom: 10px;
+}
+
+.main .messageBox .message.fromMe {
+ align-self: end;
+ background: #00abff;
+ color: white;
+}
+
+.main .messageBox .message.fromCompanion:before {
+ content: "";
+ border: solid transparent;
+ position: absolute;
+ right: 100%;
+ top: 50%;
+ border-right-color: #eee;
+ border-width: 9px;
+ margin-top: -9px;
+}
+
+.main .messageBox .message.fromMe:before {
+ content: "";
+ border: solid transparent;
+ position: absolute;
+ left: 100%;
+ top: 50%;
+ border-right-color: #eeeeee;
+ border-width: 9px;
+ margin-top: -9px;
+ transform: rotate(180deg);
+}
+
diff --git a/core/lib/Core/App.class.php b/core/lib/Core/App.class.php
index 05ccdd7..d271142 100644
--- a/core/lib/Core/App.class.php
+++ b/core/lib/Core/App.class.php
@@ -96,7 +96,7 @@
public static function dialogs()
{
global $USER;
- self::render('dialogs.twig', ['dialogs' => $USER->getDialogs()]);
+ self::render('dialogs.twig', ['dialogs' => User::isAuthorized() ? $USER->getDialogs() : []]);
}
/**
@@ -108,7 +108,23 @@
public static function dialog(int $id)
{
global $USER;
- self::render('dialog.twig', ['messages' => $USER->getMessages($id, true), 'userId' => $USER->getId()]);
+ self::render(
+ 'dialog.twig',
+ [
+ 'dialog_id' => $id,
+ 'messages' => $USER->getMessages($id, true),
+ 'userId' => $USER->getId(),
+ 'companionId' => $USER->getDialogObject()->getDialogCompanionId($id),
+ 'companionName' => (new User($USER->getDialogObject()->getDialogCompanionId($id)))->getName(),
+ ]
+ );
+ }
+
+ public static function sendMessage(int $userId)
+ {
+ global $USER;
+ $USER->getDialogObject()->sendMessage($userId, $_REQUEST['message']);
+ header('Location: /dialog/' . (int)$_REQUEST['dialogId']);
}
diff --git a/core/lib/Core/Models/Dialog.class.php b/core/lib/Core/Models/Dialog.class.php
index 52b90a0..f68ed98 100644
--- a/core/lib/Core/Models/Dialog.class.php
+++ b/core/lib/Core/Models/Dialog.class.php
@@ -78,10 +78,37 @@
return $dialogs;
}
+ /**
+ * Получения ID собеседника диалога
+ *
+ * @param int $dialogId Идентификатор диалога
+ *
+ * @return int|null Идентификатор собеседника
+ * @throws CoreException
+ */
+ public function getDialogCompanionId(int $dialogId): ?int
+ {
+ /** @var $DB DB Объект базы данных */
+ $DB = DB::getInstance();
+ $dialog = $DB->query('SELECT * FROM ' . self::TABLE_DIALOGS . ' WHERE `id`="' . $dialogId . '"');
+ if (empty($dialog)) {
+ return null;
+ }
+ $dialog = array_shift($dialog);
+ if ((int)$dialog['send'] === $this->user->getId()) {
+ return (int)$dialog['receive'];
+ } elseif ((int)$dialog['receive'] === $this->user->getId()) {
+ return (int)$dialog['send'];
+ }
+
+ return null;
+ }
+
/**
* Получение сообщений диалога
*
- * @param int $dialogId
+ * @param int $dialogId Идентификатор диаолога
+ * @param bool $markDialogViewed Пометить диалог прочитанным
*
* @return array
* @throws CoreException
diff --git a/core/lib/Core/Models/User.class.php b/core/lib/Core/Models/User.class.php
index 8ad187a..746d962 100644
--- a/core/lib/Core/Models/User.class.php
+++ b/core/lib/Core/Models/User.class.php
@@ -134,6 +134,7 @@
} else {
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
$result = array_merge($result, ['roles' => $this->getRolesObject()->getRoles()]);
+ $result['nameForDisplay'] = '[' . $result['id'] . '] (' . $result['login'] . ') ' . $result['name'];
// В случае запроса безопасных данных убираем лишнее
if ($onlySecureData) {
@@ -901,8 +902,8 @@
{
$dialogs = $this->getDialogObject()->getDialogs();
foreach ($dialogs as $key => $dialog) {
- $dialogs[$key]['send_user_data'] = (new self((int)$dialog['send']))->getAllUserData(true);
- $dialogs[$key]['receive_user_data'] = (new self((int)$dialog['receive']))->getAllUserData(true);
+ $dialogs[$key]['companionId'] = $this->getDialogObject()->getDialogCompanionId((int)$dialog['id']);
+ $dialogs[$key]['companionData'] = (new self((int)$dialogs[$key]['companionId']))->getAllUserData(true);
}
return $dialogs;
diff --git a/core/routes.php b/core/routes.php
index 01cb445..06f3f75 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -30,6 +30,8 @@
Router::route('/dialogs', '\Core\App::dialogs');
Router::route('/dialog/(\d+)', '\Core\App::dialog');
+ Router::route('/users/(\d+)/sendMessage', '\Core\App::sendMessage');
+
Router::route('/404', function () {
header('HTTP/1.0 404 Not Found');
echo '404 - Page Not Found';
diff --git a/phpcmd.php b/phpcmd.php
deleted file mode 100644
index 1154484..0000000
--- a/phpcmd.php
+++ /dev/null
@@ -1,202 +0,0 @@
-
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- die();
- use Core\DataBases\DB;
- use Core\Helpers\{Cache, Files};
- use Core\Models\{User};
-
- require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
- /** @var $USER User */
- global $USER;
-?>
-
-
-
-
-
-
-
- Главная тестовая
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Командная строка PHP
- isAdmin()) { ?>
-
-
-
-
- Результат
';
-
- try {
- if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
- echo '
';
- }
- eval($_REQUEST['query']);
- if (isset($_REQUEST['use_pre']) and $_REQUEST['use_pre'] == 'Y') {
- echo '';
- }
- } catch (ParseError $p) {
- echo '
(ParseError) Ошибка парсинга: ' . $p->getMessage() . '
';
- } catch (Throwable $e) {
- echo '
(Throwable) Ошибка при выполнении: ' . $e->getMessage()
- . '
';
- } catch (Error $e) {
- echo '
(Error) Ошибка при выполнении: ' . $e->getMessage() . '
';
- }
- echo '';
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
';
-
- ?>
- © = date('Y'); ?> Delta Project
-
-
-
-
diff --git a/templates/dialog.twig b/templates/dialog.twig
index 3a14a81..e65ea75 100644
--- a/templates/dialog.twig
+++ b/templates/dialog.twig
@@ -1,129 +1,56 @@
-
-
-
-
-
-
-
-
- Главная тестовая
-
-
-
-