Skip to content

Commit

Permalink
Merge pull request #26 from dragomano/develop
Browse files Browse the repository at this point in the history
Update to 1.8
  • Loading branch information
dragomano authored Jun 6, 2021
2 parents 328f982 + 738dfd7 commit 6263b32
Show file tree
Hide file tree
Showing 134 changed files with 2,441 additions and 1,290 deletions.
3 changes: 1 addition & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
patreon: bugo
ko_fi: dragomano
custom: ["https://boosty.to/bugo"]
custom: ["https://qiwi.com/n/DRAGOMANO"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* **Author:** Bugo [dragomano.ru](https://dragomano.ru/mods/light-portal)
* **License:** [GNU GPLv3](https://github.com/dragomano/Light-Portal/blob/master/LICENSE)
* **Compatible with:** SMF 2.1 RC3+ / PHP 7.3+
* **Tested on:** PHP 7.3.27, 7.4.16, 8.0.3 / MariaDB 10.5.6 / MySQL 5.7.25 / PostgreSQL 9.6.18
* **Tested on:** PHP 8.0.6 / MariaDB 10.5.6 / MySQL 5.7.25 / PostgreSQL 9.6.18
* **Hooks only:** Yes
* **Languages:** English, Russian, Ukrainian, Polish, Spanish, French, Turkish

Expand Down
6 changes: 3 additions & 3 deletions Sources/LightPortal/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -66,10 +66,10 @@ public function show()
loadTemplate('LightPortal/ViewBlock');

$counter = 0;
foreach ($context['template_layers'] as $position => $name) {
foreach ($context['template_layers'] as $layer) {
$counter++;

if ($name == 'body')
if ($layer === 'body')
break;
}

Expand Down
8 changes: 5 additions & 3 deletions Sources/LightPortal/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bugo\LightPortal;

use Exception;

/**
* Category.php
*
Expand All @@ -11,7 +13,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand All @@ -25,7 +27,7 @@ class Category implements PageListInterface
* Отображение всех страниц портала внутри выбранной рубрики
*
* @return void
* @throws \Exception
* @throws Exception
*/
public function show()
{
Expand Down Expand Up @@ -100,7 +102,7 @@ public function show()
* @param int $items_per_page
* @param string $sort
* @return array
* @throws \Exception
* @throws Exception
*/
public function getPages(int $start, int $items_per_page, string $sort): array
{
Expand Down
4 changes: 2 additions & 2 deletions Sources/LightPortal/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -433,7 +433,7 @@ public function getAll(int $page_id = 0): array
'message' => empty($context['lp_allowed_bbc']) ? $row['message'] : parse_bbc($row['message'], true, 'light_portal_comments_' . $page_id, $context['lp_allowed_bbc']),
'raw_message' => un_preparsecode($row['message']),
'created_at' => $row['created_at'],
'can_edit' => !empty($modSettings['lp_time_to_change_comments']) ? (time() - $row['created_at'] <= (int) $modSettings['lp_time_to_change_comments'] * 60) : false
'can_edit' => !empty($modSettings['lp_time_to_change_comments']) && time() - $row['created_at'] <= (int) $modSettings['lp_time_to_change_comments'] * 60
);
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/LightPortal/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -58,7 +58,7 @@ public function getCopyrights(): string
}

/**
* Prepare information about contrubutors and third party components
* Prepare information about contributors and third party components
*
* Формируем информацию о внесших вклад в развитие портала и об используемых компонентах
*/
Expand Down
18 changes: 9 additions & 9 deletions Sources/LightPortal/FrontPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

class FrontPage
Expand Down Expand Up @@ -188,13 +188,13 @@ public function getLayouts(): array

$layouts = $values = [];

$all_funcs = get_defined_functions()['user'];
$allFunctions = get_defined_functions()['user'];

require_once($settings['default_theme_dir'] . '/LightPortal/ViewFrontPage.template.php');

$fp_funcs = array_values(array_diff(get_defined_functions()['user'], $all_funcs));
$frontPageFunctions = array_values(array_diff(get_defined_functions()['user'], $allFunctions));

preg_match_all('/template_show_([a-z]+)(.*)/', implode("\n", $fp_funcs), $matches);
preg_match_all('/template_show_([a-z]+)(.*)/', implode("\n", $frontPageFunctions), $matches);

if (!empty($matches[1])) {
foreach ($matches[1] as $k => $v) {
Expand All @@ -216,7 +216,7 @@ public function getLayouts(): array
* @param int $date
* @return string
*/
public function getCardDate($date): string
public function getCardDate(int $date): string
{
global $modSettings;

Expand All @@ -238,9 +238,9 @@ public function getCardDate($date): string
*
* Получаем условие сортировки для SQL
*
* @return void
* @return string
*/
public function getOrderBy()
public function getOrderBy(): string
{
global $context;

Expand Down Expand Up @@ -271,7 +271,7 @@ public function getOrderBy()
* @param array $articles
* @return array
*/
private function postProcess($entity, $articles)
private function postProcess(string $entity, array $articles): array
{
return array_map(function ($article) use ($entity) {
global $context, $modSettings;
Expand All @@ -282,7 +282,7 @@ private function postProcess($entity, $articles)
if (!empty($article['date'])) {
$article['datetime'] = date('Y-m-d', $article['date']);

$article['date'] = $this->getCardDate($article['date']);
$article['date'] = $this->getCardDate((int) $article['date']);
}

$article['msg_link'] = $article['msg_link'] ?? $article['link'];
Expand Down
13 changes: 5 additions & 8 deletions Sources/LightPortal/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -383,7 +383,7 @@ public static function getDateFormat(int $day, string $month, string $postfix):
* @param string $type
* @return void
*/
public static function findMissingBlockTypes(string $type)
public static function prepareMissingBlockTypes(string $type)
{
global $txt, $context;

Expand Down Expand Up @@ -533,12 +533,9 @@ public static function getSnakeName(string $value, string $delimiter = '_'): str
* @param string $text
* @return string
*/
public static function getTeaser($text): string
public static function getTeaser(string $text): string
{
if (empty($text))
return '...';

$text = strip_tags(explode('<br>', $text)[0]);
$text = strip_tags($text);

return $text ?: '...';
}
Expand Down Expand Up @@ -706,7 +703,7 @@ public static function validate(string $key, $type = 'string')
* Получаем число в приятном глазу формате (для чисел более 10к)
*
* @param int $value
* @return float
* @return int|float
*/
public static function getFriendlyNumber(int $value = 0)
{
Expand Down
24 changes: 14 additions & 10 deletions Sources/LightPortal/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bugo\LightPortal;

use Likes;

/**
* Integration.php
*
Expand All @@ -11,7 +13,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -73,8 +75,8 @@ public function userInfo()

$lp_constants = [
'LP_NAME' => 'Light Portal',
'LP_VERSION' => '1.7.1',
'LP_RELEASE_DATE' => '2021-04-04',
'LP_VERSION' => '1.8',
'LP_RELEASE_DATE' => '2021-06-06',
'LP_DEBUG' => !empty($modSettings['lp_show_debug_info']) && !empty($user_info['is_admin']),
'LP_CACHE_TIME' => $modSettings['lp_cache_update_interval'] ?? 3600,
'LP_ADDON_DIR' => $sourcedir . '/LightPortal/addons'
Expand Down Expand Up @@ -142,10 +144,12 @@ public function redirect(string &$setLocation)
*/
public function actions(array &$actions)
{
global $context, $modSettings;
global $modSettings, $context;

if (!empty($modSettings['lp_frontpage_mode']))
$actions['portal'] = array('LightPortal/FrontPage.php', array(new FrontPage, 'show'));

$actions['portal'] = array('LightPortal/FrontPage.php', array(new FrontPage, 'show'));
$actions['forum'] = array('BoardIndex.php', 'BoardIndex');
$actions['forum'] = array('BoardIndex.php', 'BoardIndex');

if (Helpers::request()->is('portal') && $context['current_subaction'] == 'categories')
return call_user_func(array(new Category, 'show'));
Expand All @@ -154,9 +158,9 @@ public function actions(array &$actions)
return call_user_func(array(new Tag, 'show'));

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

if (!empty($context['current_action']) && array_key_exists($context['current_action'], $disabled_actions))
if (!empty($context['current_action']) && array_key_exists($context['current_action'], $context['lp_disabled_actions']))
redirectexit();
}
}
Expand Down Expand Up @@ -489,10 +493,10 @@ public function validLikes(string $type, int $content)
*
* Обновляем кэш при лайке/дизлайке страниц
*
* @param \Likes $obj
* @param Likes $obj
* @return void
*/
public function issueLike(\Likes $obj)
public function issueLike(Likes $obj)
{
if ($obj->get('type') !== 'lpp')
return;
Expand Down
15 changes: 8 additions & 7 deletions Sources/LightPortal/ManageBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -90,7 +90,7 @@ public function getAll(): array

$current_blocks[$row['placement']][$row['block_id']]['title'][$row['lang']] = $row['title'];

Helpers::findMissingBlockTypes($row['type']);
Helpers::prepareMissingBlockTypes($row['type']);
}

$smcFunc['db_free_result']($request);
Expand Down Expand Up @@ -390,7 +390,7 @@ private function validateData()
{
global $context, $modSettings;

if (Helpers::post()->has('save') || Helpers::post()->has('preview')) {
if (Helpers::post()->only(['save', 'save_exit', 'preview'])) {
$args = array(
'block_id' => FILTER_VALIDATE_INT,
'icon' => FILTER_SANITIZE_STRING,
Expand Down Expand Up @@ -453,7 +453,7 @@ private function validateData()

if (!empty($context['lp_block']['options']['parameters'])) {
foreach ($context['lp_block']['options']['parameters'] as $option => $value) {
if (!empty($parameters[$option]) && !empty($post_data['parameters']) && $post_data['parameters'][$option] === null) {
if (!empty($parameters[$option]) && !empty($post_data['parameters']) && !isset($post_data['parameters'][$option])) {
if ($parameters[$option] == FILTER_VALIDATE_BOOLEAN)
$post_data['parameters'][$option] = 0;

Expand Down Expand Up @@ -851,11 +851,11 @@ private function getPriority(): int
* @param int $item
* @return int|void
*/
private function setData(int $item = 0): int
private function setData(int $item = 0)
{
global $context;

if (!empty($context['post_errors']) || (Helpers::post()->has('save') === false && Helpers::post()->has('clone') === false))
if (!empty($context['post_errors']) || (Helpers::post()->has('save') === false && Helpers::post()->has('save_exit') === false && Helpers::post()->has('clone') === false))
return 0;

checkSubmitOnce('check');
Expand All @@ -871,7 +871,8 @@ private function setData(int $item = 0): int

Helpers::cache()->flush();

redirectexit('action=admin;area=lp_blocks;sa=main');
if (Helpers::post()->has('save_exit'))
redirectexit('action=admin;area=lp_blocks;sa=main');
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Sources/LightPortal/ManagePages.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.7
* @version 1.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -640,7 +640,7 @@ private function validateData()
{
global $context, $modSettings, $user_info;

if (Helpers::post()->has('save') || Helpers::post()->has('preview')) {
if (Helpers::post()->only(['save', 'save_exit', 'preview'])) {
$args = array(
'category' => FILTER_VALIDATE_INT,
'page_author' => FILTER_VALIDATE_INT,
Expand Down Expand Up @@ -707,7 +707,7 @@ private function validateData()
);

foreach ($context['lp_page']['options'] as $option => $value) {
if (!empty($parameters[$option]) && !empty($post_data) && $post_data[$option] === null) {
if (!empty($parameters[$option]) && !empty($post_data) && !isset($post_data[$option])) {
if ($parameters[$option] == FILTER_VALIDATE_BOOLEAN)
$post_data[$option] = 0;

Expand Down Expand Up @@ -1176,7 +1176,7 @@ private function setData(int $item = 0)
{
global $context;

if (!empty($context['post_errors']) || Helpers::post()->has('save') === false)
if (!empty($context['post_errors']) || (Helpers::post()->has('save') === false && Helpers::post()->has('save_exit') === false))
return;

checkSubmitOnce('check');
Expand All @@ -1192,7 +1192,8 @@ private function setData(int $item = 0)

Helpers::cache()->flush();

redirectexit('action=admin;area=lp_pages;sa=main');
if (Helpers::post()->has('save_exit'))
redirectexit('action=admin;area=lp_pages;sa=main');
}

/**
Expand Down
Loading

0 comments on commit 6263b32

Please sign in to comment.