From 4c9c650cff2210a388a9dc256fdadd81acc19771 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Fri, 20 Dec 2024 17:17:40 +0300 Subject: [PATCH] feat(global): news on left menu Co-authored-by: Slava Petrov <55963296+saursvepur@users.noreply.github.com> --- Web/Presenters/OpenVKPresenter.php | 13 ++++++++++++- Web/Presenters/templates/@layout.xml | 8 ++++++++ Web/static/css/main.css | 7 ++++++- locales/en.strings | 2 ++ locales/ru.strings | 3 +++ openvk-example.yml | 3 +++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 1d03a1c2..8b33b5a7 100644 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -7,7 +7,7 @@ use Chandler\Security\Authenticator; use Latte\Engine as TemplatingEngine; use openvk\Web\Models\Entities\IP; use openvk\Web\Themes\Themepacks; -use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets, Reports, CurrentUser}; +use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets, Reports, CurrentUser, Posts}; use WhichBrowser; abstract class OpenVKPresenter extends SimplePresenter @@ -207,6 +207,17 @@ abstract class OpenVKPresenter extends SimplePresenter $userValidated = 0; $cacheTime = OPENVK_ROOT_CONF["openvk"]["preferences"]["nginxCacheTime"] ?? 0; + if(OPENVK_ROOT_CONF['openvk']['preferences']['news']['show']) { + $post = (new Posts)->getPostsFromUsersWall(-OPENVK_ROOT_CONF['openvk']['preferences']['news']['groupId'], 1, 1); + $post = iterator_to_array($post)[0]; + + $text = wordwrap($post->getText(false), 150, '\n', false); + $text = explode('\n', $text)[0]; + + $this->template->newsText = $text; + $this->template->newsLink = '/wall' . $post->getPrettyId(); + } + if(!is_null($user)) { $this->user = (object) []; $this->user->raw = $user; diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 811548cd..34e033dc 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -239,6 +239,14 @@ + +
+ {_news} +
+ {$newsText}... +

+ {_news_more} +
{tr("you_still_have_x_points", $thisUser->getCoins())|noescape} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 928ef300..7333b22b 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -2314,7 +2314,7 @@ li { padding-left: 15px; } -#votesBalance { +#votesBalance, #news { margin-top: 10px; padding: 7px; background-color: #f6f6f6; @@ -2323,6 +2323,11 @@ li { user-select: none; } +#news b { + color: #8A0000; + font-size: 12px; +} + .cookies-popup { position: fixed; bottom: 0; diff --git a/locales/en.strings b/locales/en.strings index ac328308..2cfda2eb 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -1072,6 +1072,8 @@ "time_today" = "today"; "time_yesterday" = "yesterday"; +"news" = "News"; +"news_more" = "More »"; "points" = "Votes"; "points_count" = "votes"; "on_your_account" = "on your account"; diff --git a/locales/ru.strings b/locales/ru.strings index 3f036473..2a79df8a 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -1023,6 +1023,9 @@ "time_minutes_ago" = "$1 минут назад"; "time_today" = "сегодня"; "time_yesterday" = "вчера"; + +"news" = "Новости"; +"news_more" = "Подробнее »"; "points" = "Голоса"; "points_count" = "голосов"; "on_your_account" = "на вашем счету"; diff --git a/openvk-example.yml b/openvk-example.yml index b64a589e..b8cb899f 100644 --- a/openvk-example.yml +++ b/openvk-example.yml @@ -111,6 +111,9 @@ openvk: defaultMobileTheme: "" defaultFeaturePhoneTheme: "" logs: true + news: + show: false + groupId: 1 telemetry: plausible: