diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ef0de4d47..c20673818 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 @@ -33,7 +33,7 @@ jobs: node-version: 20 - name: Install pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v3 with: version: 8 run_install: false @@ -44,7 +44,7 @@ jobs: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - name: Setup pnpm cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.STORE_PATH }} key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} @@ -57,7 +57,7 @@ jobs: pnpm install - name: Setup Pages - uses: actions/configure-pages@v3 + uses: actions/configure-pages@v4 - name: Build with VitePress run: | @@ -66,7 +66,7 @@ jobs: touch .vitepress/dist/.nojekyll - name: Upload artifact - uses: actions/upload-pages-artifact@v2 + uses: actions/upload-pages-artifact@v3 with: path: docs/.vitepress/dist @@ -81,4 +81,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 diff --git a/README.md b/README.md index 44e413f08..e637c89c3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![](https://img.shields.io/badge/Demo-Forum-brightgreen.svg)](https://demo.dragomano.ru) [![](https://img.shields.io/badge/Docs-Site-orange.svg)](https://dragomano.github.io/Light-Portal/) -- **Tested on:** PHP 8.3.1 / MariaDB 10.11.6 +- **Tested on:** PHP 8.0.30, 8.1.27, 8.2.16, 8.3.3 / MariaDB 10.11.6 - **Languages:** Russian, English, Polish, Spanish, French, Turkish, Ukrainian, German, Italian, Portuguese, Greek, Czech, Danish, Dutch, Norwegian, Swedish, Arabic ## Description ([обзор на русском](https://dragomano.ru/mods/light-portal)) diff --git a/configs/vite.comments.js b/configs/vite.comments.js index 8dc27936a..86514bd64 100644 --- a/configs/vite.comments.js +++ b/configs/vite.comments.js @@ -10,17 +10,10 @@ export default defineConfig({ outDir: dist, emptyOutDir: false, rollupOptions: { - external: ['vue', 'vue-i18n', 'pinia', 'vue-showdown'], input: 'src/Themes/default/scripts/light_portal/app_comments.js', output: { entryFileNames: 'bundle_comments.js', format: 'esm', - globals: { - vue: 'Vue', - 'vue-i18n': 'VueI18n', - pinia: 'Pinia', - 'vue-showdown': 'VueShowdown', - }, }, }, }, diff --git a/src/Sources/LightPortal/Actions/Category.php b/src/Sources/LightPortal/Actions/Category.php index 903c01ff7..265aaa861 100644 --- a/src/Sources/LightPortal/Actions/Category.php +++ b/src/Sources/LightPortal/Actions/Category.php @@ -26,8 +26,9 @@ final class Category extends AbstractPageList { public function show(PageInterface $page): void { - if ($this->request()->hasNot('id')) + if ($this->request()->hasNot('id')) { $this->showAll(); + } $category = [ 'id' => (int) $this->request('id', 0) @@ -70,9 +71,6 @@ public function show(PageInterface $page): void $listOptions['get_items'] = [ 'function' => [$this, 'getPages'] ]; - $listOptions['get_count'] = [ - 'function' => [$this, 'getTotalCount'] - ]; if (isset($category['description'])) { $listOptions['additional_rows'] = [ @@ -183,30 +181,30 @@ public function showAll(): void 'function' => fn() => count($this->getAll()) ], 'columns' => [ - 'title' => [ + 'priority' => [ 'header' => [ - 'value' => Lang::$txt['lp_category'] + 'value' => Lang::$txt['lp_block_priority'] ], 'data' => [ - 'function' => static fn($entry) => $entry['icon'] . ' ' . '' . $entry['title'] . '' . - (empty($entry['description']) ? '' : '

' . $entry['description'] . '

') + 'db' => 'priority', + 'class' => 'centertext' ], 'sort' => [ - 'default' => 't.title DESC', - 'reverse' => 't.title' + 'default' => 'c.priority', + 'reverse' => 'c.priority DESC' ] ], - 'priority' => [ + 'title' => [ 'header' => [ - 'value' => Lang::$txt['lp_block_priority'] + 'value' => Lang::$txt['lp_category'] ], 'data' => [ - 'db' => 'priority', - 'class' => 'centertext' + 'function' => static fn($entry) => $entry['icon'] . ' ' . '' . $entry['title'] . '' . + (empty($entry['description']) ? '' : '

' . $entry['description'] . '

') ], 'sort' => [ - 'default' => 'c.priority', - 'reverse' => 'c.priority DESC' + 'default' => 'title DESC', + 'reverse' => 'title' ] ], 'num_pages' => [ @@ -233,12 +231,12 @@ public function showAll(): void Utils::obExit(); } - public function getAll(int $start = 0, int $limit = 0, string $sort = 't.title'): array + public function getAll(int $start = 0, int $limit = 0, string $sort = 'title'): array { $result = Db::$db->query('', ' SELECT COALESCE(c.category_id, 0) AS category_id, c.icon, c.description, c.priority, - COUNT(p.page_id) AS frequency, COALESCE(t.title, tf.title) AS cat_title + COUNT(p.page_id) AS frequency, COALESCE(t.title, tf.title) AS title FROM {db_prefix}lp_pages AS p LEFT JOIN {db_prefix}lp_categories AS c ON (p.category_id = c.category_id) LEFT JOIN {db_prefix}lp_titles AS t ON ( @@ -271,7 +269,7 @@ public function getAll(int $start = 0, int $limit = 0, string $sort = 't.title') while ($row = Db::$db->fetch_assoc($result)) { $items[$row['category_id']] = [ 'icon' => $this->getIcon($row['icon']), - 'title' => $row['cat_title'] ?: Lang::$txt['lp_no_category'], + 'title' => $row['title'] ?: Lang::$txt['lp_no_category'], 'description' => $row['description'] ?? '', 'link' => LP_BASE_URL . ';sa=categories;id=' . $row['category_id'], 'priority' => (int) $row['priority'], diff --git a/src/Sources/LightPortal/Actions/Comment.php b/src/Sources/LightPortal/Actions/Comment.php index 16550c096..dcbee2c19 100644 --- a/src/Sources/LightPortal/Actions/Comment.php +++ b/src/Sources/LightPortal/Actions/Comment.php @@ -113,7 +113,7 @@ private function add(): void exit(json_encode($result)); $parentId = $this->filterVar($data['parent_id'], 'int'); - $message = Utils::$smcFunc['htmlspecialchars']($data['message']); + $message = Utils::htmlspecialchars($data['message']); $author = $this->filterVar($data['author'], 'int'); $pageId = Utils::$context['lp_page']['id']; $pageUrl = Utils::$context['canonical_url']; @@ -179,7 +179,7 @@ private function update(): void exit(json_encode($result)); $item = $data['comment_id']; - $message = Utils::$smcFunc['htmlspecialchars']($data['message']); + $message = Utils::htmlspecialchars($data['message']); if (empty($item) || empty($message) || empty(trim($message))) exit(json_encode($result)); diff --git a/src/Sources/LightPortal/Actions/FrontPage.php b/src/Sources/LightPortal/Actions/FrontPage.php index 7143b96b6..4b715fbc7 100644 --- a/src/Sources/LightPortal/Actions/FrontPage.php +++ b/src/Sources/LightPortal/Actions/FrontPage.php @@ -81,7 +81,7 @@ public function prepare(ArticleInterface $article): void $article->init(); - $key = 'articles_u' . Utils::$context['user']['id'] . '_' . $start . '_' . $limit; + $key = 'articles_u' . User::$info['id'] . '_' . User::$info['language'] . '_' . $start . '_' . $limit; if (($data = $this->cache()->get($key)) === null) { $data['total'] = $article->getTotalCount(); diff --git a/src/Sources/LightPortal/Actions/Tag.php b/src/Sources/LightPortal/Actions/Tag.php index 9b95c243d..9c277d29e 100644 --- a/src/Sources/LightPortal/Actions/Tag.php +++ b/src/Sources/LightPortal/Actions/Tag.php @@ -26,8 +26,9 @@ final class Tag extends AbstractPageList { public function show(PageInterface $page): void { - if ($this->request()->hasNot('id')) + if ($this->request()->hasNot('id')) { $this->showAll(); + } $tag = [ 'id' => (int) $this->request('id', 0) @@ -64,9 +65,6 @@ public function show(PageInterface $page): void $listOptions['get_items'] = [ 'function' => [$this, 'getPages'] ]; - $listOptions['get_count'] = [ - 'function' => [$this, 'getTotalCount'] - ]; new ItemList($listOptions); @@ -191,8 +189,8 @@ public function showAll(): void 'class' => 'centertext' ], 'sort' => [ - 'default' => 'tag_title DESC', - 'reverse' => 'tag_title' + 'default' => 'title DESC', + 'reverse' => 'title' ] ], 'frequency' => [ @@ -219,10 +217,10 @@ public function showAll(): void Utils::obExit(); } - public function getAll(int $start = 0, int $limit = 0, string $sort = 'tag_title'): array + public function getAll(int $start = 0, int $limit = 0, string $sort = 'title'): array { $result = Db::$db->query('', ' - SELECT tag.tag_id, tag.icon, COALESCE(tt.title, tf.title) AS tag_title, COUNT(tag.tag_id) AS frequency + SELECT tag.tag_id, tag.icon, COALESCE(tt.title, tf.title) AS title, COUNT(tag.tag_id) AS frequency FROM {db_prefix}lp_pages AS p INNER JOIN {db_prefix}lp_page_tags AS pt ON (p.page_id = pt.page_id) INNER JOIN {db_prefix}lp_tags AS tag ON (pt.tag_id = tag.tag_id) @@ -256,7 +254,7 @@ public function getAll(int $start = 0, int $limit = 0, string $sort = 'tag_title while ($row = Db::$db->fetch_assoc($result)) { $items[$row['tag_id']] = [ 'icon' => $this->getIcon($row['icon']), - 'title' => $row['tag_title'], + 'title' => $row['title'], 'link' => LP_BASE_URL . ';sa=tags;id=' . $row['tag_id'], 'frequency' => (int) $row['frequency'], ]; diff --git a/src/Sources/LightPortal/Addons/ArticleList/ArticleList.php b/src/Sources/LightPortal/Addons/ArticleList/ArticleList.php index d1c08551d..b0a046f86 100644 --- a/src/Sources/LightPortal/Addons/ArticleList/ArticleList.php +++ b/src/Sources/LightPortal/Addons/ArticleList/ArticleList.php @@ -10,7 +10,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category addon - * @version 20.02.24 + * @version 01.03.24 */ namespace Bugo\LightPortal\Addons\ArticleList; @@ -194,7 +194,7 @@ public function prepareContent(object $data, array $parameters): void if ($data->type !== 'article_list') return; - $article_list = $this->cache('article_list_addon_b' . $data->id . '_u' . User::$info['id']) + $articles = $this->cache('article_list_addon_b' . $data->id . '_u' . User::$info['id']) ->setLifeTime($data->cacheTime) ->setFallback( self::class, @@ -202,12 +202,12 @@ public function prepareContent(object $data, array $parameters): void $parameters ); - if ($article_list) { + if ($articles) { echo '
'; if (empty($parameters['display_type'])) { - foreach ($article_list as $topic) { + foreach ($articles as $topic) { $content = ''; if ($topic['image']) { $content .= ' @@ -221,7 +221,7 @@ public function prepareContent(object $data, array $parameters): void echo sprintf(Utils::$context['lp_all_content_classes'][$parameters['body_class']], $content); } } else { - foreach ($article_list as $page) { + foreach ($articles as $page) { if (empty($title = $this->getTranslatedTitle($page['title']))) continue; diff --git a/src/Sources/LightPortal/Addons/CurrentMonth/CurrentMonth.php b/src/Sources/LightPortal/Addons/CurrentMonth/CurrentMonth.php index 11bc5455f..4742bd7c6 100644 --- a/src/Sources/LightPortal/Addons/CurrentMonth/CurrentMonth.php +++ b/src/Sources/LightPortal/Addons/CurrentMonth/CurrentMonth.php @@ -10,12 +10,12 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category addon - * @version 17.02.24 + * @version 01.03.24 */ namespace Bugo\LightPortal\Addons\CurrentMonth; -use Bugo\Compat\{Config, Lang, Theme, User, Utils}; +use Bugo\Compat\{Calendar, Config, Lang, Theme, User, Utils}; use Bugo\LightPortal\Addons\Block; if (! defined('LP_NAME')) @@ -35,9 +35,7 @@ public function prepareBlockParams(array &$params): void public function getData(): array { - $this->require('Subs-Calendar'); - - $today = getTodayInfo(); + $today = Calendar::getTodayInfo(); $year = $today['year']; $month = $today['month']; $day = $today['day']; @@ -58,7 +56,7 @@ public function getData(): array 'show_week_links' => (int) (Config::$modSettings['cal_week_links'] ?? 0) ]; - return getCalendarGrid(date_format($startObject, 'Y-m-d'), $options, has_picker: false); + return Calendar::getCalendarGrid(date_format($startObject, 'Y-m-d'), $options, has_picker: false); } public function prepareContent(object $data): void diff --git a/src/Sources/LightPortal/Addons/Events/Events.php b/src/Sources/LightPortal/Addons/Events/Events.php new file mode 100644 index 000000000..709caf71c --- /dev/null +++ b/src/Sources/LightPortal/Addons/Events/Events.php @@ -0,0 +1,130 @@ + + * @copyright 2024 Bugo + * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later + * + * @category addon + * @version 03.03.24 + */ + +namespace Bugo\LightPortal\Addons\Events; + +use Bugo\Compat\{Calendar, Lang, User, Utils}; +use Bugo\LightPortal\Addons\Block; +use Bugo\LightPortal\Areas\Fields\CheckboxField; +use Bugo\LightPortal\Areas\Fields\NumberField; +use Bugo\LightPortal\Areas\Fields\RangeField; + +if (! defined('LP_NAME')) + die('No direct access...'); + +/** + * Generated by PluginMaker + */ +class Events extends Block +{ + public string $icon = 'fas fa-calendar-check'; + + public function prepareBlockParams(array &$params): void + { + if (Utils::$context['current_block']['type'] !== 'events') + return; + + $params = [ + 'show_birthdays' => false, + 'show_holidays' => false, + 'show_events' => true, + 'days_in_future' => 7, + 'update_interval' => 600, + ]; + } + + public function validateBlockParams(array &$params): void + { + if (Utils::$context['current_block']['type'] !== 'events') + return; + + $params = [ + 'show_birthdays' => FILTER_VALIDATE_BOOLEAN, + 'show_holidays' => FILTER_VALIDATE_BOOLEAN, + 'show_events' => FILTER_VALIDATE_BOOLEAN, + 'days_in_future' => FILTER_VALIDATE_INT, + 'update_interval' => FILTER_VALIDATE_INT, + ]; + } + + public function prepareBlockFields(): void + { + if (Utils::$context['current_block']['type'] !== 'events') + return; + + Lang::load('ManageCalendar'); + + CheckboxField::make('show_birthdays', Lang::$txt['setting_cal_showbdays']) + ->setTab('content') + ->setValue(Utils::$context['lp_block']['options']['show_birthdays']); + + CheckboxField::make('show_holidays', Lang::$txt['setting_cal_showholidays']) + ->setTab('content') + ->setValue(Utils::$context['lp_block']['options']['show_holidays']); + + CheckboxField::make('show_events', Lang::$txt['setting_cal_showevents']) + ->setTab('content') + ->setValue(Utils::$context['lp_block']['options']['show_events']); + + RangeField::make('days_in_future', Lang::$txt['lp_events']['days_in_future']) + ->setAttribute('max', 60) + ->setValue(Utils::$context['lp_block']['options']['days_in_future']); + + NumberField::make('update_interval', Lang::$txt['lp_events']['update_interval']) + ->setAttribute('min', 0) + ->setValue(Utils::$context['lp_block']['options']['update_interval']); + } + + public function changeIconSet(array &$set): void + { + $set['cake'] = 'fas fa-cake-candles'; + $set['event'] = 'fas fa-calendar-days'; + } + + public function getData(array $parameters): array + { + $now = time(); + $todayDate = date('Y-m-d', $now); + + $futureDate = empty($parameters['days_in_future']) + ? $todayDate + : date('Y-m-d', ($now + $parameters['days_in_future'] * 24 * 60 * 60)); + + $options = [ + 'show_birthdays' => (bool) $parameters['show_birthdays'], + 'show_holidays' => (bool) $parameters['show_holidays'], + 'show_events' => (bool) $parameters['show_events'], + ]; + + return Calendar::getCalendarList($todayDate, $futureDate, $options); + } + + public function prepareContent(object $data, array $parameters): void + { + if ($data->type !== 'events') + return; + + if ($this->request()->has('preview')) + $parameters['update_interval'] = 0; + + $data = $this->cache('events_addon_b' . $data->id . '_u' . User::$info['id']) + ->setLifeTime($parameters['update_interval'] ?? $data->cacheTime) + ->setFallback(self::class, 'getData', $parameters); + + $this->setTemplate(); + + template_show_events($data); + } +} diff --git a/src/Sources/LightPortal/Addons/Todays/index.php b/src/Sources/LightPortal/Addons/Events/index.php similarity index 100% rename from src/Sources/LightPortal/Addons/Todays/index.php rename to src/Sources/LightPortal/Addons/Events/index.php diff --git a/src/Sources/LightPortal/Addons/Events/langs/english.php b/src/Sources/LightPortal/Addons/Events/langs/english.php new file mode 100644 index 000000000..eb874588a --- /dev/null +++ b/src/Sources/LightPortal/Addons/Events/langs/english.php @@ -0,0 +1,8 @@ + 'Events', + 'description' => 'Displays calendar summary such as birthdays, holidays and events.', + 'days_in_future' => 'Number of days in future to show events', + 'update_interval' => 'Data refresh interval, in seconds', +]; diff --git a/src/Sources/LightPortal/Addons/Todays/langs/index.php b/src/Sources/LightPortal/Addons/Events/langs/index.php similarity index 100% rename from src/Sources/LightPortal/Addons/Todays/langs/index.php rename to src/Sources/LightPortal/Addons/Events/langs/index.php diff --git a/src/Sources/LightPortal/Addons/Events/style.css b/src/Sources/LightPortal/Addons/Events/style.css new file mode 100644 index 000000000..d99a252be --- /dev/null +++ b/src/Sources/LightPortal/Addons/Events/style.css @@ -0,0 +1,25 @@ +.block_events { + > div:last-child { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); + grid-gap: 0 10px; + + @media screen and (max-width: 768px) { + & { + display: block; + } + } + } + + .fa-calendar { + color: forestgreen; + } + + .fa-cake-candles { + color: salmon; + } + + .fa-calendar-days { + color: rgb(59, 91, 152); + } +} diff --git a/src/Sources/LightPortal/Addons/Events/template.php b/src/Sources/LightPortal/Addons/Events/template.php new file mode 100644 index 000000000..944567b21 --- /dev/null +++ b/src/Sources/LightPortal/Addons/Events/template.php @@ -0,0 +1,149 @@ +'; + + if (! empty($data['events']) || ! empty($data['holidays'])) { + echo ' + ', Lang::$txt['birthdays'], ''; + } + + echo ' + +
'; +} + +function show_holidays(array $data): void +{ + if (empty($data['holidays'])) + return; + + echo ' +
'; + + if (! empty($data['events']) || ! empty($data['birthdays'])) { + echo ' + ', Lang::$txt['calendar_prompt'], ''; + } + + echo ' + +
'; +} + +function show_events(array $data): void +{ + if (empty($data['events'])) + return; + + echo ' +
'; + + if (! empty($data['birthdays']) || ! empty($data['holidays'])) { + echo ' + ', Lang::$txt['events'], ''; + } + + echo ' + +
'; +} diff --git a/src/Sources/LightPortal/Addons/Search/Search.php b/src/Sources/LightPortal/Addons/Search/Search.php index cc2628e77..dfbc7ae20 100644 --- a/src/Sources/LightPortal/Addons/Search/Search.php +++ b/src/Sources/LightPortal/Addons/Search/Search.php @@ -10,7 +10,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category addon - * @version 19.02.24 + * @version 04.03.24 */ namespace Bugo\LightPortal\Addons\Search; @@ -81,7 +81,7 @@ private function prepareQuickResults(): void if (empty($data['phrase'])) return; - $query = Utils::$smcFunc['htmltrim'](Utils::$smcFunc['htmlspecialchars']($data['phrase'])); + $query = Utils::$smcFunc['htmltrim'](Utils::htmlspecialchars($data['phrase'])); exit(json_encode($this->query($query))); } @@ -94,7 +94,7 @@ private function getResults(): array if ($this->request()->isNotEmpty('search') === false) return []; - $query = Utils::$smcFunc['htmltrim'](Utils::$smcFunc['htmlspecialchars']($this->request('search'))); + $query = Utils::$smcFunc['htmltrim'](Utils::htmlspecialchars($this->request('search'))); if (empty($query)) return []; diff --git a/src/Sources/LightPortal/Addons/SimpleChat/Chat.php b/src/Sources/LightPortal/Addons/SimpleChat/Chat.php index 33abe6e45..b5b19561f 100644 --- a/src/Sources/LightPortal/Addons/SimpleChat/Chat.php +++ b/src/Sources/LightPortal/Addons/SimpleChat/Chat.php @@ -10,7 +10,7 @@ * @license https://opensource.org/licenses/MIT MIT * * @category addon - * @version 19.02.24 + * @version 04.03.24 */ namespace Bugo\LightPortal\Addons\SimpleChat; @@ -77,7 +77,7 @@ public function addMessage(): void [ 'block_id' => $data['block_id'], 'user_id' => User::$info['id'], - 'message' => $message = Utils::$smcFunc['htmlspecialchars']($data['message']), + 'message' => $message = Utils::htmlspecialchars($data['message']), 'created_at' => $time = time(), ], ['id'], diff --git a/src/Sources/LightPortal/Addons/TagList/TagList.php b/src/Sources/LightPortal/Addons/TagList/TagList.php index 0ea3c345b..c1ea5b3b9 100644 --- a/src/Sources/LightPortal/Addons/TagList/TagList.php +++ b/src/Sources/LightPortal/Addons/TagList/TagList.php @@ -10,7 +10,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category addon - * @version 26.02.24 + * @version 03.03.24 */ namespace Bugo\LightPortal\Addons\TagList; @@ -105,7 +105,7 @@ public function prepareContent(object $data, array $parameters): void if ($parameters['source'] == 'lp_tags') { $tagList = $this->cache('tag_list_addon_b' . $data->id . '_u' . User::$info['id']) ->setLifeTime($data->cacheTime) - ->setFallback(Tag::class, 'getAll', 0, 0, $parameters['sorting'] === 'name' ? 'tag_title' : 'frequency DESC'); + ->setFallback(Tag::class, 'getAll', 0, 0, $parameters['sorting'] === 'name' ? 'title' : 'frequency DESC'); } else { $tagList = $this->cache('tag_list_addon_b' . $data->id . '_u' . User::$info['id']) ->setLifeTime($data->cacheTime) diff --git a/src/Sources/LightPortal/Addons/Todays/Todays.php b/src/Sources/LightPortal/Addons/Todays/Todays.php deleted file mode 100644 index a71c2e2f7..000000000 --- a/src/Sources/LightPortal/Addons/Todays/Todays.php +++ /dev/null @@ -1,168 +0,0 @@ - - * @copyright 2020-2024 Bugo - * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later - * - * @category addon - * @version 17.02.24 - */ - -namespace Bugo\LightPortal\Addons\Todays; - -use Bugo\Compat\{Config, Lang, Utils}; -use Bugo\LightPortal\Addons\Block; -use Bugo\LightPortal\Areas\Fields\{RangeField, SelectField}; - -if (! defined('LP_NAME')) - die('No direct access...'); - -class Todays extends Block -{ - public string $type = 'block ssi'; - - public string $icon = 'fas fa-calendar-day'; - - public function init(): void - { - $this->applyHook('menu_buttons'); - } - - public function menuButtons(array &$buttons): void - { - $buttons['calendar']['show'] = Utils::$context['allow_calendar'] - && empty(Utils::$context['lp_todays_plugin']['hide_calendar_in_menu']); - } - - public function addSettings(array &$settings): void - { - $settings['todays'][] = [ - 'check', - 'hide_calendar_in_menu', - 'subtext' => sprintf( - Lang::$txt['lp_todays']['hide_calendar_in_menu_subtext'], - Config::$scripturl . '?action=admin;area=managecalendar;sa=settings' - ) - ]; - } - - public function prepareBlockParams(array &$params): void - { - if (Utils::$context['current_block']['type'] !== 'todays') - return; - - $params = [ - 'widget_type' => 'calendar', - 'max_items' => 1, - ]; - } - - public function validateBlockParams(array &$params): void - { - if (Utils::$context['current_block']['type'] !== 'todays') - return; - - $params = [ - 'widget_type' => FILTER_DEFAULT, - 'max_items' => FILTER_VALIDATE_INT, - ]; - } - - public function prepareBlockFields(): void - { - if (Utils::$context['current_block']['type'] !== 'todays') - return; - - SelectField::make('widget_type', Lang::$txt['lp_todays']['type']) - ->setTab('content') - ->setOptions(array_combine( - ['birthdays', 'holidays', 'events', 'calendar'], - Lang::$txt['lp_todays']['type_set'] - )) - ->setValue(Utils::$context['lp_block']['options']['widget_type']); - - RangeField::make('max_items', Lang::$txt['lp_todays']['max_items']) - ->setAfter(Lang::$txt['lp_todays']['max_items_subtext']) - ->setAttribute('min', 1) - ->setAttribute('max', 100) - ->setValue(Utils::$context['lp_block']['options']['max_items']); - } - - public function getData(string $type, string $output_method = 'echo') - { - return $this->getFromSsi('todays' . ucfirst($type), $output_method); - } - - public function prepareContent(object $data, array $parameters): void - { - if ($data->type !== 'todays') - return; - - $result = $this->getData($parameters['widget_type'], 'array'); - - if ($parameters['widget_type'] === 'calendar') { - if ($result['calendar_holidays'] || $result['calendar_birthdays'] || $result['calendar_events']) - $this->getData($parameters['widget_type']); - else - echo Lang::$txt['lp_todays']['empty_list']; - } elseif ($parameters['widget_type'] === 'events' && $result) { - echo ' - '; - } elseif ($result) { - if ($parameters['widget_type'] !== 'birthdays' || count($result) <= $parameters['max_items']) { - $this->getData($parameters['widget_type']); - } else { - $visibleItems = array_slice($result, 0, $parameters['max_items']); - $visibleItems[$parameters['max_items'] - 1]['is_last'] = true; - $hiddenItems = array_slice($result, $parameters['max_items']); - - foreach ($visibleItems as $member) { - echo ' - - ' . $member['name'] . '' - . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . ' - ' . ($member['is_last'] ? '' : ', '); - } - - $hiddenContent = ''; - foreach ($hiddenItems as $member) { - if ($member['is_today']) - $hiddenContent .= ' - - ' . $member['name'] . '' - . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . ' - ' . ($member['is_last'] ? '' : ', '); - } - - if ($hiddenContent) - echo Lang::$txt['lp_todays']['and_more'], ' -
- - ', Lang::getTxt( - Lang::$txt['lp_todays']['birthdays_set'], - ['count' => count($result) - $parameters['max_items']] - ), ' - -
', $hiddenContent, '
-
'; - } - } else { - echo Lang::$txt['lp_todays']['empty_list']; - } - } -} diff --git a/src/Sources/LightPortal/Addons/Todays/langs/english.php b/src/Sources/LightPortal/Addons/Todays/langs/english.php deleted file mode 100644 index 62afdeaba..000000000 --- a/src/Sources/LightPortal/Addons/Todays/langs/english.php +++ /dev/null @@ -1,15 +0,0 @@ - 'Today', - 'description' => 'Displays the calendar, birthdays, holidays, or today\'s events.', - 'hide_calendar_in_menu' => 'Hide the "Calendar" item in the main menu', - 'hide_calendar_in_menu_subtext' => 'You need to enable Calendar to make this block work properly. But if you do not want to see it in the menu, you can hide it.', - 'type' => 'What to display', - 'type_set' => ['Birthdays', 'Holidays', 'Events', 'Calendar'], - 'max_items' => 'Maximum number of birthday men in the list', - 'max_items_subtext' => 'If there are more birthday men, the remaining ones will be hidden under the spoiler.', - 'and_more' => ' and more ', - 'birthdays_set' => '{count, plural, one {# birthday man} other {# birthday men}}', - 'empty_list' => 'There is nothing today.', -]; diff --git a/src/Sources/LightPortal/Addons/Todays/style.css b/src/Sources/LightPortal/Addons/Todays/style.css deleted file mode 100644 index 28c2946c7..000000000 --- a/src/Sources/LightPortal/Addons/Todays/style.css +++ /dev/null @@ -1,53 +0,0 @@ -.block_todays { - details { - display: contents; - position: relative; - margin-bottom: 0.5rem; - min-height: 1rem; - max-height: 3rem; - transition: min-height 0.15s linear, max-height 0.5s linear; - will-change: max-height; - overflow: hidden; - - summary { - display: inline-block; - cursor: pointer; - outline: 0; - transition: color 0.12s; - - &::-webkit-details-marker { - display: none; - } - - &::-moz-list-bullet { - list-style-type: none; - } - - span { - border-bottom: 1px currentColor dotted; - } - - &:hover { - color: #d06c6c; - } - } - } -} - -.block_todays details summary ~ * { - display: none; - transition: opacity 0.15s linear; -} - -.block_todays details[open] { - min-height: 2em; - max-height: 20em; - - summary { - color: #d06c6c; - } -} - -.block_todays details[open] summary ~ * { - display: block; -} diff --git a/src/Sources/LightPortal/Addons/UserInfo/template.php b/src/Sources/LightPortal/Addons/UserInfo/template.php index 0c4fc49d2..55c9c937f 100644 --- a/src/Sources/LightPortal/Addons/UserInfo/template.php +++ b/src/Sources/LightPortal/Addons/UserInfo/template.php @@ -67,7 +67,7 @@ function show_user_info_for_guests(): void