Skip to content

Commit 08c9747

Browse files
authored
Merge pull request #28 from dragomano/develop
Update to 1.8.1
2 parents 6263b32 + 5901791 commit 08c9747

30 files changed

+172
-84
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ $test = isset($variable) ? $variable : 'default_value';
8787
```
8888

8989
### JavaScript Styleguide
90-
* Use native JavaScript or [Alpine.js](https://github.com/alpinejs/alpine) instead of jQuery.
91-
* Use [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) in your scripts or functions.
90+
* Use native JavaScript or [Alpine.js](https://github.com/alpinejs/alpine) (2.x) instead of jQuery.
91+
* Use [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) in your scripts.
9292
* Use [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) or [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) instead of `var`.
9393

9494
```js

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* **Author:** Bugo [dragomano.ru](https://dragomano.ru/mods/light-portal)
77
* **License:** [GNU GPLv3](https://github.com/dragomano/Light-Portal/blob/master/LICENSE)
88
* **Compatible with:** SMF 2.1 RC3+ / PHP 7.3+
9-
* **Tested on:** PHP 8.0.6 / MariaDB 10.5.6 / MySQL 5.7.25 / PostgreSQL 9.6.18
9+
* **Tested on:** PHP 7.4.21 / MariaDB 10.5.10 / MySQL 5.7.25 / PostgreSQL 9.6.18
1010
* **Hooks only:** Yes
1111
* **Languages:** English, Russian, Ukrainian, Polish, Spanish, French, Turkish
1212

@@ -16,7 +16,7 @@ This modification will transform your forum into a portal that includes:
1616
* separate pages with keywords
1717
* blocks within 12-column flexbox grid
1818

19-
The portal supports BBC, HTML, PHP, and Markdown content within pages and blocks.
19+
The portal supports BBC, HTML, PHP, and Markdown content within pages and custom blocks.
2020

2121
### Features:
2222
* Blocks with multilingual titles and FontAwesome icons.
@@ -38,7 +38,7 @@ The portal supports BBC, HTML, PHP, and Markdown content within pages and bloc
3838
* отдельные страницы с ключевыми словами
3939
* блоки внутри 12-колоночной flexbox-сетки.
4040

41-
Поддержка контента с форумными тегами, HTML, PHP и Markdown в страницах и блоках.
41+
Поддержка контента с форумными тегами, HTML, PHP и Markdown в страницах и пользовательских блоках.
4242

4343
### Особенности:
4444
* Блоки с многоязычными заголовками и иконками FontAwesome.

Sources/LightPortal/FrontPage.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ public function prepare(string $entity = '')
124124
$context['page_index'] = constructPageIndex($scripturl . '?action=portal', Helpers::request()->get('start'), $total_items, $limit);
125125
$context['start'] = Helpers::request()->get('start');
126126

127-
$context['portal_next_page'] = Helpers::request('start') + $limit < $total_items ? $scripturl . '?action=portal;start=' . (Helpers::request('start') + $limit) : '';
127+
if (!empty($modSettings['lp_use_simple_pagination']))
128+
$context['page_index'] = $this->simplePaginate($scripturl . '?action=portal', $total_items, $limit);
128129

130+
$context['portal_next_page'] = Helpers::request('start') + $limit < $total_items ? $scripturl . '?action=portal;start=' . (Helpers::request('start') + $limit) : '';
129131
$context['lp_frontpage_articles'] = $articles;
130132

131133
Subs::runAddons('frontAssets');
@@ -299,4 +301,34 @@ private function postProcess(string $entity, array $articles): array
299301
return $article;
300302
}, $articles);
301303
}
304+
305+
/**
306+
* @param string $url
307+
* @param int $total
308+
* @param int $limit
309+
* @return string
310+
*/
311+
private function simplePaginate(string $url, int $total, int $limit)
312+
{
313+
global $context, $txt;
314+
315+
$max_pages = (($total - 1) / $limit) * $limit;
316+
317+
$prev = $context['start'] - $limit;
318+
319+
$next = $context['start'] + $limit > $max_pages ? '' : $context['start'] + $limit;
320+
321+
$paginate = '';
322+
323+
if ($prev >= 0)
324+
$paginate .= '<i class="fas fa-arrow-left"></i> <a href="' . $url . ';start=' . $prev . '">' . $txt['prev'] . '</a>';
325+
326+
if ($prev >= 0 && $next)
327+
$paginate .= ' <i class="fas fa-map-signs"></i> ';
328+
329+
if ($next)
330+
$paginate .= '<a href="' . $url . ';start=' . $next . '">' . $txt['next'] . '</a> <i class="fas fa-arrow-right"></i>';
331+
332+
return $paginate;
333+
}
302334
}

