From 398b942ef34795fe39254e5955ea2addada3f757 Mon Sep 17 00:00:00 2001 From: Bugo Date: Sun, 11 Oct 2020 16:54:28 +0500 Subject: [PATCH 01/46] Improve behavior of modifying comments --- Sources/LightPortal/Comment.php | 8 ++-- .../default/LightPortal/ViewPage.template.php | 1 + .../scripts/light_portal/manage_comments.js | 38 +++++++++++-------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Sources/LightPortal/Comment.php b/Sources/LightPortal/Comment.php index af75edcd9..653b484c3 100644 --- a/Sources/LightPortal/Comment.php +++ b/Sources/LightPortal/Comment.php @@ -188,6 +188,7 @@ private function add() 'message' => empty($enabled_tags) ? $message : parse_bbc($message, true, 'light_portal_comments_' . $item, $enabled_tags), 'created_at' => date('Y-m-d', $time), 'created' => Helpers::getFriendlyTime($time), + 'raw_message' => $message, 'can_edit' => true ], $counter + 1, $level + 1); @@ -226,8 +227,8 @@ private function edit() { global $smcFunc, $context, $modSettings; - $json = file_get_contents('php://input'); - $data = json_decode($json, true); + $json = file_get_contents('php://input'); + $data = json_decode($json, true); if (empty($data)) return; @@ -257,7 +258,7 @@ private function edit() Helpers::getFromCache('page_' . $this->alias . '_comments', null); - exit; + exit(json_encode($message)); } /** @@ -436,6 +437,7 @@ public static function getAll(int $page_id = 0) 'author_name' => $row['author_name'], 'avatar' => $avatar, 'message' => empty($enabled_tags) ? $row['message'] : parse_bbc($row['message'], true, 'light_portal_comments_' . $page_id, $enabled_tags), + 'raw_message' => $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 ); diff --git a/Themes/default/LightPortal/ViewPage.template.php b/Themes/default/LightPortal/ViewPage.template.php index 904f2b830..09610b550 100644 --- a/Themes/default/LightPortal/ViewPage.template.php +++ b/Themes/default/LightPortal/ViewPage.template.php @@ -243,6 +243,7 @@ function show_single_comment($comment, $i = 0, $level = 1) +
= 5 ? ' style="min-height: 3em"' : '', '>', $comment['message'], '
'; if ($context['user']['is_logged'] && $level < 5) { diff --git a/Themes/default/scripts/light_portal/manage_comments.js b/Themes/default/scripts/light_portal/manage_comments.js index ce6f82d7c..84aefac6a 100644 --- a/Themes/default/scripts/light_portal/manage_comments.js +++ b/Themes/default/scripts/light_portal/manage_comments.js @@ -5,6 +5,8 @@ document.addEventListener('DOMContentLoaded', function () { commentForm = document.getElementById('comment_form'), message = document.getElementById('message'); + let current_comment; + // Increase a message height on focusing message.addEventListener('focus', function () { this.style.height = 'auto'; @@ -72,9 +74,10 @@ document.addEventListener('DOMContentLoaded', function () { message.focus(); } - function lpModifyComment() { + async function lpModifyComment() { const item = this.getAttribute('data-id'), - comment_area = document.querySelector('#comment' + item + ' .content'), + comment_content = document.querySelector('#comment' + item + ' .content'), + comment_raw_content = document.querySelector('#comment' + item + ' .raw_content'), modify_button = document.querySelector('#comment' + item + ' .modify_button'), update_button = document.querySelector('#comment' + item + ' .update_button'), cancel_button = document.querySelector('#comment' + item + ' .cancel_button'); @@ -83,11 +86,13 @@ document.addEventListener('DOMContentLoaded', function () { update_button.style.display = 'inline-block'; cancel_button.style.display = 'inline-block'; - comment_area.setAttribute('contenteditable', true); - comment_area.style.boxShadow = 'inset 2px 2px 5px rgba(154, 147, 140, 0.5), 1px 1px 5px rgba(255, 255, 255, 1)'; - comment_area.style.borderRadius = '4px'; - comment_area.style.padding = '1em'; - comment_area.focus(); + current_comment = comment_content.innerHTML; + comment_content.innerText = comment_raw_content.innerText; + comment_content.setAttribute('contenteditable', true); + comment_content.style.boxShadow = 'inset 2px 2px 5px rgba(154, 147, 140, 0.5), 1px 1px 5px rgba(255, 255, 255, 1)'; + comment_content.style.borderRadius = '4px'; + comment_content.style.padding = '1em'; + comment_content.focus(); if (document.queryCommandSupported('selectAll')) document.execCommand('selectAll', false, null); @@ -111,23 +116,26 @@ document.addEventListener('DOMContentLoaded', function () { }); if (response.ok) { - lpCancelComment(this) + let comment = await response.json(); + + lpCancelComment(this, comment) } else { console.error(response) } } - function lpCancelComment(e) { + function lpCancelComment(e, source = current_comment) { const item = (e ? e : this).getAttribute('data-id'), - comment_area = document.querySelector('#comment' + item + ' .content'), + comment_content = document.querySelector('#comment' + item + ' .content'), modify_button = document.querySelector('#comment' + item + ' .modify_button'), update_button = document.querySelector('#comment' + item + ' .update_button'), cancel_button = document.querySelector('#comment' + item + ' .cancel_button'); - comment_area.setAttribute('contenteditable', false); - comment_area.style.boxShadow = 'none'; - comment_area.style.borderRadius = 0; - comment_area.style.padding = '0 14px'; + comment_content.innerHTML = source; + comment_content.setAttribute('contenteditable', false); + comment_content.style.boxShadow = 'none'; + comment_content.style.borderRadius = 0; + comment_content.style.padding = '0 14px'; cancel_button.style.display = 'none'; update_button.style.display = 'none'; @@ -155,7 +163,7 @@ document.addEventListener('DOMContentLoaded', function () { 'Content-Type': 'application/json; charset=utf-8' }, body: JSON.stringify({ - items: items + items }) }); From 97d99e99a4042840984d2c41588e679c0b6467b4 Mon Sep 17 00:00:00 2001 From: Bugo Date: Mon, 12 Oct 2020 17:39:43 +0500 Subject: [PATCH 02/46] Add Choices.js for keywords field on add/edit pages --- Sources/LightPortal/ManagePages.php | 26 ++++++++++++++----- .../LightPortal/ManagePages.template.php | 13 +++++++++- .../languages/LightPortal/.english.php | 3 ++- .../default/languages/LightPortal/.polish.php | 3 ++- .../languages/LightPortal/.russian.php | 3 ++- .../languages/LightPortal/.spanish_es.php | 3 ++- .../languages/LightPortal/.spanish_latin.php | 3 ++- .../languages/LightPortal/.ukrainian.php | 3 ++- 8 files changed, 44 insertions(+), 13 deletions(-) diff --git a/Sources/LightPortal/ManagePages.php b/Sources/LightPortal/ManagePages.php index 44c1a7525..614a644b0 100644 --- a/Sources/LightPortal/ManagePages.php +++ b/Sources/LightPortal/ManagePages.php @@ -757,6 +757,16 @@ private static function prepareFormFields() { global $context, $txt, $modSettings, $language; + // Improve keywords field ~ https://github.com/jshjohnson/Choices + loadCssFile('https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css', array('external' => true)); + addInlineCss(' + .choices__list { + position: relative; + } + .choices__input { + box-shadow: none; + }'); + checkSubmitOnce('register'); $languages = empty($modSettings['userLanguage']) ? [$language] : ['english', $language]; @@ -828,13 +838,13 @@ private static function prepareFormFields() ); $context['posting_fields']['keywords']['label']['text'] = $txt['lp_page_keywords']; - $context['posting_fields']['keywords']['label']['after'] = '
' . $txt['lp_page_keywords_after'] . ''; $context['posting_fields']['keywords']['input'] = array( - 'type' => 'textarea', + 'type' => 'text', 'attributes' => array( - 'id' => 'keywords', - 'maxlength' => 255, - 'value' => $context['lp_page']['keywords'] + 'id' => 'keywords', + 'value' => $context['lp_page']['keywords'], + 'style' => 'width: 100%', + 'dir' => $context['right_to_left'] ? 'rtl' : 'ltr' ), 'tab' => 'seo' ); @@ -1514,7 +1524,11 @@ private static function getXmlFile() foreach ($items as $item) { $xmlElement = $xmlElements->appendChild($xml->createElement('item')); foreach ($item as $key => $val) { - $xmlName = $xmlElement->appendChild(in_array($key, ['page_id', 'author_id', 'permissions', 'status', 'num_views', 'num_comments', 'created_at', 'updated_at']) ? $xml->createAttribute($key) : $xml->createElement($key)); + $xmlName = $xmlElement->appendChild( + in_array($key, ['page_id', 'author_id', 'permissions', 'status', 'num_views', 'num_comments', 'created_at', 'updated_at']) + ? $xml->createAttribute($key) + : $xml->createElement($key) + ); if (in_array($key, ['titles', 'params'])) { foreach ($item[$key] as $k => $v) { diff --git a/Themes/default/LightPortal/ManagePages.template.php b/Themes/default/LightPortal/ManagePages.template.php index 192ea3d9d..e44856cd9 100644 --- a/Themes/default/LightPortal/ManagePages.template.php +++ b/Themes/default/LightPortal/ManagePages.template.php @@ -78,5 +78,16 @@ function template_page_post() - '; + + + '; } diff --git a/Themes/default/languages/LightPortal/.english.php b/Themes/default/languages/LightPortal/.english.php index d184f6a51..a384de2d4 100644 --- a/Themes/default/languages/LightPortal/.english.php +++ b/Themes/default/languages/LightPortal/.english.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Page type'; $txt['lp_page_description'] = 'Description'; $txt['lp_page_keywords'] = 'Keywords'; -$txt['lp_page_keywords_after'] = 'Use a comma to separate'; +$txt['lp_page_keywords_only_unique'] = 'Only unique items can be added'; +$txt['lp_page_keywords_enter_to_add'] = 'Press Enter to add "${value}"'; $txt['lp_page_publish_datetime'] = 'Date and time of publication'; $txt['lp_page_options'] = array( diff --git a/Themes/default/languages/LightPortal/.polish.php b/Themes/default/languages/LightPortal/.polish.php index 3f7919007..06657313f 100644 --- a/Themes/default/languages/LightPortal/.polish.php +++ b/Themes/default/languages/LightPortal/.polish.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Typ strony'; $txt['lp_page_description'] = 'Opis'; $txt['lp_page_keywords'] = 'Słowa kluczowe'; -$txt['lp_page_keywords_after'] = 'Oddzielone przecinkami'; +$txt['lp_page_keywords_only_unique'] = 'Only unique items can be added'; +$txt['lp_page_keywords_enter_to_add'] = 'Press Enter to add "${value}"'; $txt['lp_page_publish_datetime'] = 'Data i czas publikacji'; $txt['lp_page_options'] = array( diff --git a/Themes/default/languages/LightPortal/.russian.php b/Themes/default/languages/LightPortal/.russian.php index 538ecdf7c..5867f0c0a 100644 --- a/Themes/default/languages/LightPortal/.russian.php +++ b/Themes/default/languages/LightPortal/.russian.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Тип страницы'; $txt['lp_page_description'] = 'Описание'; $txt['lp_page_keywords'] = 'Ключевые слова'; -$txt['lp_page_keywords_after'] = 'Используйте запятую для разделения'; +$txt['lp_page_keywords_only_unique'] = 'Можно добавлять только уникальные теги'; +$txt['lp_page_keywords_enter_to_add'] = 'Нажмите Enter для добавления «${value}»'; $txt['lp_page_publish_datetime'] = 'Дата и время публикации'; $txt['lp_page_options'] = array( diff --git a/Themes/default/languages/LightPortal/.spanish_es.php b/Themes/default/languages/LightPortal/.spanish_es.php index cb2063045..cc916a918 100644 --- a/Themes/default/languages/LightPortal/.spanish_es.php +++ b/Themes/default/languages/LightPortal/.spanish_es.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Tipo de página'; $txt['lp_page_description'] = 'Descripción'; $txt['lp_page_keywords'] = 'Palabras claves'; -$txt['lp_page_keywords_after'] = 'Usa una coma para separar'; +$txt['lp_page_keywords_only_unique'] = 'Only unique items can be added'; +$txt['lp_page_keywords_enter_to_add'] = 'Press Enter to add "${value}"'; $txt['lp_page_publish_datetime'] = 'Fecha y hora de publicación'; $txt['lp_page_options'] = array( diff --git a/Themes/default/languages/LightPortal/.spanish_latin.php b/Themes/default/languages/LightPortal/.spanish_latin.php index 8d70e8fdd..47d02d319 100644 --- a/Themes/default/languages/LightPortal/.spanish_latin.php +++ b/Themes/default/languages/LightPortal/.spanish_latin.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Tipo de página'; $txt['lp_page_description'] = 'Descripción'; $txt['lp_page_keywords'] = 'Palabras claves'; -$txt['lp_page_keywords_after'] = 'Usa una coma para separar'; +$txt['lp_page_keywords_only_unique'] = 'Only unique items can be added'; +$txt['lp_page_keywords_enter_to_add'] = 'Press Enter to add "${value}"'; $txt['lp_page_publish_datetime'] = 'Fecha y hora de publicación'; $txt['lp_page_options'] = array( diff --git a/Themes/default/languages/LightPortal/.ukrainian.php b/Themes/default/languages/LightPortal/.ukrainian.php index b329176ad..91fbcfad7 100644 --- a/Themes/default/languages/LightPortal/.ukrainian.php +++ b/Themes/default/languages/LightPortal/.ukrainian.php @@ -199,7 +199,8 @@ $txt['lp_page_type'] = 'Тип сторінки'; $txt['lp_page_description'] = 'Опис'; $txt['lp_page_keywords'] = 'Ключові слова'; -$txt['lp_page_keywords_after'] = 'Використовуйте кому для розділення'; +$txt['lp_page_keywords_only_unique'] = 'Можна додавати тільки унікальні теги'; +$txt['lp_page_keywords_enter_to_add'] = 'Натисніть Enter для додавання «${value}»'; $txt['lp_page_publish_datetime'] = 'Дата і час публікації'; $txt['lp_page_options'] = array( From 970f45c88360f82cbdd192b0f1277f960ccbcbb2 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 13 Oct 2020 14:32:48 +0500 Subject: [PATCH 03/46] Add new helpers (cache, post, server) and replace getFromCache() with cache() --- Sources/LightPortal/FrontPage.php | 26 ++-- Sources/LightPortal/Helpers.php | 120 +++++++++++++----- Sources/LightPortal/Page.php | 4 +- Sources/LightPortal/Subs.php | 4 +- .../LightPortal/addons/AdsBlock/AdsBlock.php | 2 +- .../addons/ArticleList/ArticleList.php | 4 +- .../addons/BoardList/BoardList.php | 2 +- .../addons/BoardNews/BoardNews.php | 2 +- .../addons/CurrentMonth/CurrentMonth.php | 2 +- .../FlipsterCarousel/FlipsterCarousel.php | 2 +- .../LightPortal/addons/PageList/PageList.php | 4 +- .../addons/RandomTopics/RandomTopics.php | 8 +- .../RecentAttachments/RecentAttachments.php | 8 +- .../addons/RecentPosts/RecentPosts.php | 8 +- .../addons/RecentTopics/RecentTopics.php | 8 +- .../LightPortal/addons/RssFeed/RssFeed.php | 2 +- .../addons/SlickSlider/SlickSlider.php | 2 +- .../LightPortal/addons/TagList/TagList.php | 6 +- .../addons/ThemeSwitcher/ThemeSwitcher.php | 6 +- .../addons/TopBoards/TopBoards.php | 2 +- .../LightPortal/addons/TopPages/TopPages.php | 4 +- .../addons/TopPosters/TopPosters.php | 2 +- .../addons/TopTopics/TopTopics.php | 2 +- .../LightPortal/addons/UserInfo/UserInfo.php | 4 +- .../addons/WhosOnline/WhosOnline.php | 7 +- Sources/LightPortal/utils/Arr.php | 56 ++++++-- Sources/LightPortal/utils/Cache.php | 112 ++++++++++++++++ Sources/LightPortal/utils/Post.php | 25 ++++ Sources/LightPortal/utils/Request.php | 6 +- Sources/LightPortal/utils/Server.php | 25 ++++ Sources/LightPortal/utils/Session.php | 2 +- 31 files changed, 372 insertions(+), 95 deletions(-) create mode 100644 Sources/LightPortal/utils/Cache.php create mode 100644 Sources/LightPortal/utils/Post.php create mode 100644 Sources/LightPortal/utils/Server.php diff --git a/Sources/LightPortal/FrontPage.php b/Sources/LightPortal/FrontPage.php index 1f2acfd86..c2cb4142a 100644 --- a/Sources/LightPortal/FrontPage.php +++ b/Sources/LightPortal/FrontPage.php @@ -178,7 +178,7 @@ public static function getTopicsFromSelectedBoards(int $start, int $limit) if (empty($selected_boards)) return []; - if (($topics = cache_get_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { + if (($topics = Helpers::cache()->get('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { $custom_columns = []; $custom_tables = []; $custom_wheres = []; @@ -282,7 +282,7 @@ public static function getTopicsFromSelectedBoards(int $start, int $limit) $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $topics, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $topics, LP_CACHE_TIME); } return $topics; @@ -304,7 +304,7 @@ public static function getTotalTopicsFromSelectedBoards() if (empty($selected_boards)) return 0; - if (($num_topics = cache_get_data('light_portal_articles_u' . $user_info['id'] . '_total', LP_CACHE_TIME)) === null) { + if (($num_topics = Helpers::cache()->get('articles_u' . $user_info['id'] . '_total', LP_CACHE_TIME)) === null) { $request = $smcFunc['db_query']('', ' SELECT COUNT(t.id_topic) FROM {db_prefix}topics AS t @@ -326,7 +326,7 @@ public static function getTotalTopicsFromSelectedBoards() $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $user_info['id'] . '_total', (int) $num_topics, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $user_info['id'] . '_total', (int) $num_topics, LP_CACHE_TIME); } return (int) $num_topics; @@ -345,8 +345,8 @@ public static function getActivePages(int $start, int $limit) { global $user_info, $smcFunc, $modSettings, $scripturl, $context; - if (($pages = cache_get_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + if (($pages = Helpers::cache()->get('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $custom_columns = []; $custom_tables = []; @@ -422,7 +422,7 @@ public static function getActivePages(int $start, int $limit) $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $pages, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $pages, LP_CACHE_TIME); } return $pages; @@ -439,7 +439,7 @@ public static function getTotalActivePages() { global $user_info, $smcFunc, $context; - if (($num_pages = cache_get_data('light_portal_articles_u' . $user_info['id'] . '_total', LP_CACHE_TIME)) === null) { + if (($num_pages = Helpers::cache()->get('articles_u' . $user_info['id'] . '_total', LP_CACHE_TIME)) === null) { $request = $smcFunc['db_query']('', ' SELECT COUNT(page_id) FROM {db_prefix}lp_pages @@ -457,7 +457,7 @@ public static function getTotalActivePages() $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $user_info['id'] . '_total', (int) $num_pages, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $user_info['id'] . '_total', (int) $num_pages, LP_CACHE_TIME); } return (int) $num_pages; @@ -481,7 +481,7 @@ public static function getSelectedBoards(int $start, int $limit) if (empty($selected_boards)) return []; - if (($boards = cache_get_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { + if (($boards = Helpers::cache()->get('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, LP_CACHE_TIME)) === null) { $custom_columns = []; $custom_tables = []; $custom_wheres = []; @@ -566,7 +566,7 @@ public static function getSelectedBoards(int $start, int $limit) $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $boards, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $user_info['id'] . '_' . $start . '_' . $limit, $boards, LP_CACHE_TIME); } return $boards; @@ -588,7 +588,7 @@ public static function getTotalSelectedBoards() if (empty($selected_boards)) return 0; - if (($num_boards = cache_get_data('light_portal_articles_u' . $context['user']['id'] . '_total', LP_CACHE_TIME)) === null) { + if (($num_boards = Helpers::cache()->get('articles_u' . $context['user']['id'] . '_total', LP_CACHE_TIME)) === null) { $request = $smcFunc['db_query']('', ' SELECT COUNT(b.id_board) FROM {db_prefix}boards AS b @@ -604,7 +604,7 @@ public static function getTotalSelectedBoards() $smcFunc['db_free_result']($request); $context['lp_num_queries']++; - cache_put_data('light_portal_articles_u' . $context['user']['id'] . '_total', (int) $num_boards, LP_CACHE_TIME); + Helpers::cache()->put('articles_u' . $context['user']['id'] . '_total', (int) $num_boards, LP_CACHE_TIME); } return (int) $num_boards; diff --git a/Sources/LightPortal/Helpers.php b/Sources/LightPortal/Helpers.php index 3f742ded7..532ad8826 100644 --- a/Sources/LightPortal/Helpers.php +++ b/Sources/LightPortal/Helpers.php @@ -2,7 +2,10 @@ namespace Bugo\LightPortal; +use Bugo\LightPortal\Utils\Cache; +use Bugo\LightPortal\Utils\Post; use Bugo\LightPortal\Utils\Request; +use Bugo\LightPortal\Utils\Server; use Bugo\LightPortal\Utils\Session; /** @@ -23,43 +26,76 @@ class Helpers { /** - * Get the request object + * Get the cache data or Cache class object * - * Получаем объект $_REQUEST + * Получаем данные из кэша или объект класса Cache + * + * @param string $key + * @param string|null $funcName + * @param string $class + * @param int $time (in seconds) + * @param mixed $vars + * @return mixed + */ + public static function cache(string $key = null, string $funcName = null, string $class = 'self', int $time = 3600, ...$vars) + { + return $key ? (new Cache)($key, $funcName, $class, $time, ...$vars) : new Cache; + } + + /** + * Get $_POST object + * + * Получаем объект $_POST * * @param string|null $key + * @param mixed|null $default * @return mixed */ - public static function request($key = null) + public static function post($key = null, $default = null) { - return $key ? (new Request)($key) : new Request; + return $key ? (new Post)($key, $default) : new Post; } /** - * Get the session object + * Get $_REQUEST object * - * Получаем объект $_SESSION + * Получаем объект $_REQUEST * * @param string|null $key + * @param mixed|null $default * @return mixed */ - public static function session($key = null) + public static function request($key = null, $default = null) { - return $key ? (new Session)($key) : new Session; + return $key ? (new Request)($key, $default) : new Request; } /** - * Get the maximum possible length of the message, in accordance with the settings of the forum + * Get $_SERVER object * - * Получаем максимально возможную длину сообщения, в соответствии с настройками форума + * Получаем объект $_SERVER * - * @return int + * @param string|null $key + * @param mixed|null $default + * @return mixed */ - public static function getMaxMessageLength() + public static function server($key = null, $default = null) { - global $modSettings; + return $key ? (new Server)($key, $default) : new Server; + } - return !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] > 65534 ? (int) $modSettings['max_messageLength'] : 65534; + /** + * Get $_SESSION object + * + * Получаем объект $_SESSION + * + * @param string|null $key + * @param mixed|null $default + * @return mixed + */ + public static function session($key = null, $default = null) + { + return $key ? (new Session)($key, $default) : new Session; } /** @@ -355,6 +391,7 @@ public static function getDateFormat(int $day, string $month, string $postfix) * * Получаем нужные данные, используя кэш * + * @deprecated 1.2.1 Function replacement * @param string $key * @param string|null $funcName * @param string $class @@ -364,25 +401,7 @@ public static function getDateFormat(int $day, string $month, string $postfix) */ public static function getFromCache(string $key, ?string $funcName, string $class = 'self', int $time = 3600, ...$vars) { - if (empty($key)) - return false; - - if ($funcName === null || $time === 0) - cache_put_data('light_portal_' . $key, null); - - if (($$key = cache_get_data('light_portal_' . $key, $time)) === null) { - $$key = null; - - if (method_exists($class, $funcName)) { - $$key = $class == 'self' ? self::$funcName(...$vars) : $class::$funcName(...$vars); - } elseif (function_exists($funcName)) { - $$key = $funcName(...$vars); - } - - cache_put_data('light_portal_' . $key, $$key, $time); - } - - return $$key; + return self::cache($key, $funcName, $class, $time, ...$vars); } /** @@ -569,4 +588,39 @@ public static function getForumThemes() return $current_themes; } + + /** + * Get the filtered $obj[$key] + * + * Получаем отфильтрованное значение $obj[$key] + * + * @param string $key + * @param string|array $type + * @return mixed + */ + public static function validate($key, $type = 'string') + { + if (is_array($type)) { + return filter_var($key, FILTER_VALIDATE_REGEXP, $type); + } + + switch ($type) { + case 'string': + $filter = FILTER_SANITIZE_STRING; + break; + case 'int': + $filter = FILTER_VALIDATE_INT; + break; + case 'bool': + $filter = FILTER_VALIDATE_BOOLEAN; + break; + case 'url': + $filter = FILTER_VALIDATE_URL; + break; + default: + $filter = FILTER_DEFAULT; + } + + return filter_var($key, $filter); + } } diff --git a/Sources/LightPortal/Page.php b/Sources/LightPortal/Page.php index 45dd7496e..6ff3c580c 100644 --- a/Sources/LightPortal/Page.php +++ b/Sources/LightPortal/Page.php @@ -35,7 +35,7 @@ public static function show() isAllowedTo('light_portal_view'); - $alias = filter_input(INPUT_GET, 'page'); + $alias = Helpers::request('page'); if (empty($alias) && !empty($modSettings['lp_frontpage_mode']) && $modSettings['lp_frontpage_mode'] == 1 && !empty($modSettings['lp_frontpage_alias'])) { $context['lp_page'] = self::getDataByAlias($modSettings['lp_frontpage_alias']); @@ -342,7 +342,7 @@ public static function getDataByAlias(string $alias) if (empty($alias)) return []; - $data = Helpers::getFromCache('page_' . $alias, 'getData', __CLASS__, LP_CACHE_TIME, array('alias' => $alias)); + $data = Helpers::cache('page_' . $alias, 'getData', __CLASS__, LP_CACHE_TIME, array('alias' => $alias)); self::prepareData($data); return $data; diff --git a/Sources/LightPortal/Subs.php b/Sources/LightPortal/Subs.php index a1da7be96..553dd2f74 100644 --- a/Sources/LightPortal/Subs.php +++ b/Sources/LightPortal/Subs.php @@ -49,8 +49,8 @@ public static function loadBlocks() $context['lp_all_content_classes'] = self::getContentClasses(); $context['lp_fontawesome_enabled'] = Helpers::doesThisThemeUseFontAwesome(); - $context['lp_active_blocks'] = Helpers::getFromCache('active_blocks', 'getActiveBlocks', __CLASS__); - $context['lp_num_active_pages'] = Helpers::getFromCache('num_active_pages_u' . $context['user']['id'], 'getNumActivePages', __CLASS__); + $context['lp_active_blocks'] = Helpers::cache('active_blocks', 'getActiveBlocks', __CLASS__); + $context['lp_num_active_pages'] = Helpers::cache('num_active_pages_u' . $context['user']['id'], 'getNumActivePages', __CLASS__); // Width of some panels | Ширина некоторых панелей $context['lp_header_panel_width'] = !empty($modSettings['lp_header_panel_width']) ? (int) $modSettings['lp_header_panel_width'] : 12; diff --git a/Sources/LightPortal/addons/AdsBlock/AdsBlock.php b/Sources/LightPortal/addons/AdsBlock/AdsBlock.php index 83809d13b..6b901fcab 100644 --- a/Sources/LightPortal/addons/AdsBlock/AdsBlock.php +++ b/Sources/LightPortal/addons/AdsBlock/AdsBlock.php @@ -91,7 +91,7 @@ public static function menuButtons() if (empty($context['current_board'])) return; - $context['lp_ads_blocks'] = Helpers::getFromCache('ads_block_addon', 'getData', __CLASS__); + $context['lp_ads_blocks'] = Helpers::cache('ads_block_addon', 'getData', __CLASS__); if (!empty($context['lp_ads_blocks'])) $context['lp_blocks'] = array_merge($context['lp_blocks'], $context['lp_ads_blocks']); diff --git a/Sources/LightPortal/addons/ArticleList/ArticleList.php b/Sources/LightPortal/addons/ArticleList/ArticleList.php index b4b7eac0a..3986fd22c 100644 --- a/Sources/LightPortal/addons/ArticleList/ArticleList.php +++ b/Sources/LightPortal/addons/ArticleList/ArticleList.php @@ -270,7 +270,7 @@ public static function getPages(array $parameters) if (empty($parameters['ids'])) return []; - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $request = $smcFunc['db_query']('', ' SELECT page_id, alias, content, description, type @@ -342,7 +342,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, }); $function = empty($parameters['article_type']) ? 'getTopics' : 'getPages'; - $article_list = Helpers::getFromCache('article_list_addon_b' . $block_id . '_u' . $user_info['id'], $function, __CLASS__, $cache_time, $parameters); + $article_list = Helpers::cache('article_list_addon_b' . $block_id . '_u' . $user_info['id'], $function, __CLASS__, $cache_time, $parameters); ob_start(); diff --git a/Sources/LightPortal/addons/BoardList/BoardList.php b/Sources/LightPortal/addons/BoardList/BoardList.php index 985a0a95d..ea5b39e6c 100644 --- a/Sources/LightPortal/addons/BoardList/BoardList.php +++ b/Sources/LightPortal/addons/BoardList/BoardList.php @@ -196,7 +196,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'board_list') return; - $board_list = Helpers::getFromCache('board_list_addon_b' . $block_id . '_u' . $context['user']['id'], 'getData', __CLASS__, $cache_time); + $board_list = Helpers::cache('board_list_addon_b' . $block_id . '_u' . $context['user']['id'], 'getData', __CLASS__, $cache_time); if (!empty($board_list)) { $context['current_board'] = $context['current_board'] ?? 0; diff --git a/Sources/LightPortal/addons/BoardNews/BoardNews.php b/Sources/LightPortal/addons/BoardNews/BoardNews.php index a94bb430b..d295560c6 100644 --- a/Sources/LightPortal/addons/BoardNews/BoardNews.php +++ b/Sources/LightPortal/addons/BoardNews/BoardNews.php @@ -194,7 +194,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'board_news') return; - $board_news = Helpers::getFromCache('board_news_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $board_news = Helpers::cache('board_news_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); if (!empty($board_news)) { ob_start(); diff --git a/Sources/LightPortal/addons/CurrentMonth/CurrentMonth.php b/Sources/LightPortal/addons/CurrentMonth/CurrentMonth.php index 565b1d360..e406e06fc 100644 --- a/Sources/LightPortal/addons/CurrentMonth/CurrentMonth.php +++ b/Sources/LightPortal/addons/CurrentMonth/CurrentMonth.php @@ -188,7 +188,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time) if ($type !== 'current_month') return; - $calendar_data = Helpers::getFromCache('current_month_addon_u' . $user_info['id'], 'getData', __CLASS__, $cache_time); + $calendar_data = Helpers::cache('current_month_addon_u' . $user_info['id'], 'getData', __CLASS__, $cache_time); if (!empty($calendar_data)) { ob_start(); diff --git a/Sources/LightPortal/addons/FlipsterCarousel/FlipsterCarousel.php b/Sources/LightPortal/addons/FlipsterCarousel/FlipsterCarousel.php index f548d2db5..fcd8fc993 100644 --- a/Sources/LightPortal/addons/FlipsterCarousel/FlipsterCarousel.php +++ b/Sources/LightPortal/addons/FlipsterCarousel/FlipsterCarousel.php @@ -245,7 +245,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'flipster_carousel') return; - $flipster_html = Helpers::getFromCache('flipster_carousel_addon_b' . $block_id, 'getHtml', __CLASS__, $cache_time, $block_id, $parameters); + $flipster_html = Helpers::cache('flipster_carousel_addon_b' . $block_id, 'getHtml', __CLASS__, $cache_time, $block_id, $parameters); if (!empty($flipster_html)) { loadCSSFile('https://cdn.jsdelivr.net/npm/jquery.flipster@1/dist/jquery.flipster.min.css', array('external' => true)); diff --git a/Sources/LightPortal/addons/PageList/PageList.php b/Sources/LightPortal/addons/PageList/PageList.php index 99b4bde08..428453a3f 100644 --- a/Sources/LightPortal/addons/PageList/PageList.php +++ b/Sources/LightPortal/addons/PageList/PageList.php @@ -141,7 +141,7 @@ public static function getData(array $parameters) { global $smcFunc, $txt, $context; - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $request = $smcFunc['db_query']('', ' SELECT @@ -210,7 +210,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'page_list') return; - $page_list = Helpers::getFromCache('page_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $page_list = Helpers::cache('page_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); ob_start(); diff --git a/Sources/LightPortal/addons/RandomTopics/RandomTopics.php b/Sources/LightPortal/addons/RandomTopics/RandomTopics.php index 619424370..b449613ff 100644 --- a/Sources/LightPortal/addons/RandomTopics/RandomTopics.php +++ b/Sources/LightPortal/addons/RandomTopics/RandomTopics.php @@ -263,7 +263,13 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'random_topics') return; - $random_topics = Helpers::getFromCache('random_topics_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters['num_topics']); + $random_topics = Helpers::cache( + 'random_topics_addon_b' . $block_id . '_u' . $user_info['id'], + 'getData', + __CLASS__, + $cache_time, + $parameters['num_topics'] + ); if (!empty($random_topics)) { ob_start(); diff --git a/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php b/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php index 55e158abf..3a91861bc 100644 --- a/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php +++ b/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php @@ -188,7 +188,13 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'recent_attachments') return; - $attachment_list = Helpers::getFromCache('recent_attachments_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $attachment_list = Helpers::cache( + 'recent_attachments_addon_b' . $block_id . '_u' . $user_info['id'], + 'getData', + __CLASS__, + $cache_time, + $parameters + ); if (!empty($attachment_list)) { ob_start(); diff --git a/Sources/LightPortal/addons/RecentPosts/RecentPosts.php b/Sources/LightPortal/addons/RecentPosts/RecentPosts.php index d2c96dd73..c520f89c3 100644 --- a/Sources/LightPortal/addons/RecentPosts/RecentPosts.php +++ b/Sources/LightPortal/addons/RecentPosts/RecentPosts.php @@ -353,7 +353,13 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'recent_posts') return; - $recent_posts = Helpers::getFromCache('recent_posts_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $parameters['update_interval'] ?? $cache_time, $parameters); + $recent_posts = Helpers::cache( + 'recent_posts_addon_b' . $block_id . '_u' . $user_info['id'], + 'getData', + __CLASS__, + $parameters['update_interval'] ?? $cache_time, + $parameters + ); if (!empty($recent_posts)) { ob_start(); diff --git a/Sources/LightPortal/addons/RecentTopics/RecentTopics.php b/Sources/LightPortal/addons/RecentTopics/RecentTopics.php index 8db1f7382..632ddba18 100644 --- a/Sources/LightPortal/addons/RecentTopics/RecentTopics.php +++ b/Sources/LightPortal/addons/RecentTopics/RecentTopics.php @@ -259,7 +259,13 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'recent_topics') return; - $recent_topics = Helpers::getFromCache('recent_topics_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $parameters['update_interval'] ?? $cache_time, $parameters); + $recent_topics = Helpers::cache( + 'recent_topics_addon_b' . $block_id . '_u' . $user_info['id'], + 'getData', + __CLASS__, + $parameters['update_interval'] ?? $cache_time, + $parameters + ); if (!empty($recent_topics)) { ob_start(); diff --git a/Sources/LightPortal/addons/RssFeed/RssFeed.php b/Sources/LightPortal/addons/RssFeed/RssFeed.php index 2c61d7608..a55244e20 100644 --- a/Sources/LightPortal/addons/RssFeed/RssFeed.php +++ b/Sources/LightPortal/addons/RssFeed/RssFeed.php @@ -154,7 +154,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'rss_feed') return; - $rss_feed = Helpers::getFromCache('rss_feed_addon_b' . $block_id, 'getData', __CLASS__, $cache_time, $parameters['url']); + $rss_feed = Helpers::cache('rss_feed_addon_b' . $block_id, 'getData', __CLASS__, $cache_time, $parameters['url']); if (!empty($rss_feed)) { ob_start(); diff --git a/Sources/LightPortal/addons/SlickSlider/SlickSlider.php b/Sources/LightPortal/addons/SlickSlider/SlickSlider.php index e378d28cb..5be78766c 100644 --- a/Sources/LightPortal/addons/SlickSlider/SlickSlider.php +++ b/Sources/LightPortal/addons/SlickSlider/SlickSlider.php @@ -310,7 +310,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'slick_slider') return; - $slick_slider_html = Helpers::getFromCache('slick_slider_addon_b' . $block_id, 'getHtml', __CLASS__, $cache_time, $block_id, $parameters); + $slick_slider_html = Helpers::cache('slick_slider_addon_b' . $block_id, 'getHtml', __CLASS__, $cache_time, $block_id, $parameters); if (!empty($slick_slider_html)) { loadCSSFile('https://cdn.jsdelivr.net/npm/slick-carousel@1/slick/slick.css', array('external' => true)); diff --git a/Sources/LightPortal/addons/TagList/TagList.php b/Sources/LightPortal/addons/TagList/TagList.php index 0a210dd02..7b29a57ea 100644 --- a/Sources/LightPortal/addons/TagList/TagList.php +++ b/Sources/LightPortal/addons/TagList/TagList.php @@ -167,9 +167,11 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, return; if ($parameters['source'] == 'lp_tags') { - $tag_list = Helpers::getFromCache('tag_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getAll', '\Bugo\LightPortal\Tag', $cache_time, ...array(0, 0, 'value')); + $tag_list = Helpers::cache( + 'tag_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getAll', '\Bugo\LightPortal\Tag', $cache_time, ...array(0, 0, 'value') + ); } else { - $tag_list = Helpers::getFromCache('tag_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getAllTopicKeywords', __CLASS__, $cache_time); + $tag_list = Helpers::cache('tag_list_addon_b' . $block_id . '_u' . $user_info['id'], 'getAllTopicKeywords', __CLASS__, $cache_time); } ob_start(); diff --git a/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php b/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php index 2c48d528a..1c1b9f86e 100644 --- a/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php +++ b/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php @@ -84,7 +84,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time) if ($type !== 'theme_switcher') return; - $available_themes = Helpers::getFromCache('theme_switcher_addon', 'getAvailableThemes', __CLASS__, $cache_time); + $available_themes = Helpers::cache('theme_switcher_addon', 'getAvailableThemes', __CLASS__, $cache_time); if (!empty($available_themes)) { ob_start(); @@ -111,9 +111,7 @@ function lp_block_', $block_id, '_themeswitcher_change() { search = search != "" ? search + ";" : "?"; window.location = window.location.origin + window.location.pathname + search + "theme=" + lp_block_', $block_id, '_themeswitcher_theme_id; } - '; - - echo ' + '; $content = ob_get_clean(); diff --git a/Sources/LightPortal/addons/TopBoards/TopBoards.php b/Sources/LightPortal/addons/TopBoards/TopBoards.php index bb62ec7fa..c77b6ed46 100644 --- a/Sources/LightPortal/addons/TopBoards/TopBoards.php +++ b/Sources/LightPortal/addons/TopBoards/TopBoards.php @@ -149,7 +149,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'top_boards') return; - $top_boards = Helpers::getFromCache('top_boards_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $top_boards = Helpers::cache('top_boards_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); if (!empty($top_boards)) { ob_start(); diff --git a/Sources/LightPortal/addons/TopPages/TopPages.php b/Sources/LightPortal/addons/TopPages/TopPages.php index 096fea7ef..dbfe4dfbf 100644 --- a/Sources/LightPortal/addons/TopPages/TopPages.php +++ b/Sources/LightPortal/addons/TopPages/TopPages.php @@ -160,7 +160,7 @@ public static function getData($parameters) { global $smcFunc, $scripturl, $context; - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $request = $smcFunc['db_query']('', ' SELECT page_id, alias, type, num_views, num_comments @@ -217,7 +217,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'top_pages') return; - $top_pages = Helpers::getFromCache('top_pages_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $top_pages = Helpers::cache('top_pages_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); ob_start(); diff --git a/Sources/LightPortal/addons/TopPosters/TopPosters.php b/Sources/LightPortal/addons/TopPosters/TopPosters.php index 9a3f6c782..333a6a792 100644 --- a/Sources/LightPortal/addons/TopPosters/TopPosters.php +++ b/Sources/LightPortal/addons/TopPosters/TopPosters.php @@ -195,7 +195,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'top_posters') return; - $top_posters = Helpers::getFromCache('top_posters_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $top_posters = Helpers::cache('top_posters_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); if (!empty($top_posters)) { ob_start(); diff --git a/Sources/LightPortal/addons/TopTopics/TopTopics.php b/Sources/LightPortal/addons/TopTopics/TopTopics.php index 462f69d46..089aa7081 100644 --- a/Sources/LightPortal/addons/TopTopics/TopTopics.php +++ b/Sources/LightPortal/addons/TopTopics/TopTopics.php @@ -183,7 +183,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'top_topics') return; - $top_topics = Helpers::getFromCache('top_topics_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); + $top_topics = Helpers::cache('top_topics_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $cache_time, $parameters); if (!empty($top_topics)) { ob_start(); diff --git a/Sources/LightPortal/addons/UserInfo/UserInfo.php b/Sources/LightPortal/addons/UserInfo/UserInfo.php index 778fc7c33..1dccd1ae7 100644 --- a/Sources/LightPortal/addons/UserInfo/UserInfo.php +++ b/Sources/LightPortal/addons/UserInfo/UserInfo.php @@ -70,7 +70,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time) ob_start(); if ($context['user']['is_logged']) { - $userData = Helpers::getFromCache('user_info_addon_u' . $context['user']['id'], 'getData', __CLASS__, $cache_time); + $userData = Helpers::cache('user_info_addon_u' . $context['user']['id'], 'getData', __CLASS__, $cache_time); echo '
    @@ -78,7 +78,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time) if (!empty($userData['avatar'])) { echo ' -
  • ', $userData['avatar']['image'], '
  • '; +
  • ', $userData['avatar']['image'], '
  • '; } $fa = false; diff --git a/Sources/LightPortal/addons/WhosOnline/WhosOnline.php b/Sources/LightPortal/addons/WhosOnline/WhosOnline.php index 29eebf170..04bc4e211 100644 --- a/Sources/LightPortal/addons/WhosOnline/WhosOnline.php +++ b/Sources/LightPortal/addons/WhosOnline/WhosOnline.php @@ -128,7 +128,12 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, if ($type !== 'whos_online') return; - $whos_online = Helpers::getFromCache('whos_online_addon_b' . $block_id . '_u' . $user_info['id'], 'getData', __CLASS__, $parameters['update_interval'] ?? $cache_time); + $whos_online = Helpers::cache( + 'whos_online_addon_b' . $block_id . '_u' . $user_info['id'], + 'getData', + __CLASS__, + $parameters['update_interval'] ?? $cache_time + ); if (!empty($whos_online)) { ob_start(); diff --git a/Sources/LightPortal/utils/Arr.php b/Sources/LightPortal/utils/Arr.php index f2922abd2..186efb338 100644 --- a/Sources/LightPortal/utils/Arr.php +++ b/Sources/LightPortal/utils/Arr.php @@ -21,16 +21,20 @@ abstract class Arr /** * Try run this object as a function * + * Пытаемся запустить данный объект как функцию + * * @param string $key * @return mixed */ - public function __invoke($name, $default = null) + public function __invoke($key, $default = null) { - return static::get($name) ?? $default; + return static::get($key) ?? $default; } /** - * Get the session key + * Get the $obj[$key] value + * + * Получаем значение $obj[$key] * * @param string $key * @param mixed $default @@ -42,19 +46,23 @@ public static function &get($key) } /** - * Put the key into a session + * Put $value into the $obj[$key] + * + * Сохраняем $value в ячейке $obj[$key] * * @param string $key * @param mixed $value * @return void */ - public static function put($key, &$value) + public static function put($key, $value) { static::$obj[$key] = &$value; } /** - * Get all request array + * Get all $obj values + * + * Получаем все содержимое $obj * * @return array */ @@ -66,6 +74,8 @@ public static function all() /** * Get only the request keys that defined in $keys * + * Получаем значения только запрошенных ключей $keys в $obj + * * @param array|string $keys * @return array */ @@ -87,6 +97,8 @@ public static function only($keys) /** * Get only the request keys that not defined in $keys * + * Получаем значения только тех ключей в $obj, которые не перечислены в $keys + * * @param array|string $keys * @return array */ @@ -106,7 +118,9 @@ public static function except($keys) } /** - * Push a value into the session key-array + * Push a value into the key-array + * + * Сохраняем значение $value в переменную-массив $key * * @param string $key * @param mixed $value @@ -126,7 +140,9 @@ public static function push($key, $value) } /** - * Unset the session key + * Unset the $obj key + * + * Очищаем содержимое ячейки $obj[$key] * * @param string $key * @return void @@ -137,7 +153,9 @@ public static function forget($key) } /** - * Unset all session array + * Unset all $obj array + * + * Очищаем все содержимое $obj * * @return void */ @@ -147,7 +165,9 @@ public static function flush() } /** - * Get and unset the session key + * Get and unset the key + * + * Получаем значение ячейки $obj[$key] и тут же очищаем её * * @param string $key * @param mixed $default @@ -163,7 +183,9 @@ public static function pull($key, $default = null) } /** - * Check if the session key is set + * Check if the key is set + * + * Проверяем, существует ли ключ $key в $obj * * @param string|array $key * @return bool @@ -188,7 +210,9 @@ public static function exists($key) } /** - * Check if the session key exists + * Check if the key is not empty + * + * Проверяем, не пуста ли ячейка $obj[$key] * * @param string $key * @return bool @@ -198,6 +222,14 @@ public static function filled($key) return ! static::isEmpty($key); } + /** + * Check if the key is empty + * + * Проверяем, пуста ли ячейка $obj[$key] + * + * @param string $key + * @return bool + */ public static function isEmpty($key) { return empty(static::$obj[$key]); diff --git a/Sources/LightPortal/utils/Cache.php b/Sources/LightPortal/utils/Cache.php new file mode 100644 index 000000000..85ffa0ec2 --- /dev/null +++ b/Sources/LightPortal/utils/Cache.php @@ -0,0 +1,112 @@ + + * @copyright 2019-2020 Bugo + * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later + * + * @version 1.2 + */ + +if (!defined('SMF')) + die('Hacking attempt...'); + +class Cache +{ + private static $prefix = 'light_portal_'; + + /** + * Get data from cache + * + * Получаем данные из кэша + * + * @param string $key + * @param string|null $funcName + * @param string $class + * @param int $time (in seconds) + * @param mixed $vars + * @return mixed + */ + public function __invoke(string $key, ?string $funcName, string $class = 'self', int $time = 3600, ...$vars) + { + if (empty($key)) + return false; + + if ($funcName === null || $time === 0) + static::forget($key); + + if (($$key = static::get($key, $time)) === null) { + $$key = null; + + if (method_exists($class, $funcName)) { + $$key = $class == 'self' ? self::$funcName(...$vars) : $class::$funcName(...$vars); + } elseif (function_exists($funcName)) { + $$key = $funcName(...$vars); + } + + static::put($key, $$key, $time); + } + + return $$key; + } + + /** + * Get $key value from the cache + * + * Получаем значение ячейки $key из кэша + * + * @param string $key + * @param int $time + * @return null|mixed + */ + public static function get($key, $time) + { + return cache_get_data(static::$prefix . $key, $time); + } + + /** + * Put $value into $key in the cache for $time ms + * + * Кладем $value в ячейку $key в кэше, на $time мс + * + * @param string $key + * @param mixed $value + * @param int $time + * @return void + */ + public static function put($key, $value, $time = null) + { + cache_put_data(static::$prefix . $key, $value, $time); + } + + /** + * Clear $key from the cache + * + * Очищаем ячейку $key в кэше + * + * @param string $key + * @return void + */ + public static function forget($key) + { + self::put($key, null); + } + + /** + * Clear cache + * + * Очищаем кэш + * + * @return void + */ + public static function flush() + { + clean_cache(); + } +} diff --git a/Sources/LightPortal/utils/Post.php b/Sources/LightPortal/utils/Post.php new file mode 100644 index 000000000..9dd32a790 --- /dev/null +++ b/Sources/LightPortal/utils/Post.php @@ -0,0 +1,25 @@ + + * @copyright 2019-2020 Bugo + * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later + * + * @version 1.2 + */ + +class Post extends Request +{ + public static $obj; + + public function __construct() + { + static::$obj = &$_POST; + } +} diff --git a/Sources/LightPortal/utils/Request.php b/Sources/LightPortal/utils/Request.php index e675e4c2f..0c7202e0b 100644 --- a/Sources/LightPortal/utils/Request.php +++ b/Sources/LightPortal/utils/Request.php @@ -20,7 +20,7 @@ class Request extends Arr public function __construct() { - static::$obj = $_REQUEST; + static::$obj = &$_REQUEST; } /** @@ -30,7 +30,7 @@ public function __construct() */ public static function path() { - return $_SERVER['REQUEST_URI'] ?? ''; + return Server('REQUEST_URI', ''); } /** @@ -50,7 +50,7 @@ public static function url() */ public static function fullUrl() { - return $_SERVER['REQUEST_URL'] ?? ''; + return Server('REQUEST_URL', ''); } /** diff --git a/Sources/LightPortal/utils/Server.php b/Sources/LightPortal/utils/Server.php new file mode 100644 index 000000000..3ad231a13 --- /dev/null +++ b/Sources/LightPortal/utils/Server.php @@ -0,0 +1,25 @@ + + * @copyright 2019-2020 Bugo + * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later + * + * @version 1.2 + */ + +class Server extends Arr +{ + public static $obj; + + public function __construct() + { + static::$obj = &$_SERVER; + } +} diff --git a/Sources/LightPortal/utils/Session.php b/Sources/LightPortal/utils/Session.php index 2a33f066e..0f015dd0a 100644 --- a/Sources/LightPortal/utils/Session.php +++ b/Sources/LightPortal/utils/Session.php @@ -20,6 +20,6 @@ class Session extends Arr public function __construct() { - static::$obj = $_SESSION; + static::$obj = &$_SESSION; } } From a57c733e1066ccc1714ea331f3754ecc2bb106e3 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 13 Oct 2020 14:33:31 +0500 Subject: [PATCH 04/46] Update some addons --- Sources/LightPortal/addons/BoardIndex/BoardIndex.php | 4 ++++ .../LightPortal/addons/BoardIndex/langs/english.php | 2 +- .../LightPortal/addons/BoardIndex/langs/russian.php | 2 +- .../LightPortal/addons/BoardIndex/langs/ukrainian.php | 2 +- .../LightPortal/addons/HidingBlocks/HidingBlocks.php | 4 +++- .../addons/LanguageAccess/LanguageAccess.php | 4 +++- Themes/default/css/light_portal/light_portal.css | 2 +- Themes/default/css/light_portal/light_portal.less | 11 +++++++++++ 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Sources/LightPortal/addons/BoardIndex/BoardIndex.php b/Sources/LightPortal/addons/BoardIndex/BoardIndex.php index d83429c1d..8ebbedee7 100644 --- a/Sources/LightPortal/addons/BoardIndex/BoardIndex.php +++ b/Sources/LightPortal/addons/BoardIndex/BoardIndex.php @@ -56,6 +56,10 @@ public static function addSettings(&$config_vars) */ public static function init() { + global $txt, $scripturl; + + $txt['lp_board_index_description'] = sprintf($txt['lp_board_index_description'], $scripturl . '?action=forum'); + add_integration_function('integrate_mark_read_button', __CLASS__ . '::toggleRobotNoIndex', false, __FILE__); } diff --git a/Sources/LightPortal/addons/BoardIndex/langs/english.php b/Sources/LightPortal/addons/BoardIndex/langs/english.php index 35f38a524..74e7ae0df 100644 --- a/Sources/LightPortal/addons/BoardIndex/langs/english.php +++ b/Sources/LightPortal/addons/BoardIndex/langs/english.php @@ -1,5 +1,5 @@ ?action=forum) if the portal is enabled.'; +$txt['lp_board_index_description'] = 'Additional settings of the forum home page if the portal is enabled.'; $txt['lp_board_index_addon_allow_for_spiders'] = 'Allow indexing of the forum home page'; diff --git a/Sources/LightPortal/addons/BoardIndex/langs/russian.php b/Sources/LightPortal/addons/BoardIndex/langs/russian.php index 0441fc11e..a01f10ae7 100644 --- a/Sources/LightPortal/addons/BoardIndex/langs/russian.php +++ b/Sources/LightPortal/addons/BoardIndex/langs/russian.php @@ -1,5 +1,5 @@ ?action=forum), если включен портал.'; +$txt['lp_board_index_description'] = 'Дополнительные настройки главной страницы форума, если включен портал.'; $txt['lp_board_index_addon_allow_for_spiders'] = 'Разрешить индексацию главной страницы форума'; diff --git a/Sources/LightPortal/addons/BoardIndex/langs/ukrainian.php b/Sources/LightPortal/addons/BoardIndex/langs/ukrainian.php index dd9ae304f..d0de5b9e5 100644 --- a/Sources/LightPortal/addons/BoardIndex/langs/ukrainian.php +++ b/Sources/LightPortal/addons/BoardIndex/langs/ukrainian.php @@ -1,5 +1,5 @@ ?action=forum), якщо включений портал.'; +$txt['lp_board_index_description'] = 'Додаткові налаштування головної сторінки форуму, якщо включений портал.'; $txt['lp_board_index_addon_allow_for_spiders'] = 'Дозволити індексацію головної сторінки форуму'; diff --git a/Sources/LightPortal/addons/HidingBlocks/HidingBlocks.php b/Sources/LightPortal/addons/HidingBlocks/HidingBlocks.php index 23c06d190..d3143da99 100644 --- a/Sources/LightPortal/addons/HidingBlocks/HidingBlocks.php +++ b/Sources/LightPortal/addons/HidingBlocks/HidingBlocks.php @@ -2,6 +2,8 @@ namespace Bugo\LightPortal\Addons\HidingBlocks; +use Bugo\LightPortal\Helpers; + /** * HidingBlocks * @@ -122,7 +124,7 @@ public static function prepareBlockFields() if (isset($context['lp_block']['options']['parameters']['hidden_breakpoints'])) { $context['lp_block']['options']['parameters']['hidden_breakpoints'] = is_array($context['lp_block']['options']['parameters']['hidden_breakpoints']) ? $context['lp_block']['options']['parameters']['hidden_breakpoints'] : explode(',', $context['lp_block']['options']['parameters']['hidden_breakpoints']); } else - $context['lp_block']['options']['parameters']['hidden_breakpoints'] = $_POST['hidden_breakpoints'] ?? []; + $context['lp_block']['options']['parameters']['hidden_breakpoints'] = Helpers::post('hidden_breakpoints', []); $context['posting_fields']['hidden_breakpoints']['label']['text'] = $txt['lp_hiding_blocks_addon_hidden_breakpoints']; $context['posting_fields']['hidden_breakpoints']['input'] = array( diff --git a/Sources/LightPortal/addons/LanguageAccess/LanguageAccess.php b/Sources/LightPortal/addons/LanguageAccess/LanguageAccess.php index db96494f9..21effc862 100644 --- a/Sources/LightPortal/addons/LanguageAccess/LanguageAccess.php +++ b/Sources/LightPortal/addons/LanguageAccess/LanguageAccess.php @@ -2,6 +2,8 @@ namespace Bugo\LightPortal\Addons\LanguageAccess; +use Bugo\LightPortal\Helpers; + /** * LanguageAccess * @@ -108,7 +110,7 @@ public static function prepareBlockFields() if (isset($context['lp_block']['options']['parameters']['allowed_languages'])) { $context['lp_block']['options']['parameters']['allowed_languages'] = is_array($context['lp_block']['options']['parameters']['allowed_languages']) ? $context['lp_block']['options']['parameters']['allowed_languages'] : explode(',', $context['lp_block']['options']['parameters']['allowed_languages']); } else - $context['lp_block']['options']['parameters']['allowed_languages'] = $_POST['allowed_languages'] ?? []; + $context['lp_block']['options']['parameters']['allowed_languages'] = Helpers::post('allowed_languages', []); $context['posting_fields']['allowed_languages']['label']['text'] = $txt['lp_language_access_addon_allowed_languages']; $context['posting_fields']['allowed_languages']['input'] = array( diff --git a/Themes/default/css/light_portal/light_portal.css b/Themes/default/css/light_portal/light_portal.css index c41d4b878..e66dcf6e8 100644 --- a/Themes/default/css/light_portal/light_portal.css +++ b/Themes/default/css/light_portal/light_portal.css @@ -1 +1 @@ -.fa-portal::before{content:"\f0ac"}.actions .fas{vertical-align:middle}.block_bbc .videocontainer,.block_html .videocontainer,.block_md .videocontainer{margin:0 auto}.preview .button{float:none !important}.descbox{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.descbox .bbc_code{overflow:hidden !important}#lp_blocks .item{cursor:pointer;height:96%}#block_icon i{vertical-align:middle}#info_center{margin-bottom:5px}#admin_form_wrapper p.errorbox{margin:0}#lp_layout h3:hover,#lp_layout h4:hover{white-space:normal}#lp_layout .file_content{white-space:break-spaces}#lp_layout #post_confirm_buttons{padding:12px 0 0 0 !important}#lp_layout .row>aside{margin:0 !important}#lp_layout .sticky_sidebar{position:sticky;top:5px}#lp_layout aside>div>h3,#lp_layout aside>div>h4{white-space:nowrap;text-overflow:ellipsis}#lp_layout aside[id^="block"]:not(:first-child){clear:both;margin-top:4px}.related_pages{margin-top:1em}.related_pages .article_list{grid-template-columns:repeat(4, 1fr)}.related_pages .article_list div{text-align:center}.comments{margin-top:1em}.comments .avatar{max-width:45px;max-height:45px;-webkit-border-radius:100%;-moz-border-radius:100%;border-radius:100%;box-shadow:0 0 7px #666}.comments .cat_bar{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}section #display_head{margin-top:.1em;margin-bottom:0}section #display_head span{margin:0}.lp_frontpage_articles .card{transition:all .4s cubic-bezier(.175, .885, 0, 1);position:relative;border-radius:12px;overflow:hidden;padding:0;display:flex;flex-direction:column;justify-content:flex-end;height:96%}.lp_frontpage_articles .card:hover{box-shadow:0 0 10px 5px #ddd}.lp_frontpage_articles .card:hover .new_posts{display:none}.lp_frontpage_articles .card:hover .card__info-hover{opacity:1;z-index:1}.lp_frontpage_articles .card:hover .card__img--hover{height:100%;opacity:.3}.lp_frontpage_articles .card:hover .card__info{background-color:transparent;position:relative}.lp_frontpage_articles .card .card__info-hover{position:absolute;padding:16px;opacity:0;top:0;right:0}.lp_frontpage_articles .card .card__info-hover .card__edit-icon{position:relative;z-index:2}.lp_frontpage_articles .card .card__img{visibility:hidden;background-size:cover;background-position:center;background-repeat:no-repeat;width:100%;height:235px;border-top-left-radius:12px;border-top-right-radius:12px}.lp_frontpage_articles .card .card__img--hover{transition:.2s all ease-out;background-size:cover;background-position:center;background-repeat:no-repeat;width:100%;position:absolute;height:235px;border-top-left-radius:12px;border-top-right-radius:12px;top:0}.lp_frontpage_articles .card .card__info{z-index:2;border-bottom-left-radius:12px;border-bottom-right-radius:12px;padding:16px 24px 24px 24px;display:flex;flex-direction:column}.lp_frontpage_articles .card .card__info.alt_style{flex-direction:column-reverse}.lp_frontpage_articles .card .card__info .card__category{font-weight:500;color:#868686}.lp_frontpage_articles .card .card__info .card__title{text-transform:uppercase;margin-top:5px;margin-bottom:10px;word-break:break-word}.lp_frontpage_articles .card .card__info .card__title+div{display:flex;flex-wrap:wrap;flex-direction:row;justify-content:space-between}.lp_frontpage_articles .card .card__info .card__by{font-weight:500}.lp_frontpage_articles .card .card__info .card__author{font-weight:600;text-decoration:none;color:#ad7d52}.comment_list{list-style:none}.comment_list li{clear:both;width:100%}.comment_avatar{position:absolute;width:74px;vertical-align:top;padding-right:10px}.comment_wrapper{width:100%;padding-left:55px}.comment_wrapper .entry{display:block;position:relative;padding:0 12px 8px;border:1px solid #ddd;-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;box-shadow:0 2px 5px rgba(0,0,0,0.1)}.comment_wrapper .entry .title{display:block;font-size:.9em;margin:-1px -13px -11px;line-height:20px;text-align:justify}.comment_wrapper .entry .title::after{display:inline-block;content:'';width:100%;height:0;visibility:hidden;overflow:hidden}.comment_wrapper .entry .title>span{font-weight:bold;border:1px solid #ddd;-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;-webkit-border-bottom-right-radius:0;-moz-border-radius-topright:0;border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;display:inline-block;vertical-align:top;padding:6px 11px}.comment_wrapper .entry .title .comment_date{border:1px solid #ddd;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-border-bottom-right-radius:7px;-moz-border-radius-topright:7px;border-bottom-right-radius:7px;-webkit-border-bottom-left-radius:7px;-moz-border-radius-bottomleft:7px;border-bottom-left-radius:7px;display:inline-block;vertical-align:top;padding:6px 11px;opacity:.8}.comment_wrapper .entry .content{padding:0 14px}.comment_wrapper .entry .update_button,.comment_wrapper .entry .cancel_button{display:none}.comment_wrapper .entry .smalltext{margin-top:6px;padding-top:6px;border-top:1px dashed #bfbfbf}#comment_form textarea{width:100%;height:30px}#comment_form button[name="comment"]{margin-top:10px;float:right;display:none}.sceditor-container{position:relative;min-height:300px !important}.priority span,.actions span{cursor:pointer}#page_comments .row{margin-right:0 !important;margin-left:0 !important}#page_comments_toggle{cursor:pointer}.lp_default_blocks th.icon,.lp_additional_blocks th.icon{width:8%}.lp_default_blocks th.type,.lp_additional_blocks th.type,.lp_default_blocks th.areas,.lp_additional_blocks th.areas,.lp_default_blocks th.priority,.lp_additional_blocks th.priority,.lp_default_blocks th.actions,.lp_additional_blocks th.actions{width:14%}.features .floatleft{width:80%}.lp_plugin_toggle,.lp_plugin_settings{cursor:pointer}.lp_plugin_settings{position:relative;top:-3px;vertical-align:baseline !important}.form_settings>div{margin:10px}.form_settings input[type="text"],.form_settings input[type="url"]{width:100%}.footer .infobox,.footer .errorbox{display:none}#postpage #post_header dt,#postblock #post_header dt,#postpage #post_header dd,#postblock #post_header dd{float:none;width:auto}@media (max-width:480px){.lp_default_blocks th.icon,.lp_additional_blocks th.icon,.lp_default_blocks td.icon,.lp_additional_blocks td.icon{display:none}#pages th.date,#pages td.date{display:none}}@media (max-width:600px){.lp_default_blocks th.title,.lp_additional_blocks th.title,.lp_default_blocks td.title,.lp_additional_blocks td.title,.lp_default_blocks th.areas,.lp_additional_blocks th.areas,.lp_default_blocks td.areas,.lp_additional_blocks td.areas{display:none}#postpage .button,#postblock .button{float:none !important;width:100%;margin-left:0 !important}.comment_avatar{display:none}.comment_wrapper{padding:0}.comment_list .col-xs-12{flex-basis:95%;margin-left:10px}#lp_layout input[type="radio"]{width:auto}}@media (max-width:887px){.information .righttext{text-align:center}#pages th.alias,#pages td.alias{display:none}}@media (max-width:800px){#pages th.num_views,#pages td.num_views,#pages th.type,#pages td.type{display:none}}@media (min-width:1022px) and (max-width:1200px){.article_info div{text-align:center;display:block}.article_info .floatleft,.article_info .floatright{float:none}}.lp_tabs{padding:0px;margin:0 auto}.lp_tabs>input{display:none;position:absolute}.lp_tabs>input:checked+label{color:#555;border-top:1px solid #f49a3a;border-bottom:1px solid #fff}.lp_tabs input:invalid,.lp_tabs textarea:invalid{border:3px double red}.lp_tabs>label{display:inline-block;margin:0 0 -1px;padding:15px 25px;font-weight:600;text-align:center;color:#aaa;border:0 solid #ddd;border-width:1px 1px 1px 1px;border-radius:3px 3px 0 0}.lp_tabs>label:hover{color:#888;cursor:pointer}.lp_tabs>label:before{font-family:"Font Awesome 5 Free";margin-right:10px}.lp_tabs>label[for*="1"]:before{content:"\f15c"}.lp_tabs>label[for*="2"]:before{content:"\f084"}.lp_tabs>label[for*="3"]:before{content:"\f53f"}.lp_tabs>label[for*="4"]:before{content:"\f509"}.lp_tabs section{display:none;padding:15px;background:#fff;border:1px solid #ddd;-webkit-border-top-left-radius:0;-moz-border-radius-topleft:0;border-top-left-radius:0;-webkit-border-top-right-radius:7px;border-top-right-radius:7px;-webkit-border-bottom-right-radius:7px;-moz-border-radius-topright:7px;border-bottom-right-radius:7px;-webkit-border-bottom-left-radius:7px;-moz-border-radius-bottomleft:7px;border-bottom-left-radius:7px}.lp_tabs section dl{margin:0 0 5px;line-height:1.5;-webkit-animation-duration:1s;animation-duration:1s;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-name:fadeIn;animation-name:fadeIn}.lp_tabs section dl dt label{font-weight:bold}.lp_tabs section dl dd{margin-bottom:1em}@-webkit-keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}#tab1:checked~#content-tab1,#tab2:checked~#content-tab2,#tab3:checked~#content-tab3,#tab4:checked~#content-tab4{display:block}@media screen and (max-width:680px){.lp_tabs>label{font-size:0}.lp_tabs>label:before{margin:0;font-size:18px}}@media screen and (max-width:400px){.lp_tabs>label{padding:15px}}@media (min-width:769px) and (max-width:1241px){.block_user_info span.floatleft,.block_user_info span.floatright{float:none;margin:0 auto;display:block}}.likely__widget{opacity:.5 !important;filter:grayscale(100%)}.likely__widget:hover{opacity:1 !important;filter:grayscale(0%)}.recent_posts li,.recent_topics li,.random_topics li,.recent_comments li{margin:4px 0 0 0;padding:6px 12px}.recent_posts .poster_avatar,.recent_topics .poster_avatar{float:left;padding:3px 11px 0 0}.recent_posts .avatar,.recent_topics .avatar{width:40px;height:40px}dl.top_posters dt img{width:24px;vertical-align:middle}.themeswitcher select{cursor:pointer}.page_md .bbc_code,.block_md .bbc_code{overflow:auto !important;white-space:pre}.page_md .task-list-item,.block_md .task-list-item{list-style:none;margin-left:-20px}.page_md blockquote{width:100% !important}.recent_attachments{display:flex;flex-direction:row;justify-content:space-evenly;align-items:center}.recent_attachments .item{margin:5px}.column_direction{flex-direction:column !important}#vk_comments{margin-top:1em}.block_current_month table{width:100%;margin-bottom:10px;border-collapse:collapse;background:#f0f4f7;border:1px solid #ddd;text-align:center}.block_current_month table .windowbg{box-shadow:none;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;box-sizing:content-box;margin:0}.block_current_month th{padding:2px;background:#e7eaef;font-size:smaller}.block_current_month td{padding:2px;width:12.5%;vertical-align:top;border-right:1px solid #ddd;border-bottom:1px solid #ddd}.block_current_month td.disabled{background:#eee;border:1px solid #ddd}.block_current_month td.events{background:rgba(30,245,20,0.1)}.block_current_month td.holidays{background:rgba(23,110,245,0.1)}.block_current_month td.birthdays{background:rgba(102,0,255,0.1)}.block_current_month td.events:hover,.block_current_month td.calendar_today.events{background:rgba(30,245,20,0.2)}.block_current_month td.holidays:hover,.block_current_month td.calendar_today.holidays{background:rgba(23,110,245,0.2)}.block_current_month td.birthdays:hover,.block_current_month td.calendar_today.birthdays{background:rgba(153,51,255,0.2)}.block_current_month td.calendar_today{font-weight:bold}.block_current_month td a{display:block}.block_current_month td a:hover{text-decoration:none;background:rgba(97,135,166,0.2)}.block_board_list ul{padding-left:10px}.flipster{overflow:hidden !important}.flipster .flipster__button{height:auto !important}.flipster .flipster__button:focus,.flipster .flipster__button:hover,.flipster .flipster__button::selection{background:none;border:none;box-shadow:none}.slick-slider{min-width:0;margin:0 20px;position:relative}.slick-slider .slick-arrow{box-shadow:none;position:absolute;top:50%;z-index:10;font-size:0;width:30px;height:60px}.slick-slider .slick-prev::before,.slick-slider .slick-next::before{color:#000 !important}.slick-slider .slick-disabled{opacity:.2}.slider__item{padding:0px 15px}.slider__item img{max-width:100%}.article_list{display:grid;grid-template-columns:repeat(auto-fit, minmax(150px, 1fr));grid-gap:0 10px} \ No newline at end of file +.fa-portal::before{content:"\f0ac"}.actions .fas{vertical-align:middle}.block_bbc .videocontainer,.block_html .videocontainer,.block_md .videocontainer{margin:0 auto}.preview .button{float:none !important}.descbox{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.descbox .bbc_code{overflow:hidden !important}#lp_blocks .item{cursor:pointer;height:96%}#block_icon i{vertical-align:middle}#info_center{margin-bottom:5px}#admin_form_wrapper p.errorbox{margin:0}#lp_layout h3:hover,#lp_layout h4:hover{white-space:normal}#lp_layout .file_content{white-space:break-spaces}#lp_layout #post_confirm_buttons{padding:12px 0 0 0 !important}#lp_layout .row>aside{margin:0 !important}#lp_layout .sticky_sidebar{position:sticky;top:5px}#lp_layout aside>div>h3,#lp_layout aside>div>h4{white-space:nowrap;text-overflow:ellipsis}#lp_layout aside[id^="block"]:not(:first-child){clear:both;margin-top:4px}.related_pages{margin-top:1em}.related_pages .article_list{grid-template-columns:repeat(4, 1fr)}.related_pages .article_list div{text-align:center}.comments{margin-top:1em}.comments .avatar{max-width:45px;max-height:45px;-webkit-border-radius:100%;-moz-border-radius:100%;border-radius:100%;box-shadow:0 0 7px #666}.comments .cat_bar{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}section #display_head{margin-top:.1em;margin-bottom:0}section #display_head span{margin:0}.lp_frontpage_articles .card{transition:all .4s cubic-bezier(.175, .885, 0, 1);position:relative;border-radius:12px;overflow:hidden;padding:0;display:flex;flex-direction:column;justify-content:flex-end;height:96%}.lp_frontpage_articles .card:hover{box-shadow:0 0 10px 5px #ddd}.lp_frontpage_articles .card:hover .new_posts{display:none}.lp_frontpage_articles .card:hover .card__info-hover{opacity:1;z-index:1}.lp_frontpage_articles .card:hover .card__img--hover{height:100%;opacity:.3}.lp_frontpage_articles .card:hover .card__info{background-color:transparent;position:relative}.lp_frontpage_articles .card .card__info-hover{position:absolute;padding:16px;opacity:0;top:0;right:0}.lp_frontpage_articles .card .card__info-hover .card__edit-icon{position:relative;z-index:2}.lp_frontpage_articles .card .card__img{visibility:hidden;background-size:cover;background-position:center;background-repeat:no-repeat;width:100%;height:235px;border-top-left-radius:12px;border-top-right-radius:12px}.lp_frontpage_articles .card .card__img--hover{transition:.2s all ease-out;background-size:cover;background-position:center;background-repeat:no-repeat;width:100%;position:absolute;height:235px;border-top-left-radius:12px;border-top-right-radius:12px;top:0}.lp_frontpage_articles .card .card__info{z-index:2;border-bottom-left-radius:12px;border-bottom-right-radius:12px;padding:16px 24px 24px 24px;display:flex;flex-direction:column}.lp_frontpage_articles .card .card__info.alt_style{flex-direction:column-reverse}.lp_frontpage_articles .card .card__info .card__category{font-weight:500;color:#868686}.lp_frontpage_articles .card .card__info .card__title{text-transform:uppercase;margin-top:5px;margin-bottom:10px;word-break:break-word}.lp_frontpage_articles .card .card__info .card__title+div{display:flex;flex-wrap:wrap;flex-direction:row;justify-content:space-between}.lp_frontpage_articles .card .card__info .card__by{font-weight:500}.lp_frontpage_articles .card .card__info .card__author{font-weight:600;text-decoration:none;color:#ad7d52}.comment_list{list-style:none}.comment_list li{clear:both;width:100%}.comment_avatar{position:absolute;width:74px;vertical-align:top;padding-right:10px}.comment_wrapper{width:100%;padding-left:55px}.comment_wrapper .entry{display:block;position:relative;padding:0 12px 8px;border:1px solid #ddd;-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;box-shadow:0 2px 5px rgba(0,0,0,0.1)}.comment_wrapper .entry .title{display:block;font-size:.9em;margin:-1px -13px -11px;line-height:20px;text-align:justify}.comment_wrapper .entry .title::after{display:inline-block;content:'';width:100%;height:0;visibility:hidden;overflow:hidden}.comment_wrapper .entry .title>span{font-weight:bold;border:1px solid #ddd;-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;-webkit-border-bottom-right-radius:0;-moz-border-radius-topright:0;border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;display:inline-block;vertical-align:top;padding:6px 11px}.comment_wrapper .entry .title .comment_date{border:1px solid #ddd;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-border-bottom-right-radius:7px;-moz-border-radius-topright:7px;border-bottom-right-radius:7px;-webkit-border-bottom-left-radius:7px;-moz-border-radius-bottomleft:7px;border-bottom-left-radius:7px;display:inline-block;vertical-align:top;padding:6px 11px;opacity:.8}.comment_wrapper .entry .content{padding:0 14px}.comment_wrapper .entry .update_button,.comment_wrapper .entry .cancel_button{display:none}.comment_wrapper .entry .smalltext{margin-top:6px;padding-top:6px;border-top:1px dashed #bfbfbf}#comment_form textarea{width:100%;height:30px}#comment_form button[name="comment"]{margin-top:10px;float:right;display:none}.sceditor-container{position:relative;min-height:300px !important}.priority span,.actions span{cursor:pointer}#page_comments .row{margin-right:0 !important;margin-left:0 !important}#page_comments_toggle{cursor:pointer}.lp_default_blocks th.icon,.lp_additional_blocks th.icon{width:8%}.lp_default_blocks th.type,.lp_additional_blocks th.type,.lp_default_blocks th.areas,.lp_additional_blocks th.areas,.lp_default_blocks th.priority,.lp_additional_blocks th.priority,.lp_default_blocks th.actions,.lp_additional_blocks th.actions{width:14%}.features .floatleft{width:80%}.lp_plugin_toggle,.lp_plugin_settings{cursor:pointer}.lp_plugin_settings{position:relative;top:-3px;vertical-align:baseline !important}.form_settings>div{margin:10px}.form_settings input[type="text"],.form_settings input[type="url"]{width:100%}.footer .infobox,.footer .errorbox{display:none}#postpage #post_header dt,#postblock #post_header dt,#postpage #post_header dd,#postblock #post_header dd{float:none;width:auto}@media (max-width:480px){.lp_default_blocks th.icon,.lp_additional_blocks th.icon,.lp_default_blocks td.icon,.lp_additional_blocks td.icon{display:none}#pages th.date,#pages td.date{display:none}}@media (max-width:600px){.lp_default_blocks th.title,.lp_additional_blocks th.title,.lp_default_blocks td.title,.lp_additional_blocks td.title,.lp_default_blocks th.areas,.lp_additional_blocks th.areas,.lp_default_blocks td.areas,.lp_additional_blocks td.areas{display:none}#postpage .button,#postblock .button{float:none !important;width:100%;margin-left:0 !important}.comment_avatar{display:none}.comment_wrapper{padding:0}.comment_list .col-xs-12{flex-basis:95%;margin-left:10px}#lp_layout input[type="radio"]{width:auto}}@media (max-width:887px){.information .righttext{text-align:center}#pages th.alias,#pages td.alias{display:none}}@media (max-width:800px){#pages th.num_views,#pages td.num_views,#pages th.type,#pages td.type{display:none}}@media (min-width:1022px) and (max-width:1200px){.article_info div{text-align:center;display:block}.article_info .floatleft,.article_info .floatright{float:none}}.lp_tabs{padding:0px;margin:0 auto}.lp_tabs>input{display:none;position:absolute}.lp_tabs>input:checked+label{color:#555;border-top:1px solid #f49a3a;border-bottom:1px solid #fff}.lp_tabs input:invalid,.lp_tabs textarea:invalid{border:3px double red}.lp_tabs>label{display:inline-block;margin:0 0 -1px;padding:15px 25px;font-weight:600;text-align:center;color:#aaa;border:0 solid #ddd;border-width:1px 1px 1px 1px;border-radius:3px 3px 0 0}.lp_tabs>label:hover{color:#888;cursor:pointer}.lp_tabs>label:before{font-family:"Font Awesome 5 Free";margin-right:10px}.lp_tabs>label[for*="1"]:before{content:"\f15c"}.lp_tabs>label[for*="2"]:before{content:"\f084"}.lp_tabs>label[for*="3"]:before{content:"\f53f"}.lp_tabs>label[for*="4"]:before{content:"\f509"}.lp_tabs section{display:none;padding:15px;background:#fff;border:1px solid #ddd;-webkit-border-top-left-radius:0;-moz-border-radius-topleft:0;border-top-left-radius:0;-webkit-border-top-right-radius:7px;border-top-right-radius:7px;-webkit-border-bottom-right-radius:7px;-moz-border-radius-topright:7px;border-bottom-right-radius:7px;-webkit-border-bottom-left-radius:7px;-moz-border-radius-bottomleft:7px;border-bottom-left-radius:7px}.lp_tabs section dl{margin:0 0 5px;line-height:1.5;-webkit-animation-duration:1s;animation-duration:1s;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-name:fadeIn;animation-name:fadeIn}.lp_tabs section dl dt label{font-weight:bold}.lp_tabs section dl dd{margin-bottom:1em}@-webkit-keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}#tab1:checked~#content-tab1,#tab2:checked~#content-tab2,#tab3:checked~#content-tab3,#tab4:checked~#content-tab4{display:block}@media screen and (max-width:680px){.lp_tabs>label{font-size:0}.lp_tabs>label:before{margin:0;font-size:18px}}@media screen and (max-width:400px){.lp_tabs>label{padding:15px}}.block_user_info ul{list-style:none;padding-left:0}.block_user_info ul .avatar{margin:1em}@media (min-width:769px) and (max-width:1241px){.block_user_info span.floatleft,.block_user_info span.floatright{float:none;margin:0 auto;display:block}}.likely__widget{opacity:.5 !important;filter:grayscale(100%)}.likely__widget:hover{opacity:1 !important;filter:grayscale(0%)}.recent_posts li,.recent_topics li,.random_topics li,.recent_comments li{margin:4px 0 0 0;padding:6px 12px}.recent_posts .poster_avatar,.recent_topics .poster_avatar{float:left;padding:3px 11px 0 0}.recent_posts .avatar,.recent_topics .avatar{width:40px;height:40px}dl.top_posters dt img{width:24px;vertical-align:middle}.themeswitcher select{cursor:pointer}.page_md .bbc_code,.block_md .bbc_code{overflow:auto !important;white-space:pre}.page_md .task-list-item,.block_md .task-list-item{list-style:none;margin-left:-20px}.page_md blockquote{width:100% !important}.recent_attachments{display:flex;flex-direction:row;justify-content:space-evenly;align-items:center}.recent_attachments .item{margin:5px}.column_direction{flex-direction:column !important}#vk_comments{margin-top:1em}.block_current_month table{width:100%;margin-bottom:10px;border-collapse:collapse;background:#f0f4f7;border:1px solid #ddd;text-align:center}.block_current_month table .windowbg{box-shadow:none;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;box-sizing:content-box;margin:0}.block_current_month th{padding:2px;background:#e7eaef;font-size:smaller}.block_current_month td{padding:2px;width:12.5%;vertical-align:top;border-right:1px solid #ddd;border-bottom:1px solid #ddd}.block_current_month td.disabled{background:#eee;border:1px solid #ddd}.block_current_month td.events{background:rgba(30,245,20,0.1)}.block_current_month td.holidays{background:rgba(23,110,245,0.1)}.block_current_month td.birthdays{background:rgba(102,0,255,0.1)}.block_current_month td.events:hover,.block_current_month td.calendar_today.events{background:rgba(30,245,20,0.2)}.block_current_month td.holidays:hover,.block_current_month td.calendar_today.holidays{background:rgba(23,110,245,0.2)}.block_current_month td.birthdays:hover,.block_current_month td.calendar_today.birthdays{background:rgba(153,51,255,0.2)}.block_current_month td.calendar_today{font-weight:bold}.block_current_month td a{display:block}.block_current_month td a:hover{text-decoration:none;background:rgba(97,135,166,0.2)}.block_board_list ul{padding-left:10px}.flipster{overflow:hidden !important}.flipster .flipster__button{height:auto !important}.flipster .flipster__button:focus,.flipster .flipster__button:hover,.flipster .flipster__button::selection{background:none;border:none;box-shadow:none}.slick-slider{min-width:0;margin:0 20px;position:relative}.slick-slider .slick-arrow{box-shadow:none;position:absolute;top:50%;z-index:10;font-size:0;width:30px;height:60px}.slick-slider .slick-prev::before,.slick-slider .slick-next::before{color:#000 !important}.slick-slider .slick-disabled{opacity:.2}.slider__item{padding:0px 15px}.slider__item img{max-width:100%}.article_list{display:grid;grid-template-columns:repeat(auto-fit, minmax(150px, 1fr));grid-gap:0 10px} \ No newline at end of file diff --git a/Themes/default/css/light_portal/light_portal.less b/Themes/default/css/light_portal/light_portal.less index 2595d0bc3..a807074bf 100644 --- a/Themes/default/css/light_portal/light_portal.less +++ b/Themes/default/css/light_portal/light_portal.less @@ -749,6 +749,17 @@ section { /* Addons */ /* UserInfo */ +.block_user_info { + ul { + list-style: none; + padding-left: 0; + + .avatar { + margin: 1em; + } + } +} + @media (min-width: 769px) and (max-width: 1241px) { .block_user_info { span { From 8c0c648e10c54431601b6a9c3ffdf53eeed98dc6 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 13 Oct 2020 14:34:14 +0500 Subject: [PATCH 05/46] Fix some comment issues --- Sources/LightPortal/Comment.php | 36 +++++++++---------- .../default/LightPortal/ViewPage.template.php | 1 - .../scripts/light_portal/manage_comments.js | 9 +++-- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Sources/LightPortal/Comment.php b/Sources/LightPortal/Comment.php index 653b484c3..f46c9f4e5 100644 --- a/Sources/LightPortal/Comment.php +++ b/Sources/LightPortal/Comment.php @@ -50,16 +50,18 @@ public function prepare() if (empty($this->alias)) return; - if (Helpers::request()->filled('sa') && Helpers::request('sa') == 'new_comment') - $this->add(); - - if (Helpers::request()->filled('sa') && Helpers::request('sa') == 'edit_comment') - $this->edit(); - - if (Helpers::request()->filled('sa') && Helpers::request('sa') == 'del_comment') - $this->remove(); + if (Helpers::request()->filled('sa')) { + switch (Helpers::request('sa')) { + case 'new_comment': + $this->add(); + case 'edit_comment': + $this->edit(); + case 'del_comment': + $this->remove(); + } + } - $comments = Helpers::getFromCache('page_' . $this->alias . '_comments', 'getAll', __CLASS__, LP_CACHE_TIME, $context['lp_page']['id']); + $comments = Helpers::cache('page_' . $this->alias . '_comments', 'getAll', __CLASS__, LP_CACHE_TIME, $context['lp_page']['id']); $comments = array_map( function ($comment) { $comment['created'] = Helpers::getFriendlyTime($comment['created_at']); @@ -111,7 +113,6 @@ private function add() 'level' => FILTER_VALIDATE_INT, 'page_id' => FILTER_VALIDATE_INT, 'page_title' => FILTER_SANITIZE_STRING, - 'page_alias' => FILTER_SANITIZE_STRING, 'page_url' => FILTER_SANITIZE_STRING, 'message' => FILTER_SANITIZE_STRING, 'start' => FILTER_VALIDATE_INT, @@ -128,7 +129,6 @@ private function add() $level = $data['level']; $page_id = $data['page_id']; $page_title = $data['page_title']; - $page_alias = $data['page_alias']; $page_url = $data['page_url']; $message = $data['message']; $start = $data['start']; @@ -143,7 +143,7 @@ private function add() 'parent_id' => 'int', 'page_id' => 'int', 'author_id' => 'int', - 'message' => 'string-' . Helpers::getMaxMessageLength(), + 'message' => 'string-' . MAX_MSG_LENGTH, 'created_at' => 'int' ), array( @@ -181,7 +181,7 @@ private function add() show_single_comment([ 'id' => $item, - 'alias' => $page_alias, + 'alias' => $this->alias, 'author_id' => $user_info['id'], 'author_name' => $user_info['name'], 'avatar' => $this->getUserAvatar(), @@ -200,7 +200,7 @@ private function add() 'comment' => $comment, 'created' => $time, 'title' => $txt['response_prefix'] . $page_title, - 'alias' => $page_alias, + 'alias' => $this->alias, 'page_url' => $page_url, 'start' => $start, 'commentator' => $commentator @@ -210,7 +210,7 @@ private function add() ? $this->makeNotify('new_comment', 'page_comment', $result) : $this->makeNotify('new_reply', 'page_comment_reply', $result); - Helpers::getFromCache('page_' . $page_alias . '_comments', null); + Helpers::cache()->forget('page_' . $this->alias . '_comments'); } exit(json_encode($result)); @@ -234,7 +234,7 @@ private function edit() return; $item = $data['comment_id']; - $message = filter_var($data['message'], FILTER_SANITIZE_STRING); + $message = Helpers::validate($data['message']); if (empty($item) || empty($message)) return; @@ -256,7 +256,7 @@ private function edit() $enabled_tags = !empty($modSettings['lp_enabled_bbc_in_comments']) ? explode(',', $modSettings['lp_enabled_bbc_in_comments']) : []; $message = empty($enabled_tags) ? $message : parse_bbc($message, true, 'light_portal_comments_' . $item, $enabled_tags); - Helpers::getFromCache('page_' . $this->alias . '_comments', null); + Helpers::cache()->forget('page_' . $this->alias . '_comments'); exit(json_encode($message)); } @@ -382,7 +382,7 @@ private function remove() $context['lp_num_queries'] += 2; - Helpers::getFromCache('page_' . $this->alias . '_comments', null); + Helpers::cache()->forget('page_' . $this->alias . '_comments'); exit; } diff --git a/Themes/default/LightPortal/ViewPage.template.php b/Themes/default/LightPortal/ViewPage.template.php index 09610b550..7775b7c6b 100644 --- a/Themes/default/LightPortal/ViewPage.template.php +++ b/Themes/default/LightPortal/ViewPage.template.php @@ -175,7 +175,6 @@ function show_comment_block() - diff --git a/Themes/default/scripts/light_portal/manage_comments.js b/Themes/default/scripts/light_portal/manage_comments.js index 84aefac6a..aa0e1b0d4 100644 --- a/Themes/default/scripts/light_portal/manage_comments.js +++ b/Themes/default/scripts/light_portal/manage_comments.js @@ -237,9 +237,14 @@ document.addEventListener('DOMContentLoaded', function () { commentForm.reset(); commentForm.comment.style.display = 'none'; commentForm.parent_id.value = 0; - commentForm.start.value = PAGE_START; - window.location.hash = '#comment' + data.item; + if (parseInt(window.location.pathname.match(/\d+/)) == commentForm.start.value) { + window.location.hash = '#comment' + data.item; + } else { + window.location = window.location.origin + window.location.pathname.replace(/(start[=.])\d+/i, '$1' + PAGE_START) + '#comment' + data.item; + } + + commentForm.start.value = PAGE_START; } else { console.error(response); } From c70201d4a6731b0a80eaf6d81d1e40f7b2237d40 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 13 Oct 2020 14:35:46 +0500 Subject: [PATCH 06/46] Fix an issue when "forum" blocks appeared on pages --- Sources/LightPortal/Block.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/LightPortal/Block.php b/Sources/LightPortal/Block.php index 82d9a46fe..2accb69b7 100644 --- a/Sources/LightPortal/Block.php +++ b/Sources/LightPortal/Block.php @@ -91,14 +91,14 @@ private static function getFilteredByAreas() $area = $context['current_action'] ?: (!empty($modSettings['lp_frontpage_mode']) ? 'portal' : 'forum'); if (!empty($modSettings['lp_standalone_mode']) && !empty($modSettings['lp_standalone_url'])) { - if (!empty($_SERVER['REQUEST_URL']) && $modSettings['lp_standalone_url'] == $_SERVER['REQUEST_URL']) { + if (Helpers::server()->filled('REQUEST_URL') && $modSettings['lp_standalone_url'] == Helpers::server('REQUEST_URL')) { $area = 'portal'; } elseif (empty($context['current_action'])) { $area = 'forum'; } } - if (!empty($context['current_board'])) + if (!empty($context['current_board']) || !empty($context['lp_page'])) $area = ''; return array_filter($context['lp_active_blocks'], function($block) use ($context, $area) { @@ -108,7 +108,7 @@ private static function getFilteredByAreas() if (isset($block['areas']['all']) || isset($block['areas'][$area])) return true; - if (empty($context['current_action']) && !empty($_GET['page']) && (isset($block['areas']['page=' . (string) $_GET['page']]) || isset($block['areas']['pages']))) + if (empty($context['current_action']) && Helpers::request()->filled('page') && (isset($block['areas']['page=' . Helpers::request('page')]) || isset($block['areas']['pages']))) return true; if (empty($context['current_board'])) From d1a55ab1111db3f9e605f4c1c00cfc92ffd41a76 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 13 Oct 2020 14:36:14 +0500 Subject: [PATCH 07/46] Continue refactoring --- Sources/LightPortal/Integration.php | 7 +-- Sources/LightPortal/ManageBlocks.php | 41 ++++++++--------- Sources/LightPortal/ManagePages.php | 38 ++++++++-------- Sources/LightPortal/Settings.php | 66 ++++++++++++++-------------- Sources/LightPortal/Tag.php | 8 ++-- 5 files changed, 83 insertions(+), 77 deletions(-) diff --git a/Sources/LightPortal/Integration.php b/Sources/LightPortal/Integration.php index ef56edd98..16e52b0f3 100644 --- a/Sources/LightPortal/Integration.php +++ b/Sources/LightPortal/Integration.php @@ -82,7 +82,8 @@ public static function userInfo() 'LP_DEBUG' => !empty($modSettings['lp_show_debug_info']) && $user_info['is_admin'], 'LP_ADDONS' => $sourcedir . '/LightPortal/addons', 'LP_CACHE_TIME' => $modSettings['lp_cache_update_interval'] ?? 3600, - 'RC2_CLEAN' => !defined('JQUERY_VERSION') + 'RC2_CLEAN' => !defined('JQUERY_VERSION'), + 'MAX_MSG_LENGTH' => !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] > 65534 ? (int) $modSettings['max_messageLength'] : 65534 ]; foreach ($lp_constants as $key => $value) @@ -161,7 +162,7 @@ public static function defaultAction() { global $modSettings, $sourcedir; - if (!empty($_GET['page'])) + if (Helpers::request()->filled('page')) return Page::show(); if (empty($modSettings['lp_frontpage_mode']) || (!empty($modSettings['lp_standalone_mode']) && !empty($modSettings['lp_standalone_url']))) { @@ -191,7 +192,7 @@ public static function currentAction(string &$current_action) if (Helpers::request()->isEmpty('action')) { $current_action = 'portal'; - if (!empty($modSettings['lp_standalone_mode']) && !empty($modSettings['lp_standalone_url']) && $modSettings['lp_standalone_url'] != $_SERVER['REQUEST_URL']) + if (!empty($modSettings['lp_standalone_mode']) && !empty($modSettings['lp_standalone_url']) && $modSettings['lp_standalone_url'] != Helpers::server('REQUEST_URL')) $current_action = 'forum'; if (Helpers::request()->filled('page')) diff --git a/Sources/LightPortal/ManageBlocks.php b/Sources/LightPortal/ManageBlocks.php index 5c470a852..34b55c935 100644 --- a/Sources/LightPortal/ManageBlocks.php +++ b/Sources/LightPortal/ManageBlocks.php @@ -131,7 +131,8 @@ public static function doActions() self::updatePriority(); - clean_cache(); + Helpers::cache()->flush(); + exit; } @@ -196,7 +197,7 @@ private static function makeCopy(int $item) if (empty($item)) return; - $_POST['clone'] = true; + Helpers::post()->put('clone', true); $result['success'] = false; $context['lp_block'] = self::getData($item); @@ -216,7 +217,7 @@ private static function makeCopy(int $item) ]; } - Helpers::getFromCache('active_blocks', null); + Helpers::cache()->forget('active_blocks'); exit(json_encode($result)); } @@ -331,10 +332,10 @@ public static function add() $context['sub_template'] = 'block_add'; - if (!isset($_POST['add_block'])) + if (Helpers::post()->has('add_block') === false) return; - $type = (string) $_POST['add_block']; + $type = Helpers::post('add_block', ''); $context['current_block']['type'] = $type; Subs::getForumLanguages(); @@ -425,7 +426,7 @@ private static function validateData() { global $context, $user_info; - if (isset($_POST['save']) || isset($_POST['preview'])) { + if (Helpers::post()->has('save') || Helpers::post()->has('preview')) { $args = array( 'block_id' => FILTER_VALIDATE_INT, 'icon' => FILTER_SANITIZE_STRING, @@ -520,11 +521,11 @@ private static function findErrors(array $data) $areas_format = array( 'options' => array("regexp" => '/' . static::$areas_pattern . '/') ); - if (!empty($data['areas']) && empty(filter_var($data['areas'], FILTER_VALIDATE_REGEXP, $areas_format))) + if (!empty($data['areas']) && empty(Helpers::validate($data['areas'], $areas_format))) $post_errors[] = 'no_valid_areas'; if (!empty($post_errors)) { - $_POST['preview'] = true; + Helpers::post()->put('preview', true); $context['post_errors'] = []; foreach ($post_errors as $error) @@ -738,7 +739,7 @@ private static function prepareFormFields() 'type' => 'textarea', 'attributes' => array( 'id' => 'content', - 'maxlength' => Helpers::getMaxMessageLength(), + 'maxlength' => MAX_MSG_LENGTH, 'value' => $context['lp_block']['content'] ), 'tab' => 'content' @@ -847,7 +848,7 @@ private static function preparePreview() { global $context, $smcFunc, $txt; - if (!isset($_POST['preview'])) + if (Helpers::post()->has('preview') === false) return; checkSubmitOnce('free'); @@ -909,13 +910,13 @@ private static function setData(int $item = 0) { global $context, $smcFunc; - if (!empty($context['post_errors']) || (!isset($_POST['save']) && !isset($_POST['clone']))) + if (!empty($context['post_errors']) || (Helpers::post()->has('save') === false && Helpers::post()->has('clone') === false)) return; checkSubmitOnce('check'); if (empty($item)) { - $max_length = Helpers::getMaxMessageLength(); + $max_length = MAX_MSG_LENGTH; $priority = self::getPriority(); $item = $smcFunc['db_insert']('', @@ -1086,15 +1087,15 @@ private static function setData(int $item = 0) $context['lp_num_queries']++; } - Helpers::getFromCache($context['lp_block']['type'] . '_addon_b' . $item, null); - Helpers::getFromCache($context['lp_block']['type'] . '_addon_u' . $context['user']['id'], null); - Helpers::getFromCache($context['lp_block']['type'] . '_addon_b' . $item . '_u' . $context['user']['id'], null); + Helpers::cache()->forget($context['lp_block']['type'] . '_addon_b' . $item); + Helpers::cache()->forget($context['lp_block']['type'] . '_addon_u' . $context['user']['id']); + Helpers::cache()->forget($context['lp_block']['type'] . '_addon_b' . $item . '_u' . $context['user']['id']); } - if (!empty($_POST['clone'])) + if (Helpers::post()->filled('clone')) return $item; - Helpers::getFromCache('active_blocks', null); + Helpers::cache()->forget('active_blocks'); redirectexit('action=admin;area=lp_blocks;sa=main'); } @@ -1204,7 +1205,7 @@ private static function getDataForXml() { global $smcFunc, $context; - if (empty($_POST['items'])) + if (Helpers::post()->isEmpty('items')) return []; $request = $smcFunc['db_query']('', ' @@ -1217,7 +1218,7 @@ private static function getDataForXml() WHERE b.block_id IN ({array_int:blocks})', array( 'type' => 'block', - 'blocks' => $_POST['items'] + 'blocks' => Helpers::post('items') ) ); @@ -1434,6 +1435,6 @@ private static function runImport() if (empty($result)) fatal_lang_error('lp_import_failed', false); - clean_cache(); + Helpers::cache()->flush(); } } diff --git a/Sources/LightPortal/ManagePages.php b/Sources/LightPortal/ManagePages.php index 614a644b0..95af4c0ee 100644 --- a/Sources/LightPortal/ManagePages.php +++ b/Sources/LightPortal/ManagePages.php @@ -294,7 +294,7 @@ public static function getAll(int $start, int $items_per_page, string $sort, str { global $smcFunc, $user_info, $context; - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $request = $smcFunc['db_query']('', ' SELECT p.page_id, p.author_id, p.alias, p.type, p.permissions, p.status, p.num_views, GREATEST(p.created_at, p.updated_at) AS date, mem.real_name AS author_name @@ -397,7 +397,8 @@ private static function doActions() self::toggleStatus([$item], $status == 'off' ? Page::STATUS_ACTIVE : Page::STATUS_INACTIVE); } - clean_cache(); + Helpers::cache()->flush(); + exit; } @@ -460,7 +461,7 @@ private static function remove(array $items) ) ); - Subs::runAddons('onRemovePages', array(&$items)); + Subs::runAddons('onPageRemoving', array(&$items)); $context['lp_num_queries'] += 5; } @@ -501,12 +502,12 @@ public static function toggleStatus(array $items, int $status = 0) */ public static function massActions() { - if (!isset($_POST['mass_actions']) || empty($_POST['items'])) + if (Helpers::post()->has('mass_actions') === false || Helpers::post()->isEmpty('items')) return; $redirect = filter_input(INPUT_SERVER, 'HTTP_REFERER', FILTER_DEFAULT, array('options' => array('default' => 'action=admin;area=lp_pages'))); - $items = $_POST['items']; + $items = Helpers::post('items'); switch (filter_input(INPUT_POST, 'page_actions')) { case 'delete': self::remove($items); @@ -635,7 +636,7 @@ private static function validateData() { global $context, $modSettings, $user_info; - if (isset($_POST['save']) || isset($_POST['preview'])) { + if (Helpers::post()->has('save') || Helpers::post()->has('preview')) { $args = array( 'alias' => FILTER_SANITIZE_STRING, 'description' => FILTER_SANITIZE_STRING, @@ -664,7 +665,7 @@ private static function validateData() ); $post_data = filter_input_array(INPUT_POST, array_merge($args, $parameters)); - $post_data['id'] = !empty($_GET['id']) ? (int) $_GET['id'] : 0; + $post_data['id'] = Helpers::request('id', 0); self::findErrors($post_data); } @@ -728,7 +729,7 @@ private static function findErrors(array $data) $alias_format = array( 'options' => array("regexp" => '/' . static::$alias_pattern . '/') ); - if (!empty($data['alias']) && empty(filter_var($data['alias'], FILTER_VALIDATE_REGEXP, $alias_format))) + if (!empty($data['alias']) && empty(Helpers::validate($data['alias'], $alias_format))) $post_errors[] = 'no_valid_alias'; if (!empty($data['alias']) && self::isUnique($data)) @@ -738,7 +739,7 @@ private static function findErrors(array $data) $post_errors[] = 'no_content'; if (!empty($post_errors)) { - $_POST['preview'] = true; + Helpers::post()->put('preview', true); $context['post_errors'] = []; foreach ($post_errors as $error) @@ -885,7 +886,7 @@ private static function prepareFormFields() 'type' => 'textarea', 'attributes' => array( 'id' => 'content', - 'maxlength' => Helpers::getMaxMessageLength(), + 'maxlength' => MAX_MSG_LENGTH, 'value' => $context['lp_page']['content'], 'required' => true ), @@ -962,7 +963,7 @@ private static function preparePreview() { global $context, $smcFunc, $txt; - if (!isset($_POST['preview'])) + if (Helpers::post()->has('preview') === false) return; checkSubmitOnce('free'); @@ -1035,7 +1036,7 @@ private static function setData(int $item = 0) { global $context, $smcFunc, $db_type; - if (!empty($context['post_errors']) || !isset($_POST['save'])) + if (!empty($context['post_errors']) || Helpers::post()->has('save') === false) return; checkSubmitOnce('check'); @@ -1049,7 +1050,7 @@ private static function setData(int $item = 0) 'author_id' => 'int', 'alias' => 'string-255', 'description' => 'string-255', - 'content' => 'string-' . Helpers::getMaxMessageLength(), + 'content' => 'string-' . MAX_MSG_LENGTH, 'type' => 'string-4', 'permissions' => 'int', 'status' => 'int', @@ -1071,7 +1072,7 @@ private static function setData(int $item = 0) $context['lp_num_queries']++; - Subs::runAddons('onDataSaving', array($item)); + Subs::runAddons('onPageSaving', array($item)); if (!empty($context['lp_page']['title'])) { $titles = []; @@ -1257,7 +1258,8 @@ private static function setData(int $item = 0) } } - clean_cache(); + Helpers::cache()->flush(); + redirectexit('action=admin;area=lp_pages;sa=main'); } @@ -1436,10 +1438,10 @@ private static function getDataForXml() { global $smcFunc, $context; - if (empty($_POST['pages']) && !isset($_POST['export_all'])) + if (Helpers::post()->isEmpty('pages') && Helpers::post()->has('export_all') === false) return false; - $pages = !empty($_POST['pages']) && !isset($_POST['export_all']) ? $_POST['pages'] : null; + $pages = !empty(Helpers::post('pages')) && Helpers::post()->has('export_all') === false ? Helpers::post('pages') : null; $request = $smcFunc['db_query']('', ' SELECT @@ -1772,6 +1774,6 @@ private static function runImport() // Restore the cache $db_cache = $db_temp_cache; - clean_cache(); + Helpers::cache()->flush(); } } diff --git a/Sources/LightPortal/Settings.php b/Sources/LightPortal/Settings.php index eab6ac116..46b678eb0 100644 --- a/Sources/LightPortal/Settings.php +++ b/Sources/LightPortal/Settings.php @@ -303,22 +303,23 @@ function toggleStandaloneMode() { });', true); // Save - if (isset($_GET['save'])) { + if (Helpers::request()->has('save')) { checkSession(); - if (empty($_POST['lp_frontpage_mode'])) - $_POST['lp_standalone_url'] = 0; + if (Helpers::post()->isEmpty('lp_frontpage_mode')) + Helpers::post()->put('lp_standalone_url', 0); - if (!empty($_POST['lp_image_placeholder'])) - $_POST['lp_image_placeholder'] = filter_var($_POST['lp_image_placeholder'], FILTER_VALIDATE_URL); + if (Helpers::post()->filled('lp_image_placeholder')) + Helpers::post()->put('lp_image_placeholder', Helpers::validate(Helpers::post('lp_image_placeholder'), 'url')); - if (!empty($_POST['lp_standalone_url'])) - $_POST['lp_standalone_url'] = filter_var($_POST['lp_standalone_url'], FILTER_VALIDATE_URL); + if (Helpers::post()->filled('lp_standalone_url')) + Helpers::post()->put('lp_standalone_url', Helpers::validate(Helpers::post('lp_standalone_url'), 'url')); $save_vars = $config_vars; saveDBSettings($save_vars); - clean_cache(); + Helpers::cache()->flush(); + redirectexit('action=admin;area=lp_settings;sa=basic'); } @@ -384,7 +385,7 @@ function toggleShowCommentBlock() { });', true); // Save - if (isset($_GET['save'])) { + if (Helpers::request()->has('save')) { checkSession(); // Clean up the tags @@ -392,19 +393,20 @@ function toggleShowCommentBlock() { foreach (parse_bbc(false) as $tag) $bbcTags[] = $tag['tag']; - if (!isset($_POST['lp_disabled_bbc_in_comments_enabledTags'])) - $_POST['lp_disabled_bbc_in_comments_enabledTags'] = []; - elseif (!is_array($_POST['lp_disabled_bbc_in_comments_enabledTags'])) - $_POST['lp_disabled_bbc_in_comments_enabledTags'] = array($_POST['lp_disabled_bbc_in_comments_enabledTags']); + if (Helpers::post()->has('lp_disabled_bbc_in_comments_enabledTags') === false) + Helpers::post()->put('lp_disabled_bbc_in_comments_enabledTags', []); + elseif (!is_array(Helpers::post('lp_disabled_bbc_in_comments_enabledTags'))) + Helpers::post()->put('lp_disabled_bbc_in_comments_enabledTags', array(Helpers::post('lp_disabled_bbc_in_comments_enabledTags'))); - $_POST['lp_enabled_bbc_in_comments'] = implode(',', $_POST['lp_disabled_bbc_in_comments_enabledTags']); - $_POST['lp_disabled_bbc_in_comments'] = implode(',', array_diff($bbcTags, $_POST['lp_disabled_bbc_in_comments_enabledTags'])); + Helpers::post()->put('lp_enabled_bbc_in_comments', implode(',', Helpers::post('lp_disabled_bbc_in_comments_enabledTags'))); + Helpers::post()->put('lp_disabled_bbc_in_comments', implode(',', array_diff($bbcTags, Helpers::post('lp_disabled_bbc_in_comments_enabledTags')))); $save_vars = $config_vars; $save_vars[] = ['text', 'lp_enabled_bbc_in_comments']; saveDBSettings($save_vars); - clean_cache(); + Helpers::cache()->flush(); + redirectexit('action=admin;area=lp_settings;sa=extra'); } @@ -470,12 +472,12 @@ public static function panels(bool $return_config = false) $context['sub_template'] = 'show_settings'; - if (isset($_GET['save'])) { + if (Helpers::request()->has('save')) { checkSession(); - $_POST['lp_left_panel_width'] = json_encode($_POST['lp_left_panel_width']); - $_POST['lp_right_panel_width'] = json_encode($_POST['lp_right_panel_width']); - $_POST['lp_panel_direction'] = json_encode($_POST['lp_panel_direction']); + Helpers::post()->put('lp_left_panel_width', json_encode(Helpers::post('lp_left_panel_width'))); + Helpers::post()->put('lp_right_panel_width', json_encode(Helpers::post('lp_right_panel_width'))); + Helpers::post()->put('lp_panel_direction', json_encode(Helpers::post('lp_panel_direction'))); $save_vars = $config_vars; $save_vars[] = ['int', 'lp_header_panel_width']; @@ -530,28 +532,28 @@ public static function plugins() $context['sub_template'] = 'plugin_settings'; - if (isset($_GET['save'])) { + if (Helpers::request()->has('save')) { checkSession(); $plugin_options = []; foreach ($config_vars as $id => $var) { - if (isset($_POST[$var[1]])) { + if (Helpers::post()->has($var[1])) { if ($var[0] == 'check') { - $plugin_options[$var[1]] = (int) filter_var($_POST[$var[1]], FILTER_VALIDATE_BOOLEAN); + $plugin_options[$var[1]] = (int) Helpers::validate(Helpers::post($var[1]), 'bool'); } elseif ($var[0] == 'int') { - $plugin_options[$var[1]] = filter_var($_POST[$var[1]], FILTER_VALIDATE_INT); + $plugin_options[$var[1]] = Helpers::validate(Helpers::post($var[1]), 'int'); } elseif ($var[0] == 'multicheck') { $plugin_options[$var[1]] = []; - foreach ($_POST[$var[1]] as $key => $value) { - $plugin_options[$var[1]][(int) $key] = (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); + foreach (Helpers::post($var[1]) as $key => $value) { + $plugin_options[$var[1]][$key] = (int) Helpers::validate($value, 'bool'); } $plugin_options[$var[1]] = json_encode($plugin_options[$var[1]]); } elseif ($var[0] == 'url') { - $plugin_options[$var[1]] = filter_var($_POST[$var[1]], FILTER_SANITIZE_URL); + $plugin_options[$var[1]] = Helpers::validate(Helpers::post($var[1]), 'url'); } else { - $plugin_options[$var[1]] = $_POST[$var[1]]; + $plugin_options[$var[1]] = Helpers::post($var[1]); } } } @@ -678,9 +680,9 @@ public static function pageArea() isAllowedTo('light_portal_manage_own_pages'); $subActions = array( - 'main' => 'ManagePages::main', - 'add' => 'ManagePages::add', - 'edit' => 'ManagePages::edit' + 'main' => 'ManagePages::main', + 'add' => 'ManagePages::add', + 'edit' => 'ManagePages::edit' ); if ($user_info['is_admin']) { @@ -729,7 +731,7 @@ private static function checkNewVersion() global $context, $txt; // Check once a week | Проверяем раз в неделю - if (LP_VERSION < $new_version = Helpers::getFromCache('last_version', 'getLastVersion', __CLASS__, 604800)) { + if (LP_VERSION < $new_version = Helpers::cache('last_version', 'getLastVersion', __CLASS__, 604800)) { $context['settings_insert_above'] = '
    ' . $txt['lp_new_version_is_available'] . ' (' . $new_version . ') diff --git a/Sources/LightPortal/Tag.php b/Sources/LightPortal/Tag.php index 0b3cc1a59..c8c3b87d2 100644 --- a/Sources/LightPortal/Tag.php +++ b/Sources/LightPortal/Tag.php @@ -30,10 +30,10 @@ public static function show() { global $context, $smcFunc, $txt, $scripturl, $modSettings, $sourcedir; - if (empty($_GET['key'])) + if (Helpers::request()->isEmpty('key')) self::showAll(); - $context['lp_keyword'] = $smcFunc['htmlspecialchars'](trim($_GET['key']), ENT_QUOTES); + $context['lp_keyword'] = $smcFunc['htmlspecialchars'](trim(Helpers::request('key')), ENT_QUOTES); $context['page_title'] = sprintf($txt['lp_all_tags_by_key'], $context['lp_keyword']); $context['canonical_url'] = $scripturl . '?action=portal;sa=tags;key=' . urlencode($context['lp_keyword']); $context['robot_no_index'] = true; @@ -147,7 +147,7 @@ public static function getAllPagesWithSelectedTag(int $start, int $items_per_pag { global $smcFunc, $txt, $context, $modSettings, $scripturl, $user_info; - $titles = Helpers::getFromCache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); + $titles = Helpers::cache('all_titles', 'getAllTitles', '\Bugo\LightPortal\Subs', LP_CACHE_TIME, 'page'); $request = $smcFunc['db_query']('', ' SELECT @@ -443,7 +443,7 @@ private static function showAsArticles() 'num_views' => 'p.num_views' ); - $context['current_sorting'] = $_POST['sort'] ?? 'created;desc'; + $context['current_sorting'] = Helpers::post('sort', 'created;desc'); $sort = $sorting_types[$context['current_sorting']]; $articles = self::getAllPagesWithSelectedTag($start, $limit, $sort); From 7a9f1edfeaf326b4f0fcd2de2fd23be9a357e0f1 Mon Sep 17 00:00:00 2001 From: Bugo Date: Wed, 14 Oct 2020 19:20:01 +0500 Subject: [PATCH 08/46] Fix comment posting when SimpleSEF is enabled --- .../scripts/light_portal/manage_comments.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Themes/default/scripts/light_portal/manage_comments.js b/Themes/default/scripts/light_portal/manage_comments.js index aa0e1b0d4..9898e282a 100644 --- a/Themes/default/scripts/light_portal/manage_comments.js +++ b/Themes/default/scripts/light_portal/manage_comments.js @@ -238,10 +238,18 @@ document.addEventListener('DOMContentLoaded', function () { commentForm.comment.style.display = 'none'; commentForm.parent_id.value = 0; - if (parseInt(window.location.pathname.match(/\d+/)) == commentForm.start.value) { - window.location.hash = '#comment' + data.item; + if (! window.location.search) { + if (parseInt(window.location.pathname.match(/\d+/) ?? 0) == commentForm.start.value) { + window.location.hash = '#comment' + data.item; + } else { + window.location = window.origin + window.location.pathname.replace(/(start[=.])\d+/i, '$1' + PAGE_START) + '#comment' + data.item; + } } else { - window.location = window.location.origin + window.location.pathname.replace(/(start[=.])\d+/i, '$1' + PAGE_START) + '#comment' + data.item; + if (parseInt(window.location.search.match(/\d+/)) == commentForm.start.value) { + window.location.hash = '#comment' + data.item; + } else { + window.location = window.location.href.replace(/(start[=.])\d+/i, '$1' + PAGE_START) + '#comment' + data.item; + } } commentForm.start.value = PAGE_START; From a710fe334ae3a4d781f90c00d8c9ce3246835ad4 Mon Sep 17 00:00:00 2001 From: Bugo Date: Fri, 16 Oct 2020 13:52:30 +0500 Subject: [PATCH 09/46] Remove some placements from AdsBlock addon --- .../LightPortal/addons/AdsBlock/AdsBlock.php | 54 ++----------------- .../addons/AdsBlock/langs/english.php | 5 +- .../addons/AdsBlock/langs/polish.php | 5 +- .../addons/AdsBlock/langs/russian.php | 5 +- .../addons/AdsBlock/langs/spanish_es.php | 5 +- .../addons/AdsBlock/langs/spanish_latin.php | 5 +- .../addons/AdsBlock/langs/ukrainian.php | 3 -- 7 files changed, 8 insertions(+), 74 deletions(-) diff --git a/Sources/LightPortal/addons/AdsBlock/AdsBlock.php b/Sources/LightPortal/addons/AdsBlock/AdsBlock.php index 6b901fcab..6084432fa 100644 --- a/Sources/LightPortal/addons/AdsBlock/AdsBlock.php +++ b/Sources/LightPortal/addons/AdsBlock/AdsBlock.php @@ -189,7 +189,9 @@ public static function prepareDisplayContext(&$output, &$message, $counter) * * Вывод рекламы перед каждым последним сообщением */ - $before_every_last_post = empty($options['view_newest_first']) ? $counter == $context['total_visible_posts'] || $counter % $context['messages_per_page'] == 0 : ($output['id'] == $context['topic_first_message'] || ($context['total_visible_posts'] - $counter) % $context['messages_per_page'] == 0); + $before_every_last_post = empty($options['view_newest_first']) + ? $counter == $context['total_visible_posts'] || $counter % $context['messages_per_page'] == 0 + : ($output['id'] == $context['topic_first_message'] || ($context['total_visible_posts'] - $counter) % $context['messages_per_page'] == 0); if (!empty($context['lp_ads_blocks']['before_every_last_post']) && $before_every_last_post) { lp_show_blocks('before_every_last_post'); } @@ -221,56 +223,6 @@ public static function prepareDisplayContext(&$output, &$message, $counter) if (!empty($context['lp_ads_blocks']['after_every_first_post']) && ($output['counter'] == (empty($options['view_newest_first']) ? $context['start'] + 1 : $current_counter - 1))) { lp_show_blocks('after_every_first_post'); } - - /** - * Displaying ads after every fifth message on the page - * - * Вывод рекламы после каждого пятого сообщения - */ - if (!empty($context['lp_ads_blocks']['after_every_five_post']) && abs($current_counter - $counter) == 5) { - ob_start(); - - lp_show_blocks('after_every_five_post'); - - $after_every_five_post = ob_get_clean(); - - addInlineJavaScript(' - const all_windowbg = document.getElementById("quickModForm").querySelectorAll("div.windowbg"); - all_windowbg[all_windowbg.length - 1].insertAdjacentHTML("afterend", ' . JavaScriptEscape($after_every_five_post) . ');', true); - } - - /** - * Displaying ads after each last message on the page - * - * Вывод рекламы после каждого последнего сообщения - */ - if (!empty($context['lp_ads_blocks']['after_every_last_post']) && ($counter == $context['total_visible_posts'] || $counter % $context['messages_per_page'] == 0)) { - ob_start(); - - lp_show_blocks('after_every_last_post'); - - $after_every_last_post = ob_get_clean(); - - addInlineJavaScript(' - const all_windowbg2 = document.getElementById("quickModForm").querySelectorAll("div.windowbg"); - all_windowbg2[all_windowbg2.length - 1].insertAdjacentHTML("afterend", ' . JavaScriptEscape($after_every_last_post) . ');', true); - } - - /** - * Displaying ads after the last message - * - * Вывод рекламы после последнего сообщения - */ - if (!empty($context['lp_ads_blocks']['after_last_post']) && $output['id'] == (empty($options['view_newest_first']) ? $context['topic_last_message'] : $context['topic_first_message'])) { - ob_start(); - - lp_show_blocks('after_last_post'); - - $after_last_post = ob_get_clean(); - - addInlineJavaScript(' - document.getElementById("quickModForm").insertAdjacentHTML("beforeend", ' . JavaScriptEscape($after_last_post) . ');', true); - } } /** diff --git a/Sources/LightPortal/addons/AdsBlock/langs/english.php b/Sources/LightPortal/addons/AdsBlock/langs/english.php index ee9b9ab74..334563565 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/english.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/english.php @@ -19,8 +19,5 @@ 'before_every_last_post' => 'Before each last message on the page', 'before_last_post' => 'Before the last message', 'after_first_post' => 'After the first message', - 'after_every_first_post' => 'After each first message on the page', - 'after_every_five_post' => 'After every fifth message on the page', - 'after_every_last_post' => 'After each last message on the page', - 'after_last_post' => 'After the last message' + 'after_every_first_post' => 'After each first message on the page' ); \ No newline at end of file diff --git a/Sources/LightPortal/addons/AdsBlock/langs/polish.php b/Sources/LightPortal/addons/AdsBlock/langs/polish.php index f67d434b1..b188b6d31 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/polish.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/polish.php @@ -19,8 +19,5 @@ 'before_every_last_post' => 'Przed ostatnią wiadomością na każdej stronie wątku', 'before_last_post' => 'Przed ostatnią wiadomością', 'after_first_post' => 'Po pierwszej wiadomości', - 'after_every_first_post' => 'Po pierwszej wiadomości na każdej stronie wątku', - 'after_every_five_post' => 'Po piątej wiadomości na każdej stronie wątku', - 'after_every_last_post' => 'Po ostatniej wiadomości na każdej stronie wątku', - 'after_last_post' => 'Po ostatniej wiadomości' + 'after_every_first_post' => 'Po pierwszej wiadomości na każdej stronie wątku' ); diff --git a/Sources/LightPortal/addons/AdsBlock/langs/russian.php b/Sources/LightPortal/addons/AdsBlock/langs/russian.php index c046d75c2..61e1668f0 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/russian.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/russian.php @@ -19,8 +19,5 @@ 'before_every_last_post' => 'Перед каждым последним сообщением на странице', 'before_last_post' => 'Перед последним сообщением', 'after_first_post' => 'После первого сообщения', - 'after_every_first_post' => 'После каждого первого сообщения на странице', - 'after_every_five_post' => 'После каждого пятого сообщения на странице', - 'after_every_last_post' => 'После каждого последнего сообщения на странице', - 'after_last_post' => 'После последнего сообщения' + 'after_every_first_post' => 'После каждого первого сообщения на странице' ); \ No newline at end of file diff --git a/Sources/LightPortal/addons/AdsBlock/langs/spanish_es.php b/Sources/LightPortal/addons/AdsBlock/langs/spanish_es.php index b2644c8e4..8173ce6d6 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/spanish_es.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/spanish_es.php @@ -21,8 +21,5 @@ 'before_every_last_post' => 'Antes de cada último mensaje en la página', 'before_last_post' => 'Antes del último mensaje', 'after_first_post' => 'Después del primer mensaje', - 'after_every_first_post' => 'Después de cada primer mensaje en la página', - 'after_every_five_post' => 'Después de cada quinto mensaje en la página', - 'after_every_last_post' => 'Después de cada último mensaje en la página.', - 'after_last_post' => 'Después del último mensaje' + 'after_every_first_post' => 'Después de cada primer mensaje en la página' ); diff --git a/Sources/LightPortal/addons/AdsBlock/langs/spanish_latin.php b/Sources/LightPortal/addons/AdsBlock/langs/spanish_latin.php index 8889271ed..07b261cee 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/spanish_latin.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/spanish_latin.php @@ -21,8 +21,5 @@ 'before_every_last_post' => 'Antes de cada último mensaje en la página', 'before_last_post' => 'Antes del último mensaje', 'after_first_post' => 'Después del primer mensaje', - 'after_every_first_post' => 'Después de cada primer mensaje en la página', - 'after_every_five_post' => 'Después de cada quinto mensaje en la página', - 'after_every_last_post' => 'Después de cada último mensaje en la página.', - 'after_last_post' => 'Después del último mensaje' + 'after_every_first_post' => 'Después de cada primer mensaje en la página' ); diff --git a/Sources/LightPortal/addons/AdsBlock/langs/ukrainian.php b/Sources/LightPortal/addons/AdsBlock/langs/ukrainian.php index 2c0466526..0959d2df8 100644 --- a/Sources/LightPortal/addons/AdsBlock/langs/ukrainian.php +++ b/Sources/LightPortal/addons/AdsBlock/langs/ukrainian.php @@ -20,7 +20,4 @@ 'before_last_post' => 'Перед останнім повідомленням', 'after_first_post' => 'Після першого повідомлення', 'after_every_first_post' => 'Після кожного першого повідомлення на сторінці', - 'after_every_five_post' => 'Після кожного п\'ятого повідомлення на сторінці', - 'after_every_last_post' => 'Після кожного останнього повідомлення на сторінці', - 'after_last_post' => 'Після останнього повідомлення' ); \ No newline at end of file From 222c358ce60535753fd7050bf3dd7947dc8a524a Mon Sep 17 00:00:00 2001 From: Bugo Date: Fri, 16 Oct 2020 13:54:00 +0500 Subject: [PATCH 10/46] Add possibility to sticky/unsticky sidebars --- Sources/LightPortal/Settings.php | 6 ++++++ Themes/default/LightPortal/ManageSettings.template.php | 6 ++++++ Themes/default/LightPortal/ViewBlock.template.php | 6 +++--- Themes/default/css/light_portal/light_portal.css | 2 +- Themes/default/css/light_portal/light_portal.less | 1 + Themes/default/languages/LightPortal/.english.php | 1 + Themes/default/languages/LightPortal/.polish.php | 1 + Themes/default/languages/LightPortal/.russian.php | 1 + Themes/default/languages/LightPortal/.spanish_es.php | 1 + Themes/default/languages/LightPortal/.spanish_latin.php | 1 + Themes/default/languages/LightPortal/.ukrainian.php | 1 + 11 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Sources/LightPortal/Settings.php b/Sources/LightPortal/Settings.php index 46b678eb0..ec05a9d0c 100644 --- a/Sources/LightPortal/Settings.php +++ b/Sources/LightPortal/Settings.php @@ -449,6 +449,10 @@ public static function panels(bool $return_config = false) $add_settings['lp_right_panel_width'] = json_encode($context['lp_right_panel_width']); if (!isset($modSettings['lp_footer_panel_width'])) $add_settings['lp_footer_panel_width'] = 12; + if (!isset($modSettings['lp_left_panel_sticky'])) + $add_settings['lp_left_panel_sticky'] = 1; + if (!isset($modSettings['lp_right_panel_sticky'])) + $add_settings['lp_right_panel_sticky'] = 1; if (!empty($add_settings)) updateSettings($add_settings); @@ -484,6 +488,8 @@ public static function panels(bool $return_config = false) $save_vars[] = ['text', 'lp_left_panel_width']; $save_vars[] = ['text', 'lp_right_panel_width']; $save_vars[] = ['int', 'lp_footer_panel_width']; + $save_vars[] = ['check', 'lp_left_panel_sticky']; + $save_vars[] = ['check', 'lp_right_panel_sticky']; $save_vars[] = ['text', 'lp_panel_direction']; saveDBSettings($save_vars); diff --git a/Themes/default/LightPortal/ManageSettings.template.php b/Themes/default/LightPortal/ManageSettings.template.php index a394e002f..ac976abde 100644 --- a/Themes/default/LightPortal/ManageSettings.template.php +++ b/Themes/default/LightPortal/ManageSettings.template.php @@ -121,6 +121,9 @@ function template_callback_panel_layout()
+
+ +
@@ -208,6 +211,9 @@ function template_callback_panel_layout() +
+ +
diff --git a/Themes/default/LightPortal/ViewBlock.template.php b/Themes/default/LightPortal/ViewBlock.template.php index 429145d98..7cf249dc9 100644 --- a/Themes/default/LightPortal/ViewBlock.template.php +++ b/Themes/default/LightPortal/ViewBlock.template.php @@ -34,7 +34,7 @@ function template_portal_above() if (!empty($context['lp_blocks']['left'])) { echo '
-