From c2031769cf2ce23559ef9c51b2d85757546b4112 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Sat, 16 Jul 2022 00:17:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20PHP=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=BD=D0=B0=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BC=D0=B5=D1=82=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/phpcmd.php | 140 +++++++++++++++--------- core/lib/Core/Models/UserMeta.class.php | 47 +------- 2 files changed, 95 insertions(+), 92 deletions(-) diff --git a/admin/phpcmd.php b/admin/phpcmd.php index 55ff71c..448078d 100644 --- a/admin/phpcmd.php +++ b/admin/phpcmd.php @@ -23,8 +23,24 @@ require_once __DIR__ . '/inc/header.php'; + global $USER; + if (isset($_REQUEST['execute']) && $_REQUEST['execute'] == 'Y') { $_SESSION['phpcmd_query'] = $_REQUEST['query']; + + if (isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y') { + $arQuery = explode(PHP_EOL, $_REQUEST['query']); + if (stristr($arQuery[0], '//title: ')) { + $queryName = str_replace('//title: ', '', $arQuery[0]); + } else { + $queryName = 'PHP код ' . date('d.m H:i'); + } + $USER->getMetaObject()->addMeta('code', serialize(['name' => $queryName, 'code' => $_REQUEST['query']])); + } + } + + if (isset($_REQUEST['delMeta'])) { + $USER->getMetaObject()->deleteMeta($_REQUEST['delMeta']); } ?> + \ No newline at end of file diff --git a/core/lib/Core/Models/UserMeta.class.php b/core/lib/Core/Models/UserMeta.class.php index d9da7e8..39784fc 100644 --- a/core/lib/Core/Models/UserMeta.class.php +++ b/core/lib/Core/Models/UserMeta.class.php @@ -42,7 +42,6 @@ foreach ($res as $meta) { $userMeta[] = [ 'id' => $meta['id'], - 'type' => $meta['type'], 'name' => $meta['name'], 'value' => $meta['value'], ]; @@ -75,40 +74,6 @@ foreach ($res as $meta) { $userMeta[] = [ 'id' => $meta['id'], - 'type' => $meta['type'], - 'name' => $meta['name'], - 'value' => $meta['value'], - ]; - } - Cache::set($cacheId, $userMeta); - } - } - return $userMeta; - } - - /** - * Получает указанные мета данные пользователя - * - * @param string|null $type Тип мета - * - * @return array|null - * @throws \Core\CoreException - */ - public function getMetaByType(string $type): ?array - { - $cacheId = md5('Meta_' . $this->user->getId() . '_getMetaByType'); - if (Cache::check($cacheId)) { - $userMeta = Cache::get($cacheId); - } else { - /** @var $DB DB */ - $DB = DB::getInstance(); - $res = $DB->query('SELECT * FROM `' . self::TABLE . '` WHERE user_id=' . $this->user->getId() . ' AND type="' . $type . '"'); - if (!empty($res)) { - $userMeta = []; - foreach ($res as $meta) { - $userMeta[] = [ - 'id' => $meta['id'], - 'type' => $meta['type'], 'name' => $meta['name'], 'value' => $meta['value'], ]; @@ -129,32 +94,32 @@ * @return int|null * @throws \Core\CoreException */ - public function addMeta(string $name, ?string $value = null, string $type = 'default'): ?int + public function addMeta(string $name, ?string $value = null): ?int { $cacheId = md5('Meta_' . $this->user->getId() . '_getAllMeta'); Cache::delete($cacheId); /** @var $DB DB */ $DB = DB::getInstance(); - return $DB->addItem(self::TABLE, ['user_id' => $this->user->getId(), 'name' => $name, 'value' => $value, 'type' => $type]); + return $DB->addItem(self::TABLE, ['user_id' => $this->user->getId(), 'name' => $name, 'value' => $value]); } /** * Убирает пользователю указанные мета данные * - * @param string $name Имя мета + * @param int $id ID Мета * - * @return int|null + * @return void * @throws \Core\CoreException */ - public function deleteMeta(string $name): void + public function deleteMeta(int $id): void { $cacheId = md5('Roles_' . $this->user->getId() . '_getRoles'); Cache::delete($cacheId); /** @var $DB DB */ $DB = DB::getInstance(); - $DB->query('DELETE FROM ' . self::TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND name="' . $name . '"'); + $DB->query('DELETE FROM ' . self::TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND id="' . $id . '"'); } } \ No newline at end of file