diff --git a/README.md b/README.md index bf79ac700..07747c6f7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Light Portal -![SMF 2.1](https://img.shields.io/badge/SMF-2.1-blue.svg?style=flat&color=ed6033) +![SMF 2.1](https://img.shields.io/badge/SMF-2.1-ed6033.svg?style=flat) ![License](https://img.shields.io/github/license/dragomano/light-portal) -![PHP](https://img.shields.io/badge/php-^7.2-red.svg?style=flat&color=blue) +![PHP](https://img.shields.io/badge/PHP-^7.2-blue.svg?style=flat) ![Downloads](https://img.shields.io/github/downloads/dragomano/light-portal/total) * **Author:** Bugo [dragomano.ru](https://dragomano.ru/mods/light-portal) * **License:** [BSD 3](https://github.com/dragomano/Light-Portal/blob/master/LICENSE) * **Compatible with:** SMF 2.1 RC2+ / PHP 7.2+ -* **Tested on:** PHP 7.3.13 / MariaDB 10.3.13 / PostgreSQL 9.6.12 +* **Tested on:** PHP 7.3.14 / MariaDB 10.3.13 / PostgreSQL 9.6.12 * **Hooks only:** Yes * **Languages:** English, Russian, Ukrainian @@ -15,26 +15,26 @@ Transform your forum into a portal: the main page, separate additional pages, and blocks, as well as the article system. Support for BBC, HTML and PHP content. Nothing extra. ### Features: -* Standalone mode -* Blocks with multilingual titles and FontAwesome icons -* Article system: portal pages or topics from selected boards -* Available panels: header, left and right sidebars, center (top and bottom), footer -* Manage blocks in Admin: Drag-n-drop of blocks, easy updating of the priority -* Pages with support for various content -* Using Flexbox to output blocks -* Caching -* Support for addons +* Standalone mode. +* Blocks with multilingual titles and FontAwesome icons. +* Article system: portal pages, forum topics, or boards. +* Available panels: header, left and right sidebars, center (top and bottom), footer. +* Manage blocks in Admin: Drag-n-drop of blocks, easy updating of the priority. +* Pages with support for various content. +* Using Flexbox to output blocks. +* Caching. +* Support for addons. ## Описание Модификация добавляет форуму функциональность портала: главная страница, отдельные дополнительные страницы и блоки, статьи. Поддержка контента с ББ-кодом, HTML и PHP-тегами. Ничего лишнего. ### Особенности: -* Автономный режим -* Блоки с многоязычными заголовками и иконками FontAwesome -* Статьи на главной: отображение тем из выбранных разделов или страниц портала -* Доступные панели: шапка, левый и правый сайдбары, центр (верх и низ), подвал -* Drag-n-drop перетаскивание блоков между панелями, с обновлением приоритета -* Страницы с поддержкой различного контента -* Использование Flexbox для вывода блоков -* Кэширование -* Поддержка плагинов \ No newline at end of file +* Автономный режим. +* Блоки с многоязычными заголовками и иконками FontAwesome. +* Статьи на главной: отображение тем, разделов или страниц портала. +* Доступные панели: шапка, левый и правый сайдбары, центр (верх и низ), подвал. +* Drag-n-drop перетаскивание блоков между панелями, с обновлением приоритета. +* Страницы с поддержкой различного контента. +* Использование Flexbox для вывода блоков. +* Кэширование. +* Поддержка плагинов. \ No newline at end of file diff --git a/Sources/LightPortal/Block.php b/Sources/LightPortal/Block.php index 9542d78ba..bbbe130c9 100644 --- a/Sources/LightPortal/Block.php +++ b/Sources/LightPortal/Block.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8.1 + * @version 0.9 */ if (!defined('SMF')) @@ -53,7 +53,7 @@ public static function display($area = 'portal') Subs::parseContent($data['content'], $data['type']); $context['lp_blocks'][$data['placement']][$item] = $data; - $icon = self::getIcon($context['lp_blocks'][$data['placement']][$item]['icon']); + $icon = Helpers::getIcon($context['lp_blocks'][$data['placement']][$item]['icon']); $context['lp_blocks'][$data['placement']][$item]['title'] = $icon . $context['lp_blocks'][$data['placement']][$item]['title'][$context['user']['language']]; } } @@ -124,7 +124,7 @@ public static function getAll() while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($context['lp_current_blocks'][$row['placement']][$row['block_id']])) $context['lp_current_blocks'][$row['placement']][$row['block_id']] = array( - 'icon' => self::getIcon($row['icon']), + 'icon' => Helpers::getIcon($row['icon']), 'type' => $row['type'], 'priority' => $row['priority'], 'permissions' => $row['permissions'], @@ -174,50 +174,36 @@ private static function postActions() */ private static function remove() { - global $db_type, $smcFunc; + global $smcFunc; $item = filter_input(INPUT_POST, 'del_block', FILTER_VALIDATE_INT); if (empty($item)) return; - if ($db_type == 'postgresql') { - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}lp_blocks - WHERE block_id = {int:id}', - array( - 'id' => $item - ) - ); - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}lp_block_titles - WHERE block_id = {int:id}', - array( - 'id' => $item - ) - ); - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}lp_params - WHERE item_id = {int:id} - AND type = {string:type}', - array( - 'id' => $item, - 'type' => 'block' - ) - ); - } else { - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}lp_blocks, {db_prefix}lp_block_titles, {db_prefix}lp_params - USING {db_prefix}lp_blocks - LEFT JOIN {db_prefix}lp_block_titles ON ({db_prefix}lp_block_titles.block_id = {db_prefix}lp_blocks.block_id) - LEFT JOIN {db_prefix}lp_params ON ({db_prefix}lp_params.item_id = {db_prefix}lp_blocks.block_id AND {db_prefix}lp_params.type = {string:type}) - WHERE {db_prefix}lp_blocks.block_id = {int:id}', - array( - 'type' => 'block', - 'id' => $item - ) - ); - } + $smcFunc['db_query']('', ' + DELETE FROM {db_prefix}lp_blocks + WHERE block_id = {int:id}', + array( + 'id' => $item + ) + ); + $smcFunc['db_query']('', ' + DELETE FROM {db_prefix}lp_block_titles + WHERE block_id = {int:id}', + array( + 'id' => $item + ) + ); + $smcFunc['db_query']('', ' + DELETE FROM {db_prefix}lp_params + WHERE item_id = {int:id} + AND type = {string:type}', + array( + 'id' => $item, + 'type' => 'block' + ) + ); } /** @@ -547,7 +533,7 @@ private static function prepareFormFields() $context['posting_fields']['icon']['label']['after'] = $txt['lp_block_icon_cheatsheet']; $context['posting_fields']['icon']['input'] = array( 'type' => 'text', - 'after' => '' . self::getIcon() . '', + 'after' => '' . Helpers::getIcon() . '', 'attributes' => array( 'id' => 'icon', 'maxlength' => 30, @@ -566,10 +552,17 @@ private static function prepareFormFields() ); foreach ($txt['lp_block_placement_set'] as $level => $title) { - $context['posting_fields']['placement']['input']['options'][$title] = array( - 'value' => $level, - 'selected' => $level == $context['lp_block']['placement'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['placement']['input']['options'][$title]['attributes'] = array( + 'value' => $level, + 'selected' => $level == $context['lp_block']['placement'] + ); + } else { + $context['posting_fields']['placement']['input']['options'][$title] = array( + 'value' => $level, + 'selected' => $level == $context['lp_block']['placement'] + ); + } } $context['posting_fields']['permissions']['label']['text'] = $txt['edit_permissions']; @@ -582,10 +575,17 @@ private static function prepareFormFields() ); foreach ($txt['lp_permissions'] as $level => $title) { - $context['posting_fields']['permissions']['input']['options'][$title] = array( - 'value' => $level, - 'selected' => $level == $context['lp_block']['permissions'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['permissions']['input']['options'][$title]['attributes'] = array( + 'value' => $level, + 'selected' => $level == $context['lp_block']['permissions'] + ); + } else { + $context['posting_fields']['permissions']['input']['options'][$title] = array( + 'value' => $level, + 'selected' => $level == $context['lp_block']['permissions'] + ); + } } $context['posting_fields']['areas']['label']['text'] = $txt['lp_block_areas']; @@ -610,10 +610,17 @@ private static function prepareFormFields() ); foreach ($context['lp_all_title_classes'] as $key => $data) { - $context['posting_fields']['title_class']['input']['options'][$key] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['title_class'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['title_class']['input']['options'][$key]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['title_class'] + ); + } else { + $context['posting_fields']['title_class']['input']['options'][$key] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['title_class'] + ); + } } $context['posting_fields']['title_style']['label']['text'] = $txt['lp_block_title_style']; @@ -637,10 +644,17 @@ private static function prepareFormFields() ); foreach ($context['lp_all_content_classes'] as $key => $data) { - $context['posting_fields']['content_class']['input']['options'][$key] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['content_class'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['content_class']['input']['options'][$key]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['content_class'] + ); + } else { + $context['posting_fields']['content_class']['input']['options'][$key] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['content_class'] + ); + } } $context['posting_fields']['content_style']['label']['text'] = $txt['lp_block_content_style']; @@ -659,6 +673,7 @@ private static function prepareFormFields() $context['posting_fields']['content']['input'] = array( 'type' => 'textarea', 'attributes' => array( + 'id' => 'content', 'maxlength' => Helpers::getMaxMessageLength(), 'value' => $context['lp_block']['content'] ) @@ -721,7 +736,7 @@ private static function showPreview() Subs::parseContent($context['preview_content'], $context['lp_block']['type']); $context['page_title'] = $txt['preview'] . ($context['preview_title'] ? ' - ' . $context['preview_title'] : ''); - $context['preview_title'] = Helpers::getPreviewTitle(self::getIcon()); + $context['preview_title'] = Helpers::getPreviewTitle(Helpers::getIcon()); } /** @@ -984,24 +999,4 @@ public static function getData($item) return $data; } - - /** - * Get the block icon - * - * Получаем иконку блока - * - * @param string $icon - * @return string - */ - public static function getIcon($icon = null) - { - global $context; - - $icon = $icon ?? ($context['lp_block']['icon'] ?? ''); - - if (!empty($icon)) - return ' '; - else - return ''; - } } diff --git a/Sources/LightPortal/Helpers.php b/Sources/LightPortal/Helpers.php index 922a226f2..3ad59061f 100644 --- a/Sources/LightPortal/Helpers.php +++ b/Sources/LightPortal/Helpers.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -188,7 +188,6 @@ public static function getFriendlyTime(int $a) $last = round(($sec) / 60); // Future time? - // Будущее время? if ($a > $time) { $days = ($a - $time) / 60 / 60 / 24; @@ -215,7 +214,7 @@ public static function getFriendlyTime(int $a) return $txt['yesterday'] . $tm; elseif ($y == date('Y', $time)) return $d . ' ' . $txt['months'][date('n', $a)] . ', ' . $tm; - elseif ($tm == '00:00') + elseif ($tm == '00:00' || $y < date('Y', $time)) return $d . ' ' . $txt['months'][date('n', $a)] . ' ' . $y; else return timeformat($a); @@ -267,4 +266,24 @@ public static function findMissingBlockTypes($type) if (empty($txt['lp_block_types'][$type])) $context['lp_missing_block_types'][$type] = sprintf($txt['lp_addon_not_installed'], str_replace('_', '', ucwords($type, '_'))); } + + /** + * Get the block icon + * + * Получаем иконку блока + * + * @param string $icon + * @return string + */ + public static function getIcon($icon = null) + { + global $context; + + $icon = $icon ?? ($context['lp_block']['icon'] ?? ''); + + if (!empty($icon)) + return ' '; + else + return ''; + } } diff --git a/Sources/LightPortal/Integration.php b/Sources/LightPortal/Integration.php index c1ee245b3..d09934666 100644 --- a/Sources/LightPortal/Integration.php +++ b/Sources/LightPortal/Integration.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -70,7 +70,7 @@ public static function userInfo() global $sourcedir; $lp_constants = [ - 'LP_VERSION' => '0.8', + 'LP_VERSION' => '0.9', 'LP_NAME' => 'Light Portal', 'LP_ADDONS' => $sourcedir . '/LightPortal/addons' ]; @@ -116,7 +116,6 @@ public static function actions(&$actions) return; // Fix for Pretty URLs - // Если установлен Pretty URLs, добавляем обработку области "portal" if (!empty($context['pretty']['action_array'])) { if (!in_array('portal', array_values($context['pretty']['action_array']))) $context['pretty']['action_array'][] = 'portal'; @@ -194,11 +193,12 @@ public static function menuButtons(&$buttons) if (!defined('LP_NAME')) return; - $context['allow_light_portal_manage'] = allowedTo('light_portal_manage'); + $context['allow_light_portal_manage_blocks'] = allowedTo('light_portal_manage_blocks'); + $context['allow_light_portal_manage_own_pages'] = allowedTo('light_portal_manage_own_pages'); // Display "Portal settings" in Main Menu => Admin // Отображение пункта "Настройки портала" - if ($context['allow_light_portal_manage']) { + if ($context['allow_light_portal_manage_blocks'] || $context['allow_light_portal_manage_own_pages']) { $buttons['admin']['show'] = true; $counter = 0; foreach ($buttons['admin']['sub_buttons'] as $area => $dummy) { @@ -218,11 +218,13 @@ public static function menuButtons(&$buttons) 'blocks' => array( 'title' => $txt['lp_blocks'], 'href' => $scripturl . '?action=admin;area=lp_blocks', + 'amt' => count($context['lp_active_blocks']), 'show' => true ), 'pages' => array( 'title' => $txt['lp_pages'], 'href' => $scripturl . '?action=admin;area=lp_pages', + 'amt' => $context['lp_active_pages_num'], 'show' => true, 'is_last' => true ) @@ -232,12 +234,14 @@ public static function menuButtons(&$buttons) 'portal_blocks' => array( 'title' => $txt['lp_blocks'], 'href' => $scripturl . '?action=admin;area=lp_blocks', - 'show' => true + 'amt' => count($context['lp_active_blocks']), + 'show' => $context['allow_light_portal_manage_blocks'] ), 'portal_pages' => array( 'title' => $txt['lp_pages'], 'href' => $scripturl . '?action=admin;area=lp_pages', - 'show' => true + 'amt' => $context['lp_active_pages_num'], + 'show' => $context['allow_light_portal_manage_own_pages'] ) ), array_slice($buttons['admin']['sub_buttons'], $counter, null, true) @@ -322,7 +326,8 @@ public static function loadIllegalGuestPermissions() $context['non_guest_permissions'] = array_merge( $context['non_guest_permissions'], array( - 'light_portal_manage' + 'light_portal_manage_blocks', + 'light_portal_manage_own_pages' ) ); } @@ -339,8 +344,9 @@ public static function loadIllegalGuestPermissions() */ public static function loadPermissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups) { - $permissionList['membergroup']['light_portal_view'] = array(false, 'light_portal'); - $permissionList['membergroup']['light_portal_manage'] = array(false, 'light_portal'); + $permissionList['membergroup']['light_portal_view'] = array(false, 'light_portal'); + $permissionList['membergroup']['light_portal_manage_blocks'] = array(false, 'light_portal'); + $permissionList['membergroup']['light_portal_manage_own_pages'] = array(false, 'light_portal'); $leftPermissionGroups[] = 'light_portal'; } diff --git a/Sources/LightPortal/Page.php b/Sources/LightPortal/Page.php index 5290e3859..fe03e72da 100644 --- a/Sources/LightPortal/Page.php +++ b/Sources/LightPortal/Page.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -59,7 +59,7 @@ public static function show($alias = '/') if ($alias === '/') { $context['page_title'] = $modSettings['lp_frontpage_title_' . $context['user']['language']] ?? $txt['lp_portal']; } else { - $context['page_title'] = $context['lp_page']['title']; + $context['page_title'] = $context['lp_page']['title']; $context['canonical_url'] = $scripturl . '?page=' . $alias; } @@ -69,16 +69,17 @@ public static function show($alias = '/') if (!empty($modSettings['lp_frontpage_mode']) && empty($_GET['page'])) { $limit = !empty($modSettings['lp_num_per_page']) ? (int) $modSettings['lp_num_per_page'] : 10; - $context['lp_frontpage_layout'] = 12 / (!empty($modSettings['lp_frontpage_layout']) ? (int) $modSettings['lp_frontpage_layout'] : 2); - if ($limit == 1) - $context['lp_frontpage_layout'] = 12; + self::calculateNumColumns(); if ($modSettings['lp_frontpage_mode'] == 1) { Subs::prepareArticles('topics'); $context['sub_template'] = 'show_topics_as_articles'; - } else { + } elseif ($modSettings['lp_frontpage_mode'] == 2) { Subs::prepareArticles(); $context['sub_template'] = 'show_pages_as_articles'; + } else { + Subs::prepareArticles('boards'); + $context['sub_template'] = 'show_boards_as_articles'; } } else { $context['sub_template'] = 'show_page'; @@ -93,6 +94,38 @@ public static function show($alias = '/') } } + /** + * Calculate the number columns for the frontpage layout + * + * Подсчитываем количество колонок для макета главной страницы + * + * @return void + */ + private static function calculateNumColumns() + { + global $modSettings, $context; + + $num_columns = 12; + + if (!empty($modSettings['lp_frontpage_layout'])) { + switch ($modSettings['lp_frontpage_layout']) { + case '1': + $num_columns = 12 / 2; + break; + case '2': + $num_columns = 12 / 3; + break; + case '3': + $num_columns = 12 / 4; + break; + default: + $num_columns = 12 / 6; + } + } + + $context['lp_frontpage_layout'] = $num_columns; + } + /** * Manage pages * @@ -333,8 +366,10 @@ public static function getTotalQuantity() */ private static function postActions() { - if (!empty($_POST['del_page'])) - self::remove((int) $_POST['del_page']); + if (!isset($_REQUEST['actions'])) + return; + + self::remove(); if (!empty($_POST['toggle_status']) && !empty($_POST['item'])) { $item = (int) $_POST['item']; @@ -352,13 +387,14 @@ private static function postActions() * * Удаление страницы * - * @param int $item * @return void */ - private static function remove($item) + private static function remove() { global $smcFunc; + $item = filter_input(INPUT_POST, 'del_page', FILTER_VALIDATE_INT); + if (empty($item)) return; @@ -369,6 +405,15 @@ private static function remove($item) 'id' => $item ) ); + $smcFunc['db_query']('', ' + DELETE FROM {db_prefix}lp_params + WHERE item_id = {int:id} + AND type = {string:type}', + array( + 'id' => $item, + 'type' => 'page' + ) + ); } /** @@ -669,10 +714,17 @@ private static function prepareFormFields() ); foreach ($txt['lp_page_types'] as $type => $title) { - $context['posting_fields']['type']['input']['options'][$title] = array( - 'value' => $type, - 'selected' => $type == $context['lp_page']['type'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['type']['input']['options'][$title]['attributes'] = array( + 'value' => $type, + 'selected' => $type == $context['lp_page']['type'] + ); + } else { + $context['posting_fields']['type']['input']['options'][$title] = array( + 'value' => $type, + 'selected' => $type == $context['lp_page']['type'] + ); + } } $context['posting_fields']['description']['label']['text'] = $txt['lp_page_description']; @@ -703,10 +755,17 @@ private static function prepareFormFields() ); foreach ($txt['lp_permissions'] as $level => $title) { - $context['posting_fields']['permissions']['input']['options'][$title] = array( - 'value' => $level, - 'selected' => $level == $context['lp_page']['permissions'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['permissions']['input']['options'][$title]['attributes'] = array( + 'value' => $level, + 'selected' => $level == $context['lp_page']['permissions'] + ); + } else { + $context['posting_fields']['permissions']['input']['options'][$title] = array( + 'value' => $level, + 'selected' => $level == $context['lp_page']['permissions'] + ); + } } if ($context['lp_page']['type'] !== 'bbc') { @@ -714,6 +773,7 @@ private static function prepareFormFields() $context['posting_fields']['content']['input'] = array( 'type' => 'textarea', 'attributes' => array( + 'id' => 'content', 'maxlength' => Helpers::getMaxMessageLength(), 'value' => $context['lp_page']['content'], 'required' => true @@ -1028,7 +1088,7 @@ public static function getData($item, $useAlias = true) $data['created'] = Helpers::getFriendlyTime($data['created_at']); $data['updated'] = Helpers::getFriendlyTime($data['updated_at']); $data['can_show'] = Subs::canShowItem($data['permissions']); - $data['can_edit'] = $user_info['is_admin'] || (allowedTo('light_portal_manage') && $data['author_id'] == $user_info['id']); + $data['can_edit'] = $user_info['is_admin'] || (allowedTo('light_portal_manage_own_pages') && $data['author_id'] == $user_info['id']); } return $data; diff --git a/Sources/LightPortal/Settings.php b/Sources/LightPortal/Settings.php index 23f4fc75d..c33114f29 100644 --- a/Sources/LightPortal/Settings.php +++ b/Sources/LightPortal/Settings.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -29,7 +29,7 @@ class Settings */ public static function adminAreas(&$admin_areas) { - global $sourcedir, $txt; + global $sourcedir, $txt, $context; require_once($sourcedir . '/ManageSettings.php'); loadLanguage('ManageSettings'); @@ -45,7 +45,7 @@ public static function adminAreas(&$admin_areas) array( 'lp_portal' => array( 'title' => $txt['lp_portal'], - 'permission' => array('admin_forum', 'light_portal_manage'), + 'permission' => array('admin_forum', 'light_portal_manage_blocks', 'light_portal_manage_own_pages'), 'areas' => array( 'lp_settings' => array( 'label' => $txt['settings'], @@ -62,7 +62,8 @@ public static function adminAreas(&$admin_areas) self::blockArea(); }, 'icon' => 'modifications', - 'permission' => array('admin_forum', 'light_portal_manage'), + 'amt' => count($context['lp_active_blocks']), + 'permission' => array('admin_forum', 'light_portal_manage_blocks'), 'subsections' => array( 'main' => array($txt['lp_blocks_manage']), 'add' => array($txt['lp_blocks_add']) @@ -74,7 +75,8 @@ public static function adminAreas(&$admin_areas) self::pageArea(); }, 'icon' => 'posts', - 'permission' => array('admin_forum', 'light_portal_manage'), + 'amt' => $context['lp_active_pages_num'], + 'permission' => array('admin_forum', 'light_portal_manage_own_pages'), 'subsections' => array( 'main' => array($txt['lp_pages_manage']), 'add' => array($txt['lp_pages_add']) @@ -123,6 +125,11 @@ public static function settingArea($return_config = false) 'description' => sprintf($txt['lp_php_mysql_info'], LP_VERSION, phpversion(), $db_engine, $db_version) ); + if (Helpers::useCache('new_version_is_available', 'isNewVersionExist', __CLASS__)) { + $message = '

' . sprintf($txt['lp_new_version_is_available'], 'https://github.com/dragomano/Light-Portal/releases') . '

'; + $context[$context['admin_menu_name']]['tab_data']['description'] .= $message; + } + $context['page_title'] = $txt['lp_settings']; $context['settings_title'] = $txt['settings']; $context['post_url'] = $scripturl . '?action=admin;area=lp_settings;save'; @@ -159,7 +166,7 @@ public static function settingArea($return_config = false) array('check', 'lp_frontpage_disable', 'disabled' => !empty($modSettings['lp_standalone'])), array('select', 'lp_frontpage_mode', $txt['lp_frontpage_mode_set'], 'disabled' => !empty($modSettings['lp_frontpage_disable'])), array('boards', 'lp_frontpage_boards', 'disabled' => $frontpage_disabled), - array('int', 'lp_frontpage_layout', 'min' => 2, 'max' => 3, 'disabled' => $frontpage_disabled), + array('select', 'lp_frontpage_layout', $txt['lp_frontpage_layout_set'], 'disabled' => $frontpage_disabled), array('check', 'lp_show_images_in_articles', 'disabled' => $frontpage_disabled), array('int', 'lp_subject_size', 'min' => 0, 'disabled' => $frontpage_disabled), array('int', 'lp_teaser_size', 'min' => 0, 'disabled' => $frontpage_disabled), @@ -176,7 +183,8 @@ public static function settingArea($return_config = false) array('text', 'lp_page_itemprop_phone', 80), array('title', 'edit_permissions'), array('permissions', 'light_portal_view'), - array('permissions', 'light_portal_manage') + array('permissions', 'light_portal_manage_blocks'), + array('permissions', 'light_portal_manage_own_pages') ) ); @@ -232,6 +240,8 @@ private static function getDbInfo() */ public static function blockArea() { + isAllowedTo('light_portal_manage_blocks'); + $subActions = array( 'main' => 'Block::manage', 'add' => 'Block::add', @@ -250,6 +260,8 @@ public static function blockArea() */ public static function pageArea() { + isAllowedTo('light_portal_manage_own_pages'); + $subActions = array( 'main' => 'Page::manage', 'add' => 'Page::add', @@ -272,8 +284,6 @@ private static function loadGeneralSettingParameters($subActions = [], $defaultA { global $sourcedir, $context; - isAllowedTo('light_portal_manage'); - require_once($sourcedir . '/ManageServer.php'); $context['sub_template'] = 'show_settings'; @@ -285,4 +295,29 @@ private static function loadGeneralSettingParameters($subActions = [], $defaultA call_helper(__NAMESPACE__ . '\\' . $subActions[$_REQUEST['sa']]); } + + /** + * Check if exists the new version of LP + * + * Проверка новой версии мода + * + * @return bool + */ + public static function isNewVersionExist() + { + $ch = curl_init('https://api.github.com/repos/dragomano/light-portal/releases/latest'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + "User-Agent: dragomano" + ]); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $data = curl_exec($ch); + curl_close($ch); + $data = json_decode($data); + + if (LP_VERSION < str_replace('v', '', $data->tag_name)) + return true; + + return false; + } } diff --git a/Sources/LightPortal/Subs.php b/Sources/LightPortal/Subs.php index c89da30ad..457c76950 100644 --- a/Sources/LightPortal/Subs.php +++ b/Sources/LightPortal/Subs.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -24,14 +24,25 @@ class Subs * * Формируем массив статей * - * @param string $source (pages|topics) + * @param string $source (pages|topics|boards) * @return void */ public static function prepareArticles($source = 'pages') { global $user_info, $modSettings, $context, $scripturl; - $articles = Helpers::useCache('frontpage_' . $source . '_u' . $user_info['id'], $source == 'topics' ? 'getTopicsFromSelectedBoards' : 'getActivePages', __CLASS__); + switch ($source) { + case 'topics': + $function = 'getTopicsFromSelectedBoards'; + break; + case 'boards': + $function = 'getSelectedBoards'; + break; + default: + $function = 'getActivePages'; + } + + $articles = Helpers::useCache('frontpage_' . $source . '_u' . $user_info['id'], $function, __CLASS__); $total_items = count($articles); $limit = !empty($modSettings['lp_num_per_page']) ? (int) $modSettings['lp_num_per_page'] : 10; @@ -95,13 +106,15 @@ public static function getTopicsFromSelectedBoards() censorText($row['subject']); censorText($row['body']); + $row['subject'] = Helpers::cleanBbcode($row['subject']); + $rating = !empty($row['total_votes']) ? number_format($row['total_value'] / $row['total_votes'], 0) : 0; $image = null; if (!empty($modSettings['lp_show_images_in_articles'])) { $body = parse_bbc($row['body'], false); $first_post_image = preg_match('/' . $row['name'] . '', 'is_sticky' => !empty($row['is_sticky']), 'is_new' => $row['new_from'] <= $row['id_msg_modified'], @@ -150,7 +163,7 @@ public static function getTopicsFromSelectedBoards() */ public static function getActivePages() { - global $smcFunc, $modSettings, $scripturl, $settings, $user_info; + global $smcFunc, $modSettings, $settings, $scripturl, $user_info; $request = $smcFunc['db_query']('', ' SELECT @@ -177,7 +190,7 @@ public static function getActivePages() $image = null; if (!empty($modSettings['lp_show_images_in_articles'])) { $first_post_image = preg_match('/

%1$s%3$s

', - 'div.title_bar > h3.titlebg' => '

%1$s%3$s

', - 'div.title_bar > h4.titlebg' => '

%1$s%3$s

', - 'div.sub_bar > h3.subbg' => '

%1$s%3$s

', - 'div.sub_bar > h4.subbg' => '

%1$s%3$s

', - 'div.errorbox > h3' => '
%1$s%3$s
', - 'div.generic_list_wrapper > h3' => '
%1$s%3$s
' + 'div.cat_bar > h3.catbg' => '

%1$s

', + 'div.title_bar > h3.titlebg' => '

%1$s

', + 'div.title_bar > h4.titlebg' => '

%1$s

', + 'div.sub_bar > h3.subbg' => '

%1$s

', + 'div.sub_bar > h4.subbg' => '

%1$s

', + 'div.errorbox > h3' => '

%1$s

', + 'div.generic_list_wrapper > h3' => '

%1$s

' ]; } diff --git a/Sources/LightPortal/addons/BoardList/BoardList.php b/Sources/LightPortal/addons/BoardList/BoardList.php index 01cbc2845..abd954e6b 100644 --- a/Sources/LightPortal/addons/BoardList/BoardList.php +++ b/Sources/LightPortal/addons/BoardList/BoardList.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -100,10 +100,17 @@ public static function prepareBlockFields() ); foreach ($context['lp_all_title_classes'] as $key => $data) { - $context['posting_fields']['category_class']['input']['options'][$key] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['options']['parameters']['category_class'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['category_class']['input']['options'][$key]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['category_class'] + ); + } else { + $context['posting_fields']['category_class']['input']['options'][$key] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['category_class'] + ); + } } $context['posting_fields']['board_class']['label']['text'] = $txt['lp_boardlist_addon_board_class']; @@ -116,10 +123,17 @@ public static function prepareBlockFields() ); foreach ($context['lp_all_content_classes'] as $key => $data) { - $context['posting_fields']['board_class']['input']['options'][$key] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['options']['parameters']['board_class'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['board_class']['input']['options'][$key]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['board_class'] + ); + } else { + $context['posting_fields']['board_class']['input']['options'][$key] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['board_class'] + ); + } } } @@ -173,7 +187,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, ob_start(); foreach ($context['lp_boardlist'] as $category) { - echo sprintf($context['lp_all_title_classes'][$parameters['category_class']], $category['name'], null, null); + echo sprintf($context['lp_all_title_classes'][$parameters['category_class']], $category['name']); echo ' diff --git a/Sources/LightPortal/addons/BoardNews/BoardNews.php b/Sources/LightPortal/addons/BoardNews/BoardNews.php index dff92ef0a..0394084a6 100644 --- a/Sources/LightPortal/addons/BoardNews/BoardNews.php +++ b/Sources/LightPortal/addons/BoardNews/BoardNews.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -106,12 +106,21 @@ public static function prepareBlockFields() foreach ($board_list as $category) { $context['posting_fields']['board_id']['input']['options'][$category['name']] = array('options' => array()); - foreach ($category['boards'] as $board) - $context['posting_fields']['board_id']['input']['options'][$category['name']]['options'][$board['name']] = array( - 'value' => $board['id'], - 'selected' => (bool) $board['selected'], - 'label' => ($board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '') . ' ' . $board['name'], - ); + foreach ($category['boards'] as $board) { + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['board_id']['input']['options'][$category['name']]['options'][$board['name']]['attributes'] = array( + 'value' => $board['id'], + 'selected' => (bool) $board['selected'], + 'label' => ($board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '') . ' ' . $board['name'], + ); + } else { + $context['posting_fields']['board_id']['input']['options'][$category['name']]['options'][$board['name']] = array( + 'value' => $board['id'], + 'selected' => (bool) $board['selected'], + 'label' => ($board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '') . ' ' . $board['name'], + ); + } + } } $context['posting_fields']['num_posts']['label']['text'] = $txt['lp_board_news_addon_num_posts']; diff --git a/Sources/LightPortal/addons/EasyMDE/EasyMDE.php b/Sources/LightPortal/addons/EasyMDE/EasyMDE.php index 3bf1c6d14..629521b79 100644 --- a/Sources/LightPortal/addons/EasyMDE/EasyMDE.php +++ b/Sources/LightPortal/addons/EasyMDE/EasyMDE.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -94,6 +94,7 @@ className: "fas fa-italic", className: "fas fa-strikethrough", title: "' . $editortxt['strikethrough'] . '" }, + "|", { name: "heading-4", action: (editor) => { @@ -104,6 +105,25 @@ className: "fas fa-header", title: "' . $txt['lp_title'] . '" }, "|", + { + name: "image", + action: EasyMDE.drawImage, + className: "fas fa-picture-o", + title: "' . $editortxt['insert_image'] . '" + }, + { + name: "link", + action: EasyMDE.drawLink, + className: "fas fa-link", + title: "' . $editortxt['insert_link'] . '" + }, + "|", + { + name: "table", + action: EasyMDE.drawTable, + className: "fas fa-table", + title: "' . $editortxt['insert_table'] . '" + }, { name: "code", action: EasyMDE.toggleCodeBlock, @@ -116,6 +136,7 @@ className: "fas fa-code", className: "fas fa-quote-left", title: "' . $editortxt['insert_quote'] . '" }, + "|", { name: "unordered-list", action: EasyMDE.toggleUnorderedList, @@ -128,24 +149,14 @@ className: "fas fa-list-ul", className: "fas fa-list-ol", title: "' . $editortxt['numbered_list'] . '" }, - "|", - { - name: "link", - action: EasyMDE.drawLink, - className: "fas fa-link", - title: "' . $editortxt['insert_link'] . '" - }, - { - name: "image", - action: EasyMDE.drawImage, - className: "fas fa-picture-o", - title: "' . $editortxt['insert_image'] . '" - }, { - name: "table", - action: EasyMDE.drawTable, - className: "fas fa-table", - title: "' . $editortxt['insert_table'] . '" + name: "task-list", + action: (editor) => { + editor.codemirror.replaceSelection(\'- [ ] \'); + editor.codemirror.focus(); + }, + className: "fas fa-tasks", + title: "' . $txt['lp_easymde_addon_tasks'] . '" }, { name: "horizontal-rule", diff --git a/Sources/LightPortal/addons/EasyMDE/langs/english.php b/Sources/LightPortal/addons/EasyMDE/langs/english.php index ee85e1cb6..054b6fa40 100644 --- a/Sources/LightPortal/addons/EasyMDE/langs/english.php +++ b/Sources/LightPortal/addons/EasyMDE/langs/english.php @@ -3,6 +3,7 @@ $txt['lp_block_types']['md'] = 'Custom Markdown'; $txt['lp_block_types_descriptions']['md'] = 'In this block, you can use the basic Markdown syntax as content.'; +$txt['lp_easymde_addon_tasks'] = 'Task list'; $txt['lp_easymde_addon_lines'] = 'lines: '; $txt['lp_easymde_addon_words'] = 'words: '; $txt['lp_easymde_addon_toggle'] = 'Toggle Side by Side'; diff --git a/Sources/LightPortal/addons/EasyMDE/langs/russian.php b/Sources/LightPortal/addons/EasyMDE/langs/russian.php index 20015c161..7f5d3f921 100644 --- a/Sources/LightPortal/addons/EasyMDE/langs/russian.php +++ b/Sources/LightPortal/addons/EasyMDE/langs/russian.php @@ -3,6 +3,7 @@ $txt['lp_block_types']['md'] = 'Блок с Markdown-разметкой'; $txt['lp_block_types_descriptions']['md'] = 'В этом блоке в качестве контента можно использовать базовый синтаксис Markdown.'; +$txt['lp_easymde_addon_tasks'] = 'Список задач'; $txt['lp_easymde_addon_lines'] = 'строк: '; $txt['lp_easymde_addon_words'] = 'слов: '; $txt['lp_easymde_addon_toggle'] = 'Правка и превью вместе'; diff --git a/Sources/LightPortal/addons/EasyMDE/langs/ukrainian.php b/Sources/LightPortal/addons/EasyMDE/langs/ukrainian.php index 437550f18..95edcfc7c 100644 --- a/Sources/LightPortal/addons/EasyMDE/langs/ukrainian.php +++ b/Sources/LightPortal/addons/EasyMDE/langs/ukrainian.php @@ -3,6 +3,7 @@ $txt['lp_block_types']['md'] = 'Блок з Markdown-розміткою'; $txt['lp_block_types_descriptions']['md'] = 'У цьому блоці як контент можна використовувати базовий синтаксис Markdown.'; +$txt['lp_easymde_addon_tasks'] = 'Список задач'; $txt['lp_easymde_addon_lines'] = 'рядків: '; $txt['lp_easymde_addon_words'] = 'слів: '; $txt['lp_easymde_addon_toggle'] = 'Правка і превью разом'; diff --git a/Sources/LightPortal/addons/GoogleTranslate/GoogleTranslate.php b/Sources/LightPortal/addons/GoogleTranslate/GoogleTranslate.php index 9c9cb89bd..5ef0d7274 100644 --- a/Sources/LightPortal/addons/GoogleTranslate/GoogleTranslate.php +++ b/Sources/LightPortal/addons/GoogleTranslate/GoogleTranslate.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) diff --git a/Sources/LightPortal/addons/Likely/Likely.php b/Sources/LightPortal/addons/Likely/Likely.php index 7bf6722d3..ba04f08f0 100644 --- a/Sources/LightPortal/addons/Likely/Likely.php +++ b/Sources/LightPortal/addons/Likely/Likely.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -94,8 +94,26 @@ public static function prepareBlockFields() 'type' => 'select', 'attributes' => array( 'id' => 'size' - ), - 'options' => array( + ) + ); + + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['size']['input']['options'] = array( + 'small' => array( + 'attributes' => array( + 'value' => 'small', + 'selected' => 'small' == $context['lp_block']['options']['parameters']['size'] + ) + ), + 'big' => array( + 'attributes' => array( + 'value' => 'big', + 'selected' => 'big' == $context['lp_block']['options']['parameters']['size'] + ) + ) + ); + } else { + $context['posting_fields']['size']['input']['options'] = array( 'small' => array( 'value' => 'small', 'selected' => 'small' == $context['lp_block']['options']['parameters']['size'] @@ -104,16 +122,34 @@ public static function prepareBlockFields() 'value' => 'big', 'selected' => 'big' == $context['lp_block']['options']['parameters']['size'] ) - ) - ); + ); + } $context['posting_fields']['skin']['label']['text'] = $txt['lp_likely_addon_skin']; $context['posting_fields']['skin']['input'] = array( 'type' => 'select', 'attributes' => array( 'id' => 'skin' - ), - 'options' => array( + ) + ); + + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['skin']['input']['options'] = array( + 'normal' => array( + 'attributes' => array( + 'value' => 'normal', + 'selected' => 'normal' == $context['lp_block']['options']['parameters']['skin'] + ) + ), + 'light' => array( + 'attributes' => array( + 'value' => 'light', + 'selected' => 'light' == $context['lp_block']['options']['parameters']['skin'] + ) + ) + ); + } else { + $context['posting_fields']['skin']['input']['options'] = array( 'normal' => array( 'value' => 'normal', 'selected' => 'normal' == $context['lp_block']['options']['parameters']['skin'] @@ -122,8 +158,8 @@ public static function prepareBlockFields() 'value' => 'light', 'selected' => 'light' == $context['lp_block']['options']['parameters']['skin'] ) - ) - ); + ); + } $context['posting_fields']['buttons']['label']['text'] = $txt['lp_likely_addon_buttons']; $context['posting_fields']['buttons']['input'] = array( diff --git a/Sources/LightPortal/addons/Markdown/Markdown.php b/Sources/LightPortal/addons/Markdown/Markdown.php index 853a3a582..6ba2db7f0 100644 --- a/Sources/LightPortal/addons/Markdown/Markdown.php +++ b/Sources/LightPortal/addons/Markdown/Markdown.php @@ -2,8 +2,6 @@ namespace Bugo\LightPortal\Addons\Markdown; -use Bugo\LightPortal\Addons\Markdown\Michelf\MarkdownSMF; - /** * Markdown * @@ -13,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -45,7 +43,7 @@ private static function getParsedMarkdown($text) require_once(__DIR__ . '/Michelf/MarkdownExtra.inc.php'); require_once(__DIR__ . '/Michelf/MarkdownSMF.php'); - return MarkdownSMF::defaultTransform(un_htmlspecialchars($text)); + return Michelf\MarkdownSMF::defaultTransform(un_htmlspecialchars($text)); } /** diff --git a/Sources/LightPortal/addons/Markdown/Michelf/MarkdownSMF.php b/Sources/LightPortal/addons/Markdown/Michelf/MarkdownSMF.php index 46a4e9425..b00efe22e 100644 --- a/Sources/LightPortal/addons/Markdown/Michelf/MarkdownSMF.php +++ b/Sources/LightPortal/addons/Markdown/Michelf/MarkdownSMF.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ class MarkdownSMF extends \Michelf\MarkdownExtra @@ -206,7 +206,7 @@ protected function _doLists_callback($matches) $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul class=\"bbc_list\"" : "ul class=\"bbc_list\" style=\"list-style-type: decimal\""; - $marker_any_re = ( $list_type == "ul class=\"bbc_list\"" ? $marker_ul_re : $marker_ol_re ); + $marker_any_re = ($list_type == "ul class=\"bbc_list\"" ? $marker_ul_re : $marker_ol_re); $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); @@ -222,10 +222,10 @@ protected function _doLists_callback($matches) } } - if ($ol_start > 1 && $list_type == 'ul class=\"bbc_list\" style=\"list-style-type: decimal\"'){ - $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); + if ($ol_start > 1 && $list_type == 'ul class=\"bbc_list\" style=\"list-style-type: decimal\"') { + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); } else { - $result = $this->hashBlock("<$list_type>\n" . $result . ""); + $result = $this->hashBlock("<$list_type>\n" . $result . ""); } return "\n". $result ."\n\n"; diff --git a/Sources/LightPortal/addons/PageList/PageList.php b/Sources/LightPortal/addons/PageList/PageList.php index 6de29c53a..950c95a31 100644 --- a/Sources/LightPortal/addons/PageList/PageList.php +++ b/Sources/LightPortal/addons/PageList/PageList.php @@ -14,7 +14,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -84,10 +84,17 @@ public static function prepareBlockFields() ); foreach ($txt['lp_page_list_addon_sort_set'] as $key => $value) { - $context['posting_fields']['sort']['input']['options'][$value] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['options']['parameters']['sort'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['sort']['input']['options'][$value]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['sort'] + ); + } else { + $context['posting_fields']['sort']['input']['options'][$value] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['sort'] + ); + } } } diff --git a/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php b/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php index 18876b4a7..107a412d6 100644 --- a/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php +++ b/Sources/LightPortal/addons/RecentAttachments/RecentAttachments.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8.1 + * @version 0.9 */ if (!defined('SMF')) @@ -123,10 +123,17 @@ public static function prepareBlockFields() ); foreach ($txt['lp_recent_attachments_addon_direction_set'] as $direction => $title) { - $context['posting_fields']['direction']['input']['options'][$title] = array( - 'value' => $direction, - 'selected' => $direction == $context['lp_block']['options']['parameters']['direction'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['direction']['input']['options'][$title]['attributes'] = array( + 'value' => $direction, + 'selected' => $direction == $context['lp_block']['options']['parameters']['direction'] + ); + } else { + $context['posting_fields']['direction']['input']['options'][$title] = array( + 'value' => $direction, + 'selected' => $direction == $context['lp_block']['options']['parameters']['direction'] + ); + } } } diff --git a/Sources/LightPortal/addons/RecentPosts/RecentPosts.php b/Sources/LightPortal/addons/RecentPosts/RecentPosts.php index bb90c1d92..0f8e66d00 100644 --- a/Sources/LightPortal/addons/RecentPosts/RecentPosts.php +++ b/Sources/LightPortal/addons/RecentPosts/RecentPosts.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -110,10 +110,17 @@ public static function prepareBlockFields() ); foreach ($txt['lp_recent_posts_addon_type_set'] as $key => $value) { - $context['posting_fields']['link_type']['input']['options'][$value] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['options']['parameters']['link_type'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['link_type']['input']['options'][$value]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['link_type'] + ); + } else { + $context['posting_fields']['link_type']['input']['options'][$value] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['link_type'] + ); + } } } @@ -162,7 +169,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, echo '
  • ', ($post['is_new'] ? '' . $txt['new'] . ' ' : ''), $post[$parameters['link_type']], ' -
    ', $txt['by'], ' ', $post['poster']['link'], ' +
    ', $txt['by'], ' ', $post['poster']['link'], '
    ', Helpers::getFriendlyTime($post['timestamp']), '
  • '; } diff --git a/Sources/LightPortal/addons/RecentTopics/RecentTopics.php b/Sources/LightPortal/addons/RecentTopics/RecentTopics.php index a6353a5d9..0dbeb20a8 100644 --- a/Sources/LightPortal/addons/RecentTopics/RecentTopics.php +++ b/Sources/LightPortal/addons/RecentTopics/RecentTopics.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -135,7 +135,7 @@ public static function prepareContent(&$content, $type, $block_id, $cache_time, echo '
  • ', ($topic['is_new'] ? '' . $txt['new'] . '' : ''), $topic['icon'], ' ', $topic['link'], ' -
    ', $txt['by'], ' ', $topic['poster']['link'], ' +
    ', $txt['by'], ' ', $topic['poster']['link'], '
    ', Helpers::getFriendlyTime($topic['timestamp']), '
  • '; } diff --git a/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php b/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php index 240a095b5..d4dfac7ba 100644 --- a/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php +++ b/Sources/LightPortal/addons/ThemeSwitcher/ThemeSwitcher.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) diff --git a/Sources/LightPortal/addons/Todays/Todays.php b/Sources/LightPortal/addons/Todays/Todays.php new file mode 100644 index 000000000..cb9cafea0 --- /dev/null +++ b/Sources/LightPortal/addons/Todays/Todays.php @@ -0,0 +1,151 @@ + + * @copyright 2019-2020 Bugo + * @license https://opensource.org/licenses/BSD-3-Clause BSD + * + * @version 0.9 + */ + +if (!defined('SMF')) + die('Hacking attempt...'); + +class Todays +{ + /** + * Что отображаем (birthdays|holidays|events|calendar) + * + * @var string + */ + private static $type = 'calendar'; + + /** + * Добавляем параметры блока + * + * @param array $options + * @return void + */ + public static function blockOptions(&$options) + { + $options['todays'] = array( + 'parameters' => array( + 'widget_type' => static::$type + ) + ); + } + + /** + * Валидируем параметры + * + * @param array $args + * @return void + */ + public static function validateBlockData(&$args) + { + global $context; + + if ($context['current_block']['type'] !== 'todays') + return; + + $args['parameters'] = array( + 'widget_type' => FILTER_SANITIZE_STRING + ); + } + + /** + * Добавляем поля конкретно для этого блока + * + * @return void + */ + public static function prepareBlockFields() + { + global $context, $txt; + + if ($context['lp_block']['type'] !== 'todays') + return; + + $context['posting_fields']['widget_type']['label']['text'] = $txt['lp_todays_addon_type']; + $context['posting_fields']['widget_type']['input'] = array( + 'type' => 'select', + 'attributes' => array( + 'id' => 'widget_type' + ), + 'options' => array() + ); + + foreach ($txt['lp_todays_addon_type_set'] as $key => $value) { + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['widget_type']['input']['options'][$value]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['widget_type'] + ); + } else { + $context['posting_fields']['widget_type']['input']['options'][$value] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['widget_type'] + ); + } + } + } + + /** + * Получаем список того, что запрашиваем + * + * @param string $type + * @param string $output_method + * @return string + */ + public static function getTodays($type, $output_method = 'echo') + { + global $boarddir; + + $funcName = 'ssi_todays' . ucfirst($type); + + require_once($boarddir . '/SSI.php'); + return function_exists($funcName) ? $funcName($output_method) : ''; + } + + /** + * Формируем контент блока + * + * @param string $content + * @param string $type + * @param int $block_id + * @param int $cache_time + * @param array $parameters + * @return void + */ + public static function prepareContent(&$content, $type, $block_id, $cache_time, $parameters) + { + global $txt; + + if ($type !== 'todays') + return; + + ob_start(); + + $result = self::getTodays($parameters['widget_type'], 'array'); + + if ($parameters['widget_type'] == 'calendar') { + if (!empty($result['calendar_holidays']) || !empty($result['calendar_birthdays']) || !empty($result['calendar_events'])) + self::getTodays($parameters['widget_type']); + else + echo $txt['lp_todays_addon_empty_list']; + } elseif (!empty($result)) { + self::getTodays($parameters['widget_type']); + } else { + echo $txt['lp_todays_addon_empty_list']; + } + + $content = ob_get_clean(); + } +} diff --git a/Sources/LightPortal/addons/Todays/index.php b/Sources/LightPortal/addons/Todays/index.php new file mode 100644 index 000000000..69278ce68 --- /dev/null +++ b/Sources/LightPortal/addons/Todays/index.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/Sources/LightPortal/addons/Todays/langs/english.php b/Sources/LightPortal/addons/Todays/langs/english.php new file mode 100644 index 000000000..51abc7d38 --- /dev/null +++ b/Sources/LightPortal/addons/Todays/langs/english.php @@ -0,0 +1,8 @@ + 'Birthdays', 'holidays' => 'Holidays', 'events' => 'Events', 'calendar' => 'Calendar'); +$txt['lp_todays_addon_empty_list'] = 'There is nothing today.'; \ No newline at end of file diff --git a/Sources/LightPortal/addons/Todays/langs/index.php b/Sources/LightPortal/addons/Todays/langs/index.php new file mode 100644 index 000000000..69278ce68 --- /dev/null +++ b/Sources/LightPortal/addons/Todays/langs/index.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/Sources/LightPortal/addons/Todays/langs/russian.php b/Sources/LightPortal/addons/Todays/langs/russian.php new file mode 100644 index 000000000..79dca9dcc --- /dev/null +++ b/Sources/LightPortal/addons/Todays/langs/russian.php @@ -0,0 +1,8 @@ + 'Дни рождения', 'holidays' => 'Праздники', 'events' => 'События', 'calendar' => 'Календарь'); +$txt['lp_todays_addon_empty_list'] = 'Сегодня ничего нет.'; \ No newline at end of file diff --git a/Sources/LightPortal/addons/Todays/langs/ukrainian.php b/Sources/LightPortal/addons/Todays/langs/ukrainian.php new file mode 100644 index 000000000..eeaf12d8a --- /dev/null +++ b/Sources/LightPortal/addons/Todays/langs/ukrainian.php @@ -0,0 +1,8 @@ + 'Дні народження', 'holidays' => 'Свята', 'events' => 'Події', 'calendar' => 'Календар'); +$txt['lp_todays_addon_empty_list'] = 'Сьогодні нічого немає.'; \ No newline at end of file diff --git a/Sources/LightPortal/addons/TopBoards/TopBoards.php b/Sources/LightPortal/addons/TopBoards/TopBoards.php index aa117eac2..ed060bdd9 100644 --- a/Sources/LightPortal/addons/TopBoards/TopBoards.php +++ b/Sources/LightPortal/addons/TopBoards/TopBoards.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) diff --git a/Sources/LightPortal/addons/TopPosters/TopPosters.php b/Sources/LightPortal/addons/TopPosters/TopPosters.php index 330f1f1bd..57af9ab37 100644 --- a/Sources/LightPortal/addons/TopPosters/TopPosters.php +++ b/Sources/LightPortal/addons/TopPosters/TopPosters.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) diff --git a/Sources/LightPortal/addons/TopTopics/TopTopics.php b/Sources/LightPortal/addons/TopTopics/TopTopics.php index 2e23b821e..f3da6086b 100644 --- a/Sources/LightPortal/addons/TopTopics/TopTopics.php +++ b/Sources/LightPortal/addons/TopTopics/TopTopics.php @@ -13,7 +13,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -101,10 +101,17 @@ public static function prepareBlockFields() ); foreach ($txt['lp_top_topics_addon_type_set'] as $key => $value) { - $context['posting_fields']['popularity_type']['input']['options'][$value] = array( - 'value' => $key, - 'selected' => $key == $context['lp_block']['options']['parameters']['popularity_type'] - ); + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['popularity_type']['input']['options'][$value]['attributes'] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['popularity_type'] + ); + } else { + $context['posting_fields']['popularity_type']['input']['options'][$value] = array( + 'value' => $key, + 'selected' => $key == $context['lp_block']['options']['parameters']['popularity_type'] + ); + } } $context['posting_fields']['num_topics']['label']['text'] = $txt['lp_top_topics_addon_num_topics']; diff --git a/Sources/LightPortal/addons/Trumbowyg.php b/Sources/LightPortal/addons/Trumbowyg.php index 41ccded00..e5745f275 100644 --- a/Sources/LightPortal/addons/Trumbowyg.php +++ b/Sources/LightPortal/addons/Trumbowyg.php @@ -11,7 +11,7 @@ * @copyright 2019-2020 Bugo * @license https://opensource.org/licenses/BSD-3-Clause BSD * - * @version 0.8 + * @version 0.9 */ if (!defined('SMF')) @@ -27,19 +27,48 @@ class Trumbowyg */ public static function prepareEditor($object) { - global $txt; + global $txt, $editortxt; if ($object['type'] == 'html') { + loadLanguage('Editor'); + loadCssFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/ui/trumbowyg.min.css', array('external' => true)); loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/trumbowyg.min.js', array('external' => true)); - loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/langs/' . $txt['lang_dictionary'] . '.min.js', array('external' => true)); + + if ($txt['lang_dictionary'] !== 'en') + loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/langs/' . $txt['lang_dictionary'] . '.min.js', array('external' => true)); + + loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/plugins/history/trumbowyg.history.min.js', array('external' => true)); + loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/plugins/pasteimage/trumbowyg.pasteimage.min.js', array('external' => true)); + loadJavaScriptFile('https://cdn.jsdelivr.net/npm/trumbowyg@2/plugins/preformatted/trumbowyg.preformatted.min.js', array('external' => true)); addInlineJavaScript(' $("#content").trumbowyg({ lang: "' . $txt['lang_dictionary'] . '", + btnsDef: { + historyUndo: { + title: "' . $editortxt['undo'] . '" + }, + historyRedo: { + title: "' . $editortxt['redo'] . '" + } + }, + btns: [ + ["historyUndo", "historyRedo"], + ["strong", "em", "del"], + ["p", "h4"], + ["superscript", "subscript"], + ["justifyLeft", "justifyCenter", "justifyRight", "justifyFull"], + ["insertImage", "link"], + ["table", "preformatted", "blockquote"], + ["unorderedList", "orderedList"], + ["horizontalRule"], + ["viewHTML", "removeformat"], + ["fullscreen"] + ], semantic: true, urlProtocol: true, imageWidthModalEdit: true - }).trumbowyg("toggle");', true); + });', true); } } diff --git a/Sources/LightPortal/addons/UserInfo/UserInfo.php b/Sources/LightPortal/addons/UserInfo/UserInfo.php new file mode 100644 index 000000000..3c476ec0f --- /dev/null +++ b/Sources/LightPortal/addons/UserInfo/UserInfo.php @@ -0,0 +1,88 @@ + + * @copyright 2019-2020 Bugo + * @license https://opensource.org/licenses/BSD-3-Clause BSD + * + * @version 0.9 + */ + +if (!defined('SMF')) + die('Hacking attempt...'); + +class UserInfo +{ + /** + * Получаем список популярных тем + * + * @return array + */ + public static function getUserInfo() + { + global $user_info, $memberContext; + + loadMemberData($user_info['id']); + loadMemberContext($user_info['id'], true); + + return $memberContext[$user_info['id']]; + } + + /** + * Формируем контент блока + * + * @param string $content + * @param string $type + * @param int $block_id + * @param int $cache_time + * @return void + */ + public static function prepareContent(&$content, $type, $block_id, $cache_time) + { + global $context, $txt, $scripturl, $boarddir; + + if ($type !== 'user_info') + return; + + ob_start(); + + if ($context['user']['is_logged']) { + $userData = Helpers::useCache('user_info_addon_u' . $context['user']['id'], 'getUserInfo', __CLASS__, $cache_time); + + echo ' + '; + } else { + require_once($boarddir . '/SSI.php'); + ssi_welcome(); + } + + $content = ob_get_clean(); + } +} diff --git a/Sources/LightPortal/addons/UserInfo/index.php b/Sources/LightPortal/addons/UserInfo/index.php new file mode 100644 index 000000000..69278ce68 --- /dev/null +++ b/Sources/LightPortal/addons/UserInfo/index.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/Sources/LightPortal/addons/UserInfo/langs/english.php b/Sources/LightPortal/addons/UserInfo/langs/english.php new file mode 100644 index 000000000..319bc5717 --- /dev/null +++ b/Sources/LightPortal/addons/UserInfo/langs/english.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/Sources/LightPortal/addons/UserInfo/langs/russian.php b/Sources/LightPortal/addons/UserInfo/langs/russian.php new file mode 100644 index 000000000..c713c1b4b --- /dev/null +++ b/Sources/LightPortal/addons/UserInfo/langs/russian.php @@ -0,0 +1,4 @@ + 'select', 'attributes' => array( 'id' => 'widget_theme' - ), - 'options' => array( + ) + ); + + if (!defined('JQUERY_VERSION')) { + $context['posting_fields']['widget_theme']['input']['options'] = array( + 'light' => array( + 'attributes' => array( + 'value' => 'light', + 'selected' => 'light' == $context['lp_block']['options']['parameters']['widget_theme'] + ) + ), + 'dark' => array( + 'attributes' => array( + 'value' => 'dark', + 'selected' => 'dark' == $context['lp_block']['options']['parameters']['widget_theme'] + ) + ) + ); + } else { + $context['posting_fields']['widget_theme']['input']['options'] = array( 'light' => array( 'value' => 'light', 'selected' => 'light' == $context['lp_block']['options']['parameters']['widget_theme'] @@ -103,8 +121,8 @@ public static function prepareBlockFields() 'value' => 'dark', 'selected' => 'dark' == $context['lp_block']['options']['parameters']['widget_theme'] ) - ) - ); + ); + } $context['posting_fields']['auto_mode']['label']['text'] = $txt['lp_yandex_translate_addon_auto_mode']; $context['posting_fields']['auto_mode']['input'] = array( diff --git a/Themes/default/LightPortal/ManageBlocks.template.php b/Themes/default/LightPortal/ManageBlocks.template.php index 42a55860e..6a34c27d3 100644 --- a/Themes/default/LightPortal/ManageBlocks.template.php +++ b/Themes/default/LightPortal/ManageBlocks.template.php @@ -168,7 +168,7 @@ function show_block_table() echo ' - ', $txt['lp_no_items'], ' + ', $txt['lp_no_items'], ' '; } @@ -242,10 +242,16 @@ function template_block_post() if (!empty($context['lp_block']['content_style'])) $style = ' style="' . $context['lp_block']['content_style'] . '"'; + echo ' +
    '; + if (!empty($context['lp_block']['content_class'])) echo sprintf($context['lp_all_content_classes'][$context['lp_block']['content_class']], $context['preview_content'], $style); else echo $context['preview_content']; + + echo ' +
    '; } else { echo '
    diff --git a/Themes/default/LightPortal/ManagePages.template.php b/Themes/default/LightPortal/ManagePages.template.php index 36c4fc807..c233d3432 100644 --- a/Themes/default/LightPortal/ManagePages.template.php +++ b/Themes/default/LightPortal/ManagePages.template.php @@ -77,7 +77,7 @@ function template_manage_pages_below() echo '