From 1f0b707193d27bf0ff0f1a5c0f3fd18a04999de6 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Fri, 31 Mar 2023 13:56:28 +0300 Subject: [PATCH] * show notice in notification extension if allow_url_fopen directive is off --- src/ext/notifications/class.telegramapi.php | 4 ++-- src/ext/notifications/extension.json | 2 +- src/ext/notifications/lang/en.json | 1 + src/ext/notifications/lang/ru.json | 1 + src/ext/notifications/loader.php | 6 ++++++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ext/notifications/class.telegramapi.php b/src/ext/notifications/class.telegramapi.php index 524cf50..51df96e 100644 --- a/src/ext/notifications/class.telegramapi.php +++ b/src/ext/notifications/class.telegramapi.php @@ -53,7 +53,7 @@ class TelegramApi $body = @file_get_contents('https://api.telegram.org/bot'. $this->token .'/'. $method, false, $context); } catch (\Exception $e) { - $err = ini_get('html_errors') ? htmlspecialchars_decode($e->getMessage()) : $e->getMessage(); + $err = boolval(ini_get('html_errors')) ? htmlspecialchars_decode($e->getMessage()) : $e->getMessage(); } restore_error_handler(); if ($body === false || null !== $err) { @@ -88,7 +88,7 @@ class TelegramApi $body = @file_get_contents('https://api.telegram.org/bot'. $this->token .'/'. $method, false, $context); } catch (\Exception $e) { - $err = ini_get('html_errors') ? htmlspecialchars_decode($e->getMessage()) : $e->getMessage(); + $err = boolval(ini_get('html_errors')) ? htmlspecialchars_decode($e->getMessage()) : $e->getMessage(); } restore_error_handler(); if ($body === false || null !== $err) { diff --git a/src/ext/notifications/extension.json b/src/ext/notifications/extension.json index 592b5e7..42ef9b2 100644 --- a/src/ext/notifications/extension.json +++ b/src/ext/notifications/extension.json @@ -1,6 +1,6 @@ { "bundleId": "notifications", "name": "Notifications", - "version": "1.0.1", + "version": "1.0.2", "description": "Notify about new tasks and lists on e-mail or telegram" } diff --git a/src/ext/notifications/lang/en.json b/src/ext/notifications/lang/en.json index efa6aa8..c65c38d 100644 --- a/src/ext/notifications/lang/en.json +++ b/src/ext/notifications/lang/en.json @@ -1,5 +1,6 @@ { "ext.notifications.name": "Notifications", + "notifications.urlconfigwarning": "Enable PHP 'allow_url_fopen' directive to use Telegram notifications.", "notifications.check": "Check", "notifications.bot_not_configured": "Bot is not configured", "notifications.h_email": "E-Mail:", diff --git a/src/ext/notifications/lang/ru.json b/src/ext/notifications/lang/ru.json index bf27af2..c35924f 100644 --- a/src/ext/notifications/lang/ru.json +++ b/src/ext/notifications/lang/ru.json @@ -1,5 +1,6 @@ { "ext.notifications.name": "Уведомления", + "notifications.urlconfigwarning": "Для использования Telegram требуется включить директиву 'allow_url_fopen' в настройках PHP .", "notifications.check": "Проверить", "notifications.bot_not_configured": "Бот не настроен", "notifications.h_email": "E-Mail:", diff --git a/src/ext/notifications/loader.php b/src/ext/notifications/loader.php index 60c93b7..4ff0d65 100644 --- a/src/ext/notifications/loader.php +++ b/src/ext/notifications/loader.php @@ -100,11 +100,17 @@ class NotificationsExtension extends MTTExtension implements MTTHttpApiExtender, $newChat = $e('notifications.bot_not_configured'); } + $warning = ''; + if (!boolval(ini_get('allow_url_fopen'))) { + $warning = "
⚠️ {$e('notifications.urlconfigwarning')}
"; + } + //$e = function($s) { return __($s, true); }; //$c = function($key) { return htmlspecialchars(Config::get($key)); }; return <<
{$e('notifications.h_email')}
{$e('notifications.d_email')}