Skip to content

Commit

Permalink
Merge branch 'rel/2.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gokujo committed Jun 17, 2022
2 parents 8df9a23 + 2ff45ae commit 77f69f4
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 123 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.5 Beta",
"version": "2.0.6",
"status": "dev",
"dle": [
"13.x",
Expand Down
2 changes: 1 addition & 1 deletion upload/engine/inc/maharder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$modInfo = [
'module_name' => 'MaHarder Assets',
'module_version' => '2.0.4',
'module_version' => '2.0.6',
'module_description' => 'Административная панель для моих разработок',
'module_code' => 'maharder',
'module_icon' => 'fad fa-robot',
Expand Down
17 changes: 10 additions & 7 deletions upload/engine/inc/maharder/_includes/classes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ public function __construct() {
$this->setVar('js', $this->htmlStatic($this->jsArr, 'html', 'js'));
$this->preSetMenu();
$mh_settings = $this->getConfig('maharder');
$this->logs = isset($mh_settings['logs']);
if(file_exists(ENGINE_DIR . '/inc/maharder/admin/assets/css/dark.css')) if(isset($mh_settings['theme'])
&& $mh_settings['theme']
=== 'dark') $this->setCss(
URL . '/maharder/admin/assets/css/dark.css'
);

$this->setLogs(isset($mh_settings['logs']));
$this->setTelegramType($mh_settings["logs_telegram_type"]);
$this->setTelegramBot($mh_settings["logs_telegram_api"]);
$this->setTelegramChannel($mh_settings["logs_telegram_channel"]);
$this->setTelegramSend(isset($mh_settings["logs_telegram"]));
if(file_exists(ENGINE_DIR . '/inc/maharder/admin/assets/css/dark.css')) {
if(isset($mh_settings['theme']) && $mh_settings['theme'] === 'dark') {
$this->setCss(URL . '/maharder/admin/assets/css/dark.css');
}
}
if(!mkdir($cache_folder = $this->getCacheFolder(), 0755, true) && !is_dir($cache_folder)) {
$this->generate_log('maharder', 'construct', sprintf('Directory "%s" was not created', $cache_folder));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ protected static function getModulesUrl() {
: self::getThisSelf() . "?{self::getServerData()['QUERY_STRING']}");
}

public function parseUrl(string $url) : string {
public function parseUrl(string $url)
: string {
$parts = parse_url(trim(str_replace(['&', '\t', '\n'], ['&', '', ''], $url)));
parse_str($parts['query'], $_url_data);

foreach ($_url_data as $param => $value) {
foreach($_url_data as $param => $value) {
$_url_data[$param] = $value;
}

Expand All @@ -77,7 +78,8 @@ public function parseUrl(string $url) : string {
return "{$url_path}?" . http_build_query($_url_data);
}

public function getGlobals() : array {
public function getGlobals()
: array {

return [
'assets_url' => self::getAssetsUrl(), 'plugin_url' => self::getModulesUrl(),
Expand Down
9 changes: 9 additions & 0 deletions upload/engine/inc/maharder/_includes/classes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ class Ajax {
use LogGenerator;
use DataLoader;
use AssetsChecker;

public function __construct() {
$mh_settings = $this->getConfig('maharder');
$this->setLogs(isset($mh_settings['logs']));
$this->setTelegramType($mh_settings["logs_telegram_type"]);
$this->setTelegramBot($mh_settings["logs_telegram_api"]);
$this->setTelegramChannel($mh_settings["logs_telegram_channel"]);
$this->setTelegramSend(isset($mh_settings["logs_telegram"]));
}
}
7 changes: 7 additions & 0 deletions upload/engine/inc/maharder/_includes/classes/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class Model {
public function __construct(string $model_name, string $table_name, string $id_name, array $vars, array $table_keys = []) {
$this->table = new Table($id_name, $table_name, $model_name, $vars, $table_keys);
$this->table->checkMigrations();

$mh_settings = $this->getConfig('maharder');
$this->setLogs(isset($mh_settings['logs']));
$this->setTelegramType($mh_settings["logs_telegram_type"]);
$this->setTelegramBot($mh_settings["logs_telegram_api"]);
$this->setTelegramChannel($mh_settings["logs_telegram_channel"]);
$this->setTelegramSend(isset($mh_settings["logs_telegram"]));
}


Expand Down
7 changes: 7 additions & 0 deletions upload/engine/inc/maharder/_includes/classes/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public function __construct(
if($now !== 0) $this->setNow($now); else $this->setNow();
$this->setPrefix($name);
foreach($col_keys as $key) $this->setColKeys($this->setKey($key['name'], $key));

$mh_settings = $this->getConfig('maharder');
$this->setLogs(isset($mh_settings['logs']));
$this->setTelegramType($mh_settings["logs_telegram_type"]);
$this->setTelegramBot($mh_settings["logs_telegram_api"]);
$this->setTelegramChannel($mh_settings["logs_telegram_channel"]);
$this->setTelegramSend(isset($mh_settings["logs_telegram"]));
}

/**
Expand Down
194 changes: 174 additions & 20 deletions upload/engine/inc/maharder/_includes/traits/LogGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if ( ! class_exists('Monolog\Logger')) {
if(!class_exists('Monolog\Logger')) {
include_once ENGINE_DIR . '/inc/maharder/_includes/vendor/autoload.php';
}

Expand All @@ -9,30 +9,61 @@
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\FirePHPHandler;
use Monolog\Handler\TelegramBotHandler;

trait LogGenerator {

/**
* Регулятор логирования системы
*
* @var bool|int
*/
protected int $logs = 0;

/**
* Генерация лог-файлов, если по какой-то прочине произошла ошибка во время исполнения функционала
* Регулятор отправки логов в телеграм канал
* По умолчанию - выключен
*
* @var bool
*/
protected bool $telegram_send = false;
/**
* ID канала, куда будут отправляться логи
*
* @param $service
* @param $function_name
* @var int|string|null
*/
protected $telegram_channel = null;
/**
* API телеграм бота, который будет отправлять логи
*
* @var string|null
*/
protected ?string $telegram_bot = null;
/**
* Тип логов, которые будут отправлены в телеграм
*
* @var string|null
*/
protected ?string $telegram_type = null;

/**
* Генерация лог-файлов, если по какой-то причине произошла ошибка во время исполнения функционала
*
* @param string $service
* @param string $function_name
* @param $message
* @param $type
* @param string $type
*
* @throws \Monolog\Handler\MissingExtensionException
*/
public function generate_log($service, $function_name, $message, $type = 'error'): void {
if ($this->getLogs()) {
public function generate_log(string $service, string $function_name, $message, string $type = 'error')
: void {
if($this->getLogs()) {
$root_dir = dirname(__DIR__, 2);
$date = date('[Y-m-d] d.m.Y, H:i');
$date = date('Y-m-d d.m.Y H:i');
$concurrentDirectory = $root_dir . '/_logs/' . $service . '/' . $function_name;

if (!mkdir($concurrentDirectory, 0777, true) && !is_dir($concurrentDirectory)) {
if(!mkdir($concurrentDirectory, 0777, true) && !is_dir($concurrentDirectory)) {
echo "<b>Уведомление</b>:{$type}<br>";
echo "<b>Модуль</b>:{$service}<br>";
echo "<b>Функция</b>:{$function_name}<br>";
Expand All @@ -46,7 +77,7 @@ public function generate_log($service, $function_name, $message, $type = 'error'

$logger = new Logger($service);

switch ($type) {
switch($type) {
case 'error':
$log_level = Logger::ERROR;
break;
Expand All @@ -73,6 +104,10 @@ public function generate_log($service, $function_name, $message, $type = 'error'
$log_level = Logger::ALERT;
break;

case 'emergency':
$log_level = Logger::EMERGENCY;
break;

case 'Debug':
case 'debug':
default:
Expand All @@ -84,13 +119,64 @@ public function generate_log($service, $function_name, $message, $type = 'error'
$logger->pushHandler(new ChromePHPHandler($log_level));
$logger->pushHandler(new BrowserConsoleHandler($log_level));

// You can now use your logger
$logger->info($type, [
'plugin' => $service,
'function' => $function_name,
'datetime' => $date,
'message' => $message
]);
$log_message = [
'plugin' => $service, 'function_name' => $function_name, 'datetime' => $date, 'message' => $message
];

$telegram_send = false;

if($this->isTelegramSend()) {
$telegramLogger = new TelegramBotHandler($this->getTelegramBot(), $this->getTelegramChannel(), $log_level);
$telegramLogger->setParseMode('HTML');

$t_type = explode(' ', $this->getTelegramType());
if(is_array($t_type)) {
if(in_array('all', $t_type)) {
$logger->pushHandler($telegramLogger);
$telegram_send = true;
} elseif(in_array($type, $t_type)) {
$logger->pushHandler($telegramLogger);
$telegram_send = true;
}
}
}

switch($type) {
case 'error':
$logger->error($function_name, $log_message);
break;

case 'info':
$logger->info($function_name, $log_message);
break;

case 'notice':
$logger->notice($function_name, $log_message);
break;

case 'warn':
case 'warning':
$logger->warning($function_name, $log_message);
break;

case 'crit':
case 'critical':
$logger->critical($function_name, $log_message);
break;

case 'alert':
$logger->alert($function_name, $log_message);
break;

case 'emergency':
$logger->emergency($function_name, $log_message);
break;

case 'Debug':
case 'debug':
default:
$logger->debug($function_name, $log_message);
}

}
}
Expand All @@ -100,15 +186,83 @@ public function generate_log($service, $function_name, $message, $type = 'error'
*/
public function getLogs()
: bool {
return (bool) $this->logs;
return (bool)$this->logs;
}

/**
* @param bool|int $logs
*/
public function setLogs($logs): void {
$this->logs = $logs;
public function setLogs(?bool $logs)
: void {
$this->logs = (bool)$logs;
}

/**
* Устанавливает регулятор для отправки
*
* @param bool $telegram_send
*/
public function setTelegramSend(bool $telegram_send = false)
: void {
$this->telegram_send = $telegram_send;
}

/**
* @return bool
*/
public function isTelegramSend()
: bool {
return $this->telegram_send;
}

/**
* @param int|null|string $telegram_channel
*/
public function setTelegramChannel($telegram_channel)
: void {
$this->telegram_channel = $telegram_channel;
}

/**
* @return int|null
*/
public function getTelegramChannel()
: ?int {
return $this->telegram_channel;
}

/**
* @param string|null $telegram_bot
*/
public function setTelegramBot(?string $telegram_bot)
: void {
$this->telegram_bot = $telegram_bot;
}

/**
* @return string|null
*/
public function getTelegramBot()
: ?string {
return $this->telegram_bot;
}

/**
* @param string|null $telegram_type
*/
public function setTelegramType(?string $telegram_type)
: void {
$this->telegram_type = $telegram_type;
}

/**
* @return string|null
*/
public function getTelegramType()
: ?string {
return $this->telegram_type;
}



}
6 changes: 0 additions & 6 deletions upload/engine/inc/maharder/admin/assets/css/fa_old.css

This file was deleted.

6 changes: 0 additions & 6 deletions upload/engine/inc/maharder/admin/assets/css/icons.css

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions upload/engine/inc/maharder/admin/assets/js/jquery-confirm.min.js

This file was deleted.

4 changes: 4 additions & 0 deletions upload/engine/inc/maharder/admin/modules/admin/changelog.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

$logs = [
'2.0.6' => [
'[NEW] Добавлена функция отправки логов в телеграм [БЕТА]',
'[FIX] Исправил ошибку работы логирования',
],
'2.0.5' => [
'[FIX] Исправил работу моделей',
'[FIX] Исправил обработку кеша',
Expand Down
Loading

0 comments on commit 77f69f4

Please sign in to comment.