diff --git a/README.md b/README.md index 6a831a8..0fc7b0e 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,23 @@ [![GitHub license](https://img.shields.io/github/license/Gokujo/dle_api.svg?style=flat-square)](https://github.com/Gokujo/dle_api/blob/master/LICENSE) ![DLE-13.x](https://img.shields.io/badge/DLE-13.x-green.svg?style=flat-square) +![MySQL-5.5.6](https://img.shields.io/badge/MySQL-5.5.6-red.svg?style=flat-square) -![Версия_релиза](https://img.shields.io/badge/Version-1.0-orange.svg?style=flat-square) +![Версия_релиза](https://img.shields.io/badge/Version-0.1.3-orange.svg?style=flat-square) ![Версия_релиза](https://img.shields.io/badge/Version-BETA-orange.svg?style=flat-square) # DLE API Модификация для админпанели и глобальные функции для моих разработок -Совместимость проверенна на DLE-версиях 13.х +Совместимость проверенна на DLE-версиях 13.х. Для корректной работы требуется минимальная версия MySQL 5.5.6 или MariaDB 10.0, поскольку используются Foreign Key, которые требуют наличие InnoDB. -Для установки достаточно скачать [релиз](https://github.com/Gokujo/dle_api/releases). +Для установки достаточно скачать [релиз](https://github.com/Gokujo/dle_api/releases/latest). Документация к API находится на сервере [POSTMAN](https://documenter.getpostman.com/view/7856564/SW7T9BsW). На данный момент она не полная и пополняется медлено, но верно. Релизы выше только для версий DLE 13 и выше. Для пожеланий можно использовать [feathub](https://feathub.com/Gokujo/dle_api). [![Feature Requests](https://feathub.com/Gokujo/dle_api?format=svg)](https://feathub.com/Gokujo/dle_api) + # DLE >= 13.x Скачайте релиз. У вас три варианта для установки: 1. **При помощи bat-Скрипта. Для пользователей Windows** @@ -30,4 +32,56 @@ Затем устанавливаем архив через менеджер плагинов. 1. **Просто залить** -Залейте папку **engine** в корень сайта и установите плагин через менеджер плагинов. \ No newline at end of file +Залейте папку **engine** в корень сайта и установите плагин через менеджер плагинов. + + + +# DLE < 13 +В теории, и на движках младше всё должно работать, поскольку в процессе не затрагиваются файлы движка. Но, это не точно, я не пробовал, не эксперементировал. На свой страх и риск. + +## Установка +Залить папки **api** и **engine** из папки **upload** в корень сайта. Затем выполнить запрос в базу данных: + +```SQL +CREATE TABLE {prefix}_api_keys ( + id int auto_increment + primary key, + api varchar(255) not null, + is_admin tinyint(1) default 0 not null, + creator int default 0 null, + created datetime default CURRENT_TIMESTAMP not null, + active tinyint(1) default 0 not null, + user_id int default 0 not null, + constraint {prefix}_api_keys_key_uindex + unique (api) +); + +create table {prefix}_api_scope ( + scope_id int auto_increment + primary key, + `table` varchar(255) null, + `read` tinyint(1) default 0 not null, + `write` tinyint(1) default 0 not null, + `delete` tinyint(1) default 0 not null, + key_id int default 0 not null, + constraint {prefix}_api_scope_{prefix}_api_keys_id_fk + foreign key (key_id) references {prefix}_api_keys (id) + on update cascade on delete cascade +); + +INSERT INTO {prefix}_admin_sections (name, title, descr, icon, allow_groups) VALUES ('dleapi', 'DLE-API', 'Неофициальное API для DLE. Раздел по созданию и управлению над ключами доступа к API.', '/engine/skins/images/icons/dleapi.png', 1); +``` + + +## Удаление +Удаляем **из корня** сайта папку **api**, a так-же из папки **engine/inc** файл **dleapi.php** и из **engine/skins/images** файл **dleapi.png**. + +Выполняем запрос в базу данных: + + +```SQL +DELETE FROM {prefix}_admin_sections WHERE `name` = 'dleapi'; +DROP TABLE {prefix}_api_keys cascade, {prefix}_api_scope cascade; +``` + +**{prefix}** заменяем на свой префикс базы данных. diff --git a/manifest.json b/manifest.json index 477eeb3..b59ca2e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,4 +1,4 @@ { - "version": "1.0.1", + "version": "0.1.3", "name": "DLE API" -} \ No newline at end of file +} diff --git a/upload/api/composer.json b/upload/api/composer.json index 209c89c..67e725a 100644 --- a/upload/api/composer.json +++ b/upload/api/composer.json @@ -1,13 +1,13 @@ { - "config": { - "platform": { - "php": "5.6.19" - } - }, "require": { "ext-json": "*", - "slim/slim": "*", + "slim/slim": "^3.12", "monolog/monolog": "*", "ext-pdo": "*" + }, + "config": { + "platform": { + "php": "5.6" + } } } diff --git a/upload/api/composer.lock b/upload/api/composer.lock index 3d2a9ec..1dfcece 100644 --- a/upload/api/composer.lock +++ b/upload/api/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eb44020867ecd69735b90e59114a7da0", + "content-hash": "6a9b55f2d468c78a3738f7867403c4a2", "packages": [ { "name": "monolog/monolog", @@ -442,7 +442,7 @@ }, "platform-dev": [], "platform-overrides": { - "php": "5.6.19" + "php": "5.6" }, "plugin-api-version": "2.0.0" } diff --git a/upload/api/includes/functions.php b/upload/api/includes/functions.php index b69f23c..e973614 100644 --- a/upload/api/includes/functions.php +++ b/upload/api/includes/functions.php @@ -134,7 +134,7 @@ public function __construct ($module, $id = '', $data = '', $app = 'full', $path /** * @param string $cachePath */ - public function setCachePath (string $cachePath) { + public function setCachePath ($cachePath) { $this->cachePath = $cachePath; } diff --git a/upload/api/index.php b/upload/api/index.php index 4c47f62..33fa7ca 100644 --- a/upload/api/index.php +++ b/upload/api/index.php @@ -2,7 +2,7 @@ /** * @author Maxim Harder - * @copyright 2019 DevCraft.club + * @copyright 2019-2021 DevCraft.club * * Приложение должно заменить стандартный API самого DLE и предоставить альтернативный вариант. * Использовать на свой страх и риск! @@ -26,6 +26,7 @@ require_once ENGINE_DIR.'/classes/plugins.class.php'; include_once DLEPlugins::Check(API_DIR.'/includes/functions.php'); + include_once DLEPlugins::Check(ENGINE_DIR.'/inc/includes/functions.inc.php'); $config = [ 'settings' => [ @@ -41,6 +42,5 @@ // Подключаем файл-роутер и запускаем главную функцию include_once DLEPlugins::Check(API_DIR.'/routes/_router.php'); - -?> \ No newline at end of file +?> diff --git a/upload/api/routes/_router.php b/upload/api/routes/_router.php index 72bed50..49d61fa 100644 --- a/upload/api/routes/_router.php +++ b/upload/api/routes/_router.php @@ -16,6 +16,7 @@ return $logger; }; + $app->group('/v1', function (App $app) use ($connect) { include_once (DLEPlugins::Check(API_DIR . '/routes/admin_logs.php')); include_once (DLEPlugins::Check(API_DIR . '/routes/admin_sections.php')); @@ -74,4 +75,4 @@ // Own path add }); - $app->run(); \ No newline at end of file + $app->run(); diff --git a/upload/api/routes/admin_logs.php b/upload/api/routes/admin_logs.php index 0172c3a..e8204a6 100644 --- a/upload/api/routes/admin_logs.php +++ b/upload/api/routes/admin_logs.php @@ -9,6 +9,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; $api_name = "admin_logs"; + $possibleData = array( array( 'name' => 'id', @@ -64,6 +65,7 @@ // ); // possibleData Add ); + $app->group('/' . $api_name, function ( ) use ( $connect, $api_name, $possibleData ) { $header = array(); $access = array( @@ -73,6 +75,7 @@ 'can_delete' => false, ); + $this->get('[/]', function (Request $request, Response $response, Array $args) use ($possibleData, $api_name, $connect, $header, $access ) { foreach ( $request->getHeaders() as $name => $value ) { $name = strtolower(str_replace('HTTP_', '', $name)); @@ -80,7 +83,9 @@ } $checkAccess = checkAPI($header['x_api_key'], $api_name); - if (isset($checkAccess['error'])) return $response->withStatus(400)->getBody()->write(json_encode(array('error' => $checkAccess['error']))); + if (isset($checkAccess['error'])) { + return $response->withStatus(400)->getBody()->write(json_encode(array('error' => $checkAccess['error']))); + } $access['full'] = $checkAccess['admin']; $access['can_read'] = $checkAccess['read']; @@ -112,6 +117,7 @@ } else $data = json_decode($getData->get(), true); + $response->withStatus( 200 )->getBody()->write( json_encode( $data ) ); } else { diff --git a/upload/api/routes/comments.php b/upload/api/routes/comments.php index 1a14580..3983332 100644 --- a/upload/api/routes/comments.php +++ b/upload/api/routes/comments.php @@ -321,6 +321,7 @@ $sql = 'DELETE FROM '. PREFIX . "_{$api_name} WHERE id = {$id}"; $connect->query( $sql ); + deletecomments($id); $cache = new CacheSystem($api_name, $sql); $cache->clear($api_name); diff --git a/upload/api/routes/post.php b/upload/api/routes/post.php index 6abb67a..964da5b 100644 --- a/upload/api/routes/post.php +++ b/upload/api/routes/post.php @@ -370,6 +370,8 @@ $sql = 'DELETE FROM '. PREFIX . "_{$api_name} WHERE id = {$id}"; $connect->query( $sql ); + deletenewsbyid($id); + deletecommentsbynewsid($id); $cache = new CacheSystem($api_name, $sql); $cache->clear($api_name); diff --git a/upload/api/vendor/composer/InstalledVersions.php b/upload/api/vendor/composer/InstalledVersions.php index a405b1a..0ca68e0 100644 --- a/upload/api/vendor/composer/InstalledVersions.php +++ b/upload/api/vendor/composer/InstalledVersions.php @@ -24,24 +24,24 @@ class InstalledVersions private static $installed = array ( 'root' => array ( - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', 'aliases' => array ( ), - 'reference' => '4753cb6bc670bb60bbf409046c37571a4efa8304', + 'reference' => '9e1c17f28a7703c5f3abb7577844728a67f21d4c', 'name' => '__root__', ), 'versions' => array ( '__root__' => array ( - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', 'aliases' => array ( ), - 'reference' => '4753cb6bc670bb60bbf409046c37571a4efa8304', + 'reference' => '9e1c17f28a7703c5f3abb7577844728a67f21d4c', ), 'monolog/monolog' => array ( diff --git a/upload/api/vendor/composer/installed.json b/upload/api/vendor/composer/installed.json index 4e80755..110d986 100644 --- a/upload/api/vendor/composer/installed.json +++ b/upload/api/vendor/composer/installed.json @@ -189,6 +189,10 @@ "container", "dependency injection" ], + "support": { + "issues": "https://github.com/silexphp/Pimple/issues", + "source": "https://github.com/silexphp/Pimple/tree/master" + }, "install-path": "../pimple/pimple" }, { @@ -241,6 +245,10 @@ "container-interop", "psr" ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/master" + }, "install-path": "../psr/container" }, { diff --git a/upload/api/vendor/composer/installed.php b/upload/api/vendor/composer/installed.php index 81b87c5..8cc92f4 100644 --- a/upload/api/vendor/composer/installed.php +++ b/upload/api/vendor/composer/installed.php @@ -1,24 +1,24 @@ array ( - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', 'aliases' => array ( ), - 'reference' => '4753cb6bc670bb60bbf409046c37571a4efa8304', + 'reference' => '9e1c17f28a7703c5f3abb7577844728a67f21d4c', 'name' => '__root__', ), 'versions' => array ( '__root__' => array ( - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', 'aliases' => array ( ), - 'reference' => '4753cb6bc670bb60bbf409046c37571a4efa8304', + 'reference' => '9e1c17f28a7703c5f3abb7577844728a67f21d4c', ), 'monolog/monolog' => array ( diff --git "a/\320\237\321\200\320\276\321\207\321\202\320\270 \320\274\320\265\320\275\321\217.txt" "b/\320\237\321\200\320\276\321\207\321\202\320\270 \320\274\320\265\320\275\321\217.txt" index 6e46391..2ce651d 100644 --- "a/\320\237\321\200\320\276\321\207\321\202\320\270 \320\274\320\265\320\275\321\217.txt" +++ "b/\320\237\321\200\320\276\321\207\321\202\320\270 \320\274\320\265\320\275\321\217.txt" @@ -1,16 +1,57 @@ -DLE-API -Модификация для админпанели и глобальные функции для моих разработок Совместимость проверенна на DLE-версиях 13.х - -Для установки достаточно скачать релиз. Релизы выше только для версий DLE 13 и выше. - -Хотите что-то увидеть в следующем релизе? Тогда вам сюда: https://feathub.com/Gokujo/dle_api -Документация по API (не полная): https://documenter.getpostman.com/view/7856564/SW7T9BsW +DLE API +Модификация для админпанели и глобальные функции для моих разработок Совместимость проверенна на DLE-версиях 13.х. Для корректной работы требуется минимальная версия MySQL 5.5.6 или MariaDB 10.0, поскольку используются Foreign Key, которые требуют наличие InnoDB. +Для установки достаточно скачать релиз (https://github.com/Gokujo/dle_api/releases/latest). +Документация к API находится на сервере POSTMAN (https://documenter.getpostman.com/view/7856564/SW7T9BsW). +На данный момент она не полная и пополняется медлено, но верно. Релизы выше только для версий DLE 13 и выше. +Для пожеланий можно использовать feathub (https://feathub.com/Gokujo/dle_api)). DLE >= 13.x Скачайте релиз. У вас три варианта для установки: -При помощи bat-Скрипта. Для пользователей Windows Для этого устанавливаем 7Zip. После установки запускаем скрипт install_archive.bat. После завершения установки - загружаем maharder_assets.zip в менеджер плагинов. +1. При помощи bat-Скрипта. Для пользователей Windows Для этого устанавливаем 7Zip (https://www.7-zip.org/download.html). После установки запускаем скрипт install_archive.bat. После завершения установки - загружаем install.zip в менеджер плагинов. +2. Упаковать самому Любым архиватором запаковать всё содержимое в папке upload, причём так, чтобы в корне архива был файл install.xml и папка engine. Затем устанавливаем архив через менеджер плагинов. +3. Просто залить Залейте папку engine в корень сайта и установите плагин через менеджер плагинов. + +DLE < 13 +В теории, и на движках младше всё должно работать, поскольку в процессе не затрагиваются файлы движка. Но, это не точно, я не пробовал, не эксперементировал. На свой страх и риск. + +Установка +Залить папки api и engine из папки upload в корень сайта. Затем выполнить запрос в базу данных: + +CREATE TABLE {prefix}_api_keys ( + id int auto_increment + primary key, + api varchar(255) not null, + is_admin tinyint(1) default 0 not null, + creator int default 0 null, + created datetime default CURRENT_TIMESTAMP not null, + active tinyint(1) default 0 not null, + user_id int default 0 not null, + constraint {prefix}_api_keys_key_uindex + unique (api) +); + +create table {prefix}_api_scope ( + scope_id int auto_increment + primary key, + `table` varchar(255) null, + `read` tinyint(1) default 0 not null, + `write` tinyint(1) default 0 not null, + `delete` tinyint(1) default 0 not null, + key_id int default 0 not null, + constraint {prefix}_api_scope_{prefix}_api_keys_id_fk + foreign key (key_id) references {prefix}_api_keys (id) + on update cascade on delete cascade +); + +INSERT INTO {prefix}_admin_sections (name, title, descr, icon, allow_groups) VALUES ('dleapi', 'DLE-API', 'Неофициальное API для DLE. Раздел по созданию и управлению над ключами доступа к API.', '/engine/skins/images/icons/dleapi.png', 1); + + +Удаление +Удаляем из корня сайта папку api, a так-же из папки engine/inc файл dleapi.php и из engine/skins/images файл dleapi.png. -Упаковать самому Любым архиватором запаковать всё содержимое в папке upload, причём так, чтобы в корне архива был файл install.xml и папка engine. Затем устанавливаем архив через менеджер плагинов. +Выполняем запрос в базу данных: -Просто залить Залейте папку engine в корень сайта и установите плагин через менеджер плагинов. \ No newline at end of file +DELETE FROM {prefix}_admin_sections WHERE `name` = 'dleapi'; +DROP TABLE {prefix}_api_keys cascade, {prefix}_api_scope cascade; +{prefix} заменяем на свой префикс базы данных.