Skip to content

Commit

Permalink
Merge pull request #246 from dragomano/hot_fixes
Browse files Browse the repository at this point in the history
Add some fixes
  • Loading branch information
dragomano authored Nov 11, 2024
2 parents 72faf3e + 8f88b43 commit 052bb62
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 63 deletions.
2 changes: 1 addition & 1 deletion docs/src/plugins/create-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Plugins for importing and exporting various portal elements.

### `block_options` | `page_options`

Plugins that add additional parameters for the corresponding entity (block or .page).
Plugins that add additional parameters for the corresponding entity (block or page).

### `icons`

Expand Down
4 changes: 0 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;

return RectorConfig::configure()
Expand All @@ -13,9 +12,6 @@
__DIR__ . '**/Tasks/Notifier.php',
__DIR__ . '**/Libs/*',
__DIR__ . '**/vendor/*',
__DIR__ . '**/langs/*',
__DIR__ . '**/index.php',
StringClassNameToClassConstantRector::class,
NullToStrictStringFuncCallArgRector::class,
])
->withParallel(360)
Expand Down
2 changes: 1 addition & 1 deletion src/Sources/LightPortal/Actions/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function show(): void
$icon = Icon::parse(Utils::$context['lp_blocks'][$data['placement']][$item]['icon']);

if (! empty($data['parameters']['link_in_title'])) {
$title = Str::html('a')->href($data['parameters']['link_in_title'])->setText($title);
$title = Str::html('a', $title)->href($data['parameters']['link_in_title']);
}
} else {
$title = $icon = '';
Expand Down
8 changes: 3 additions & 5 deletions src/Sources/LightPortal/Actions/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ public function showAll(): void
'value' => Lang::$txt['lp_category']
],
'data' => [
'function' => static fn($entry) => $entry['icon'] . ' ' . Str::html('a')
->href($entry['link'])
->setText($entry['title']) . (empty($entry['description']) ? '' :
Str::html('p', ['class' => 'smalltext'])
->setText($entry['description']))
'function' => static fn($entry) => $entry['icon'] . ' ' . Str::html('a', $entry['title'])
->href($entry['link']) . (empty($entry['description']) ? '' :
Str::html('p', $entry['description'])->class('smalltext'))
],
'sort' => [
'default' => 'title DESC',
Expand Down
5 changes: 1 addition & 4 deletions src/Sources/LightPortal/Actions/FrontPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,7 @@ private function simplePaginate(string $url, int $total, int $limit): string

$paginate = '';

$button = Str::html('a', [
'class' => 'button',
'href' => '%s;start=%s',
]);
$button = Str::html('a')->class('button')->href('%s;start=%s');

if ($prev >= 0) {
$title = Icon::get('arrow_left') . ' ' . Lang::$txt['prev'];
Expand Down
12 changes: 5 additions & 7 deletions src/Sources/LightPortal/Actions/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ public function getList(): array
'value' => Lang::$txt['lp_title']
],
'data' => [
'function' => static fn($entry) => Str::html('a', [
'class' => 'bbc_link' . ($entry['is_front'] ? ' new_posts' : ''),
'href' => $entry['is_front'] ? Config::$scripturl : (LP_PAGE_URL . $entry['slug']),
])->setText($entry['title']),
'function' => static fn($entry) => Str::html('a', $entry['title'])
->class('bbc_link' . ($entry['is_front'] ? ' new_posts' : ''))
->href($entry['is_front'] ? Config::$scripturl : (LP_PAGE_URL . $entry['slug'])),
'class' => 'word_break'
],
'sort' => [
Expand All @@ -251,9 +250,8 @@ public function getList(): array
'data' => [
'function' => static fn($entry) => empty($entry['author']['name'])
? Lang::$txt['guest_title']
: Str::html('a')
->href($entry['author']['link'])
->setText($entry['author']['name']),
: Str::html('a', $entry['author']['name'])
->href($entry['author']['link']),
'class' => 'centertext'
],
'sort' => [
Expand Down
5 changes: 2 additions & 3 deletions src/Sources/LightPortal/Actions/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ public function showAll(): void
'value' => Lang::$txt['lp_tag_column']
],
'data' => [
'function' => static fn($entry) => $entry['icon'] . ' ' . Str::html('a')
->href($entry['link'])
->setText($entry['title']),
'function' => static fn($entry) => $entry['icon'] . ' ' . Str::html('a', $entry['title'])
->href($entry['link']),
],
'sort' => [
'default' => 'title DESC',
Expand Down
18 changes: 4 additions & 14 deletions src/Sources/LightPortal/Areas/PluginArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function handleToggle(): void
)
]);

$this->updateAssetMtime(Utils::$context['lp_plugins'][$pluginId]);
$this->removeAssets();

$this->cache()->flush();