Sources/LightPortal/Helpers.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ public static function cleanBbcode(&$data)
126126
}
127127

128128
/**
129-
* @param string|null $icon
130-
* @param string|null $type
129+
* @param string $icon
130+
* @param string $type
131131
* @return string
132132
*/
133-
public static function getIcon($icon = null, $type = null): string
133+
public static function getIcon(string $icon = '', string $type = ''): string
134134
{
135135
global $context;
136136

137-
$icon = $icon ?? ($context['lp_block']['icon'] ?? $context['lp_page']['options']['icon'] ?? '');
138-
$type = $type ?? ($context['lp_block']['icon_type'] ?? $context['lp_page']['options']['icon_type'] ?? 'fas');
137+
$icon = $icon ?: ($context['lp_block']['icon'] ?? $context['lp_page']['options']['icon'] ?? '');
138+
$type = $type ?: ($context['lp_block']['icon_type'] ?? $context['lp_page']['options']['icon_type'] ?? 'fas');
139139

140140
if (!empty($icon))
141141
return '<i class="' . $type . ' fa-' . $icon . '"></i> ';
@@ -144,14 +144,20 @@ public static function getIcon($icon = null, $type = null): string
144144
}
145145

146146
/**
147-
* @param string|null $prefix
147+
* @param string $prefix
148148
* @return string
149149
*/
150-
public static function getPreviewTitle($prefix = null): string
150+
public static function getPreviewTitle(string $prefix = ''): string
151151
{
152152
global $context, $txt;
153153

154-
return self::getFloatSpan((!empty($prefix) ? $prefix . ' ' : '') . $context['preview_title'], $context['right_to_left'] ? 'right' : 'left') . self::getFloatSpan($txt['preview'], $context['right_to_left'] ? 'left' : 'right') . '<br>';
154+
return self::getFloatSpan(
155+
(!empty($prefix) ? $prefix . ' ' : '') . $context['preview_title'],
156+
$context['right_to_left'] ? 'right' : 'left'
157+
) . self::getFloatSpan(
158+
$txt['preview'],
159+
$context['right_to_left'] ? 'left' : 'right'
160+
) . '<br>';
155161
}
156162

157163
/**
@@ -522,11 +528,10 @@ public static function getSnakeName(string $value, string $delimiter = '_'): str
522528
{
523529
if (!ctype_lower($value)) {
524530
$value = preg_replace('/\s+/u', '', ucwords($value));
525-
526-
$value = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
531+
$value = preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value);
527532
}
528533

529-
return $value;
534+
return strtolower($value);
530535
}
531536

532537
/**
@@ -802,15 +807,15 @@ public static function getNumActivePages($all = false): int
802807
*/
803808
public static function getAllCategories()
804809
{
805-
return self::cache('all_categories', 'getList', Category::class);
810+
return self::cache('all_categories', 'getList', Lists\Category::class);
806811
}
807812

808813
/**
809814
* @return array
810815
*/
811816
public static function getAllTags()
812817
{
813-
return self::cache('all_tags', 'getList', Tag::class);
818+
return self::cache('all_tags', 'getList', Lists\Tag::class);
814819
}
815820

