Skip to content

Commit

Permalink
feat(global): news on left menu
Browse files Browse the repository at this point in the history
Co-authored-by: Slava Petrov <[email protected]>
  • Loading branch information
veselcraft and saursvepur committed Dec 20, 2024
1 parent 1677d98 commit 4c9c650
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Web/Presenters/OpenVKPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down Expand Up @@ -207,6 +207,17 @@ function onStartup(): void
$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;
Expand Down
8 changes: 8 additions & 0 deletions Web/Presenters/templates/@layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@
</object>
</a>
</div>

<div id="news" n:if="OPENVK_ROOT_CONF['openvk']['preferences']['news']['show']">
<b>{_news} </b>
<hr size="1">
<text>{$newsText}...</text>
<br><br>
<a href="{$newsLink}">{_news_more}</a>
</div>

<div n:if="OPENVK_ROOT_CONF['openvk']['preferences']['commerce'] && $thisUser->getCoins() != 0" id="votesBalance">
{tr("you_still_have_x_points", $thisUser->getCoins())|noescape}
Expand Down
7 changes: 6 additions & 1 deletion Web/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ li {
padding-left: 15px;
}

#votesBalance {
#votesBalance, #news {
margin-top: 10px;
padding: 7px;
background-color: #f6f6f6;
Expand All @@ -2323,6 +2323,11 @@ li {
user-select: none;
}

#news b {
color: #8A0000;
font-size: 12px;
}

.cookies-popup {
position: fixed;
bottom: 0;
Expand Down
2 changes: 2 additions & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,9 @@
"time_minutes_ago" = "$1 минут назад";
"time_today" = "сегодня";
"time_yesterday" = "вчера";

"news" = "Новости";
"news_more" = "Подробнее »";
"points" = "Голоса";
"points_count" = "голосов";
"on_your_account" = "на вашем счету";
Expand Down
3 changes: 3 additions & 0 deletions openvk-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ openvk:
defaultMobileTheme: ""
defaultFeaturePhoneTheme: ""
logs: true
news:
show: false
groupId: 1

telemetry:
plausible:
Expand Down

0 comments on commit 4c9c650

Please sign in to comment.