Expand Down Expand Up @@ -342,20 +342,10 @@ private function prepareJsonData(): void
]);
}

private function updateAssetMtime(string $plugin): void
private function removeAssets(): void
{
$path = LP_ADDON_DIR . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;

$assets = [
$path . 'style.css',
$path . 'script.js',
];

foreach ($assets as $asset) {
if (is_file($asset)) {
touch($asset);
}
}
unlink(Theme::$current->settings['default_theme_dir'] . '/css/light_portal/plugins.css');
unlink(Theme::$current->settings['default_theme_dir'] . '/scripts/light_portal/plugins.js');
}

private function extendPluginList(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Sources/LightPortal/Hooks/CommonChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait CommonChecks

protected function isPortalCanBeLoaded(): bool
{
if (! defined('LP_NAME') || $this->request()->is('printpage')) {
if (! defined('LP_NAME') || isset(Utils::$context['uninstalling']) || $this->request()->is('printpage')) {
Config::$modSettings['minimize_files'] = 0;
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Sources/LightPortal/Hooks/PreCssOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class PreCssOutput
{
public function __invoke(): void
{
if (isset(Utils::$context['uninstalling']))
return;

echo "\n\t" . Str::html('link')
->rel('preconnect')
->href('//cdn.jsdelivr.net');
Expand Down
4 changes: 0 additions & 4 deletions src/Sources/LightPortal/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Bugo\LightPortal;

use Bugo\Compat\Utils;
use Bugo\LightPortal\Enums\Hook;
use Bugo\LightPortal\Hooks\Actions;
use Bugo\LightPortal\Hooks\AlertTypes;
Expand Down Expand Up @@ -49,9 +48,6 @@ final class Integration

public function __invoke(): void
{
if (isset(Utils::$context['uninstalling']))
return;

if (str_starts_with(SMF_VERSION, '3.0')) {
$this->applyHook(Hook::preLoad, PreLoad::class);
$this->applyHook(Hook::permissionsList, PermissionsList::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function init(): void

public function menuButtons(): void
{
if ($this->request()->has('xml'))
if (isset(Utils::$context['uninstalling']) || $this->request()->has('xml'))
return;

if (empty(Utils::$context['lp_custom_translate_plugin']['languages']))
Expand Down
6 changes: 3 additions & 3 deletions src/Sources/LightPortal/Plugins/HelloPortal/steps.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
intro: "' . Lang::$txt['lp_hello_portal']['basic_settings_tour'][1] . '"
},' . (! empty(Config::$modSettings['lp_frontpage_mode']) && Config::$modSettings['lp_frontpage_mode'] !== 'chosen_page' ? ('
{
element: document.getElementById("lp_frontpage_order_by_replies"),
element: document.getElementById("caption_lp_frontpage_order_by_replies"),
intro: "' . Lang::$txt['lp_hello_portal']['basic_settings_tour'][2] . '"
},') : '') . '
{
element: document.getElementById("setting_lp_standalone_mode").parentNode.parentNode.parentNode,
element: document.querySelector("[data-tab=standalone]"),
intro: "' . Lang::$txt['lp_hello_portal']['basic_settings_tour'][3] . '"
},
{
element: document.getElementById("setting_light_portal_view").parentNode.parentNode,
element: document.querySelector("[data-tab=permissions]"),
intro: "' . Lang::$txt['lp_hello_portal']['basic_settings_tour'][4] . '"
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/Sources/LightPortal/Plugins/HelloPortal/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.lp_addon_hello_portal * {
font-size: 1.4em;
}

.introjs-helperLayer {
background: transparent !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @category plugin
* @version 08.11.24
* @version 09.11.24
*/

namespace Bugo\LightPortal\Plugins\ThemeSwitcher;
Expand Down Expand Up @@ -50,18 +50,15 @@ public function prepareContent(Event $e): void

$id = $e->args->data->id;

$container = Str::html('div')
->class('themeswitcher centertext');
$container = Str::html('div')->class('themeswitcher centertext');

$select = Str::html('select')
->id("lp_block_{$id}_themeswitcher")
->setAttribute('onchange', "lp_block_{$id}_themeswitcher_change();")
->setAttribute('disabled', count($themes) < 2 ? 'disabled' : null);

foreach ($themes as $themeId => $name) {
$option = Str::html('option')
->value($themeId)
->setText($name);
$option = Str::html('option', $name)->value($themeId);

if (Theme::$current->settings['theme_id'] === $themeId) {
$option->setAttribute('selected', 'selected');
Expand Down
3 changes: 3 additions & 0 deletions src/Sources/LightPortal/Repositories/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected function saveOptions(int $item, string $method = ''): void

protected function prepareTitles(): void
{
if (empty(Utils::$context['lp_' . $this->entity]['titles']))
return;

// Remove all punctuation symbols
Utils::$context['lp_' . $this->entity]['titles'] = preg_replace(
"#[[:punct:]]#", "", (array) Utils::$context['lp_' . $this->entity]['titles']
Expand Down
4 changes: 3 additions & 1 deletion src/Sources/LightPortal/Repositories/BlockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function getAll(): array
'areas' => str_replace(',', PHP_EOL, (string) $row['areas']),
];

$currentBlocks[$row['placement']][$row['block_id']]['titles'][$row['lang']] = $row['title'];
if (! empty($row['lang'])) {
$currentBlocks[$row['placement']][$row['block_id']]['titles'][$row['lang']] = $row['title'];
}

$this->prepareMissingBlockTypes($row['type']);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Sources/LightPortal/Repositories/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ final class PageRepository extends AbstractRepository

protected string $entity = 'page';

private CommentRepository $commentRepository;

public function __construct()
{
$this->commentRepository = new CommentRepository();
Expand Down Expand Up @@ -670,9 +672,7 @@ private function updateData(int $item): void
if (Utils::$context['lp_page']['author_id'] !== User::$info['id']) {
$title = Utils::$context['lp_page']['titles'][User::$info['language']];
Logging::logAction('update_lp_page', [
'page' => Str::html('a')
->href(LP_PAGE_URL . Utils::$context['lp_page']['slug'])
->setText($title)
'page' => Str::html('a', $title)->href(LP_PAGE_URL . Utils::$context['lp_page']['slug'])
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Sources/LightPortal/Utils/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function getImageFromText(string $text): string
return $result;
}

public static function html(string $name, array $params = []): Html
public static function html(string $name, array|string|null $params = null): Html
{
return Html::el($name, $params);
}
Expand Down
12 changes: 11 additions & 1 deletion src/Themes/default/LightPortal/ManageBlocks.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ function show_block_entry(int $id, array $data): void
if (empty($id) || empty($data))
return;

$title = $data['note'] ?? '';

if (isset($data['titles'])) {
if (! empty($data['titles'][Utils::$context['user']['language']])) {
$title = $data['titles'][Utils::$context['user']['language']];
} elseif (! empty($data['titles'][Config::$language])) {
$title = $data['titles'][Config::$language];
}
}

echo '
<tr
class="windowbg"
Expand All @@ -112,7 +122,7 @@ class="windowbg"
', $data['icon'], '
</td>
<td class="title">
<div class="hidden-xs hidden-sm hidden-md">', $title = $data['note'] ?: ($data['titles'][Utils::$context['user']['language']] ?? $data['titles'][Config::$language] ?? ''), '</div>
<div class="hidden-xs hidden-sm hidden-md">', $title, '</div>
<div class="hidden-lg hidden-xl">
<table class="table_grid">
<tbody>
Expand Down
3 changes: 2 additions & 1 deletion src/Themes/default/LightPortal/ManageFeedback.template.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Bugo\Compat\{Config, Lang, Utils};
use Bugo\Compat\{Config, Db, Lang, Utils};

function template_feedback(): void
{
Expand All @@ -22,6 +22,7 @@ function template_feedback(): void
<input type="hidden" name="portal_version" value="', LP_VERSION, '">
<input type="hidden" name="smf_version" value="', SMF_VERSION, '">
<input type="hidden" name="php_version" value="', PHP_VERSION, '">
<input type="hidden" name="database" value="', Utils::$smcFunc['db_title'] . ' ' . Db::$db->get_version(), '">
<input type="hidden" name="enabled_plugins" value="', str_replace(',', "\n", (string) Config::$modSettings['lp_enabled_plugins']), '">
<input type="hidden" name="language" value="', Utils::$context['user']['language'], '">
<input type="checkbox" name="botcheck" class="hidden" style="display: none">
Expand Down
4 changes: 2 additions & 2 deletions src/package-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
<require-dir name="Sources/LightPortal" destination="$sourcedir" />
<require-dir name="Themes/default" destination="$themes_dir" />
<require-file name="portal.php" destination="$boarddir" />
<hook hook="integrate_pre_include" file="$sourcedir/LightPortal/app.php" />
<hook hook="integrate_pre_include" function="$sourcedir/LightPortal/app.php" />
<redirect url="?action=admin;area=lp_settings" timeout="3000" />
</install>

<uninstall for="2.1.*, 3.0.*">
<hook hook="integrate_pre_include" file="$sourcedir/LightPortal/app.php" reverse="true" />
<hook hook="integrate_pre_include" function="$sourcedir/LightPortal/app.php" reverse="true" />
<code>uninstall.php</code>
<database>uninstall-optional.php</database>
<remove-dir name="$themedir/LightPortal" />
Expand Down

0 comments on commit 052bb62

Please sign in to comment.