816821
/**

Sources/LightPortal/Integration.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function autoload(array &$classMap)
6060
$classMap['Bugo\\LightPortal\\Addons\\'] = 'LightPortal/addons/';
6161
$classMap['Bugo\\LightPortal\\Front\\'] = 'LightPortal/front/';
6262
$classMap['Bugo\\LightPortal\\Impex\\'] = 'LightPortal/impex/';
63+
$classMap['Bugo\\LightPortal\\Lists\\'] = 'LightPortal/lists/';
6364
$classMap['Bugo\\LightPortal\\Utils\\'] = 'LightPortal/utils/';
6465
}
6566

@@ -75,8 +76,8 @@ public function userInfo()
7576

7677
$lp_constants = [
7778
'LP_NAME' => 'Light Portal',
78-
'LP_VERSION' => '1.8',
79-
'LP_RELEASE_DATE' => '2021-06-06',
79+
'LP_VERSION' => '1.8.1',
80+
'LP_RELEASE_DATE' => '2021-07-24',
8081
'LP_DEBUG' => !empty($modSettings['lp_show_debug_info']) && !empty($user_info['is_admin']),
8182
'LP_CACHE_TIME' => $modSettings['lp_cache_update_interval'] ?? 3600,
8283
'LP_ADDON_DIR' => $sourcedir . '/LightPortal/addons'
@@ -152,10 +153,10 @@ public function actions(array &$actions)
152153
$actions['forum'] = array('BoardIndex.php', 'BoardIndex');
153154

154155
if (Helpers::request()->is('portal') && $context['current_subaction'] == 'categories')
155-
return call_user_func(array(new Category, 'show'));
156+
return call_user_func(array(new Lists\Category, 'show'));
156157

157158
if (Helpers::request()->is('portal') && $context['current_subaction'] == 'tags')
158-
return call_user_func(array(new Tag, 'show'));
159+
return call_user_func(array(new Lists\Tag, 'show'));
159160

160161
if (!empty($modSettings['lp_standalone_mode'])) {
161162
Subs::unsetDisabledActions($actions);

Sources/LightPortal/ManagePages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,15 @@ private function improveSelectFields()
791791
}');
792792

793793
// Prepare the tag list
794-
$all_tags = $context['lp_tags'] = Helpers::cache('all_tags', 'getList', Tag::class);
794+
$all_tags = $context['lp_tags'] = Helpers::cache('all_tags', 'getList', Lists\Tag::class);
795795

796796
$context['lp_all_tags'] = [];
797797
foreach ($all_tags as $id => $value) {
798798
$context['lp_all_tags'][] = "\t\t\t\t" . '{text: "' . $value . '", value: "' . $id . '", selected: ' . (isset($context['lp_page']['keywords'][$id]) ? 'true' : 'false') . '}';
799799
}
800800

801801
// Prepare the category list
802-
$all_categories = Helpers::cache('all_categories', 'getList', Category::class);
802+
$all_categories = Helpers::cache('all_categories', 'getList', Lists\Category::class);
803803

804804
$context['lp_all_categories'] = [];
805805
foreach ($all_categories as $id => $category) {

Sources/LightPortal/Page.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Bugo\LightPortal;
44

55
use Exception;
6+
use Bugo\LightPortal\Lists\PageListInterface;
67

78
/**
89
* Page.php

Sources/LightPortal/Settings.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public function basic(bool $return_config = false)
247247
array('select', 'lp_frontpage_layout', $context['lp_frontpage_layout']),
248248
array('select', 'lp_frontpage_num_columns', $txt['lp_frontpage_num_columns_set']),
249249
array('select', 'lp_show_pagination', $txt['lp_show_pagination_set']),
250+
array('check', 'lp_use_simple_pagination'),
250251
array('int', 'lp_num_items_per_page'),
251252
array('title', 'lp_standalone_mode_title'),
252253
array('check', 'lp_standalone_mode', 'label' => $txt['lp_action_on']),
@@ -282,7 +283,7 @@ public function basic(bool $return_config = false)
282283
$frontpage_mode_toggle_dt[] = 'setting_' . $item;
283284
}
284285

285-
$frontpage_alias_toggle = array('lp_frontpage_title', 'lp_frontpage_categories', 'lp_frontpage_boards', 'lp_frontpage_pages', 'lp_frontpage_topics', 'lp_show_images_in_articles', 'lp_image_placeholder', 'lp_frontpage_time_format', 'lp_frontpage_custom_time_format', 'lp_show_teaser', 'lp_show_author', 'lp_show_num_views_and_comments','lp_frontpage_order_by_num_replies', 'lp_frontpage_article_sorting', 'lp_frontpage_layout', 'lp_frontpage_num_columns', 'lp_num_items_per_page');
286+
$frontpage_alias_toggle = array('lp_frontpage_title', 'lp_frontpage_categories', 'lp_frontpage_boards', 'lp_frontpage_pages', 'lp_frontpage_topics', 'lp_show_images_in_articles', 'lp_image_placeholder', 'lp_frontpage_time_format', 'lp_frontpage_custom_time_format', 'lp_show_teaser', 'lp_show_author', 'lp_show_num_views_and_comments','lp_frontpage_order_by_num_replies', 'lp_frontpage_article_sorting', 'lp_frontpage_layout', 'lp_frontpage_num_columns', 'lp_show_pagination', 'lp_use_simple_pagination', 'lp_num_items_per_page');
286287

287288
$frontpage_alias_toggle_dt = [];
288289
foreach ($frontpage_alias_toggle as $item) {
@@ -437,6 +438,11 @@ public function extra(bool $return_config = false)
437438
$modSettings['bbc_disabled_lp_disabled_bbc_in_comments'] = empty($modSettings['lp_disabled_bbc_in_comments']) ? [] : explode(',', $modSettings['lp_disabled_bbc_in_comments']);
438439
$modSettings['bbc_disabled_lp_disabled_bbc_in_comments'] = array_merge($modSettings['bbc_disabled_lp_disabled_bbc_in_comments'], explode(',', $modSettings['disabledBBC']));
439440

441+
$txt['lp_show_comment_block_set']['none'] = $txt['lp_show_comment_block_set'][0];
442+
$txt['lp_show_comment_block_set']['default'] = $txt['lp_show_comment_block_set'][1];
443+
444+
unset($txt['lp_show_comment_block_set'][0], $txt['lp_show_comment_block_set'][1]);
445+
440446
$txt['lp_disabled_bbc_in_comments_subtext'] = sprintf($txt['lp_disabled_bbc_in_comments_subtext'], $scripturl . '?action=admin;area=featuresettings;sa=bbc;' . $context['session_var'] . '=' . $context['session_id'] . '#disabledBBC');
441447

442448
// Initial settings
@@ -451,7 +457,7 @@ public function extra(bool $return_config = false)
451457
array('check', 'lp_show_tags_on_page'),
452458
array('check', 'lp_show_items_as_articles'),
453459
array('check', 'lp_show_related_pages'),
454-
array('select', 'lp_show_comment_block', array_combine(array('none', 'default'), $txt['lp_show_comment_block_set'])),
460+
array('select', 'lp_show_comment_block', $txt['lp_show_comment_block_set']),
455461
array('bbc', 'lp_disabled_bbc_in_comments', 'subtext' => $txt['lp_disabled_bbc_in_comments_subtext']),
456462
array('int', 'lp_time_to_change_comments', 'postinput' => $txt['manageposts_minutes']),
457463
array('int', 'lp_num_comments_per_page'),
@@ -545,7 +551,7 @@ public function categories()
545551

546552
$context['page_title'] = $txt['lp_categories'];
547553

548-
$category = new Category;
554+
$category = new Lists\Category;
549555

550556
$context['lp_categories'] = $category->getList();
551557

Sources/LightPortal/Subs.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ public static function loadAddonCss(string $addon = '')
225225

226226
$addon = Helpers::getSnakeName($addon);
227227

228-
if (!@is_writable($settings['default_theme_dir'] . '/css/light_portal') || !@copy($style, $settings['default_theme_dir'] . '/css/light_portal/addon_' . $addon . '.css'))
228+
$addon_css = $settings['default_theme_dir'] . '/css/light_portal/addon_' . $addon . '.css';
229+
230+
$css_exists = true;
231+
if (!is_file($addon_css))
232+
$css_exists = @copy($style, $addon_css);
233+
234+
if (!@is_writable($settings['default_theme_dir'] . '/css/light_portal') || !$css_exists)
229235
return;
230236

231237
loadCSSFile('light_portal/addon_' . $addon . '.css');

Sources/LightPortal/addons/BoardStats/BoardStats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function getData(array $parameters)
154154
{
155155
global $boarddir, $modSettings;
156156

157-
if (empty($parameters['show_basic_info']) && empty($parameters['show_whos_online']))
157+
if (empty($parameters['show_latest_member']) && empty($parameters['show_basic_info']) && empty($parameters['show_whos_online']))
158158
return [];
159159

160160
require_once($boarddir . '/SSI.php');

Sources/LightPortal/addons/FlarumStyle/FlarumStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function getCategories()
8686
global $context, $txt, $modSettings;
8787

8888
if ($context['is_portal']) {
89-
$all_categories = Helpers::cache('all_categories', 'getList', \Bugo\LightPortal\Category::class);
89+
$all_categories = Helpers::cache('all_categories', 'getList', \Bugo\LightPortal\Lists\Category::class);
9090

9191
$categories = array(
9292
array(

Sources/LightPortal/addons/PageList/PageList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function prepareBlockFields()
8282
return;
8383

8484
// Prepare the category list
85-
$all_categories = Helpers::cache('all_categories', 'getList', \Bugo\LightPortal\Category::class);
85+
$all_categories = Helpers::cache('all_categories', 'getList', \Bugo\LightPortal\Lists\Category::class);
8686
$current_categories = $context['lp_block']['options']['parameters']['categories'] ?? [];
8787
$current_categories = is_array($current_categories) ? $current_categories : explode(',', $current_categories);
8888

Sources/LightPortal/addons/RecentPosts/RecentPosts.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,9 @@ public function prepareContent(&$content, $type, $block_id, $cache_time, $parame
319319

320320
if ($post['is_new'])
321321
echo '
322-
<a class="new_posts" href="', $scripturl, '?topic=', $post['topic'], '.msg', $post['new_from'], ';topicseen#new">', $txt['new'], '</a>';
322+
<a class="new_posts" href="', $scripturl, '?topic=', $post['topic'], '.msg', $post['new_from'], ';topicseen#new">', $txt['new'], '</a> ';
323323

324-
echo '
325-
', $post[$parameters['link_type']];
324+
echo $post[$parameters['link_type']];
326325

327326
if (empty($parameters['show_avatars']))
328327
echo '

0 commit comments

Comments
 (0)