Skip to content

Commit

Permalink
v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomano committed Jan 10, 2020
1 parent 9d1cc42 commit e2d94b8
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 351 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* **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.0-7.3 / MariaDB 10.3 / PostgreSQL 9.6
* **Tested on:** PHP 7.3.13 / MariaDB 10.3.13 / PostgreSQL 9.6.12
* **Hooks only:** Yes
* **Languages:** English, Russian, Ukrainian

Expand Down
6 changes: 1 addition & 5 deletions Sources/LightPortal/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2020 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause BSD
*
* @version 0.2
* @version 0.3
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -84,7 +84,6 @@ public static function manage()
{
global $context, $txt;

isAllowedTo('light_portal_manage');
loadTemplate('LightPortal/ManageBlocks');

$context['page_title'] = $txt['lp_portal'] . ' - ' . $txt['lp_blocks_manage'];
Expand Down Expand Up @@ -299,7 +298,6 @@ public static function add()
{
global $context, $txt, $scripturl;

isAllowedTo('light_portal_manage');
loadTemplate('LightPortal/ManageBlocks');

$context['page_title'] = $txt['lp_portal'] . ' - ' . $txt['lp_blocks_add_title'];
Expand Down Expand Up @@ -340,8 +338,6 @@ public static function edit()
{
global $context, $txt, $user_info, $scripturl;

isAllowedTo('light_portal_manage');

$item = !empty($_REQUEST['block_id']) ? (int) $_REQUEST['block_id'] : null;
$item = $item ?: (!empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : null);

Expand Down
30 changes: 23 additions & 7 deletions Sources/LightPortal/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2020 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause BSD
*
* @version 0.2
* @version 0.3
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function userInfo()
global $sourcedir;

$lp_constants = [
'LP_VERSION' => '0.1',
'LP_VERSION' => '0.3',
'LP_NAME' => 'Light Portal',
'LP_ADDONS' => $sourcedir . '/LightPortal/addons'
];
Expand All @@ -86,6 +86,9 @@ public static function loadTheme()
{
global $txt;

if (!defined('LP_NAME'))
return;

loadLanguage('LightPortal/');

Subs::runAddons();
Expand Down Expand Up @@ -182,8 +185,11 @@ public static function menuButtons(&$buttons)
if (!defined('LP_NAME'))
return;

$context['allow_light_portal_manage'] = allowedTo('light_portal_manage');

// Display "Portal settings" in Main Menu => Admin | Отображение пункта "Настройки портала"
if ($context['allow_admin']) {
if ($context['allow_light_portal_manage']) {
$buttons['admin']['show'] = true;
$counter = 0;
foreach ($buttons['admin']['sub_buttons'] as $area => $dummy) {
$counter++;
Expand All @@ -193,11 +199,11 @@ public static function menuButtons(&$buttons)

$buttons['admin']['sub_buttons'] = array_merge(
array_slice($buttons['admin']['sub_buttons'], 0, $counter, true),
array(
'portalsettings' => array(
allowedTo('admin_forum') ? array(
'portal_settings' => array(
'title' => $txt['lp_settings'],
'href' => $scripturl . '?action=admin;area=lp_settings',
'show' => allowedTo('admin_forum'),
'show' => true,
'sub_buttons' => array(
'blocks' => array(
'title' => $txt['lp_blocks'],
Expand All @@ -212,6 +218,17 @@ public static function menuButtons(&$buttons)
)
)
)
) : array(
'portal_blocks' => array(
'title' => $txt['lp_blocks'],
'href' => $scripturl . '?action=admin;area=lp_blocks',
'show' => true
),
'portal_pages' => array(
'title' => $txt['lp_pages'],
'href' => $scripturl . '?action=admin;area=lp_pages',
'show' => true
)
),
array_slice($buttons['admin']['sub_buttons'], $counter, null, true)
);
Expand Down Expand Up @@ -308,7 +325,6 @@ 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');

$leftPermissionGroups[] = 'light_portal';
}
Expand Down
44 changes: 27 additions & 17 deletions Sources/LightPortal/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2020 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause BSD
*
* @version 0.2
* @version 0.3
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -85,7 +85,6 @@ public static function manage()
{
global $context, $txt, $modSettings, $scripturl, $sourcedir;

isAllowedTo('light_portal_manage');
loadTemplate('LightPortal/ManagePages');

$context['page_title'] = $txt['lp_portal'] . ' - ' . $txt['lp_pages_manage'];
Expand All @@ -95,7 +94,8 @@ public static function manage()
'description' => $txt['lp_pages_manage_tab_description']
);

$context['template_layers'][] = 'manage_pages';
if (allowedTo('admin_forum'))
$context['template_layers'][] = 'manage_pages';

self::postActions();

Expand Down Expand Up @@ -241,11 +241,14 @@ public static function getAll($start, $items_per_page, $sort)
global $smcFunc, $context;

$request = $smcFunc['db_query']('', '
SELECT page_id, title, alias, type, status, num_views, GREATEST(created_at, updated_at) AS date
FROM {db_prefix}lp_pages
SELECT page_id, author_id, title, alias, type, status, num_views, GREATEST(created_at, updated_at) AS date
FROM {db_prefix}lp_pages' . (allowedTo('admin_forum') ? '' : '
WHERE author_id = {int:user_id}') . '
ORDER BY ' . $sort . ', page_id
LIMIT ' . $start . ', ' . $items_per_page,
array()
array(
'user_id' => $context['user']['id']
)
);

$items = [];
Expand Down Expand Up @@ -282,14 +285,16 @@ public static function getAll($start, $items_per_page, $sort)
*/
public static function getTotalQuantity()
{
global $smcFunc;
global $smcFunc, $context;

$request = $smcFunc['db_query']('', '
SELECT COUNT(page_id)
FROM {db_prefix}lp_pages
WHERE alias != {string:alias}',
WHERE alias != {string:alias}' . (allowedTo('admin_forum') ? '' : '
AND author_id = {int:user_id}'),
array(
'alias' => '/'
'alias' => '/',
'user_id' => $context['user']['id']
)
);

Expand Down Expand Up @@ -380,12 +385,11 @@ public static function add()
{
global $context, $txt, $scripturl;

isAllowedTo('light_portal_manage');
loadTemplate('LightPortal/ManagePages');

$context['page_title'] = $txt['lp_portal'] . ' - ' . $txt['lp_pages_add_title'];
$context['page_title'] = $txt['lp_portal'] . ' - ' . $txt['lp_pages_add_title'];
$context['page_area_title'] = $txt['lp_pages_add_title'];
$context['canonical_url'] = $scripturl . '?action=admin;area=lp_pages;sa=add';
$context['canonical_url'] = $scripturl . '?action=admin;area=lp_pages;sa=add';

$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => LP_NAME,
Expand All @@ -411,7 +415,6 @@ public static function edit()
{
global $context, $txt, $scripturl;

isAllowedTo('light_portal_manage');
loadTemplate('LightPortal/ManagePages');

$item = !empty($_REQUEST['page_id']) ? (int) $_REQUEST['page_id'] : null;
Expand All @@ -431,10 +434,13 @@ public static function edit()

$context['lp_page'] = self::getData($item, is_int($item) ? false : true);

if (!$context['lp_page']['can_edit'])
fatal_lang_error('lp_page_not_editable', false);

self::validateData();

$context['page_area_title'] = $txt['lp_pages_edit_title'] . ' - ' . $context['lp_page']['title'];
$context['canonical_url'] = $scripturl . '?action=admin;area=lp_pages;sa=edit;id=' . $context['lp_page']['id'];
$context['canonical_url'] = $scripturl . '?action=admin;area=lp_pages;sa=edit;id=' . $context['lp_page']['id'];

self::prepareFormFields();
self::prepareEditor();
Expand Down Expand Up @@ -717,6 +723,7 @@ public static function setData($item = null)
$item = $smcFunc['db_insert']('',
'{db_prefix}lp_pages',
array_merge(array(
'author_id' => 'int',
'title' => 'string-255',
'alias' => 'string-255',
'description' => 'string-255',
Expand All @@ -727,6 +734,7 @@ public static function setData($item = null)
'created_at' => 'int'
), $db_type == 'postgresql' ? array('page_id' => 'int') : array()),
array_merge(array(
$context['user']['id'],
$context['lp_page']['title'],
$context['lp_page']['alias'],
$context['lp_page']['description'],
Expand Down Expand Up @@ -799,14 +807,14 @@ private static function getAutoIncrementValue()
*/
public static function getData($item, $useAlias = true)
{
global $smcFunc;
global $smcFunc, $user_info;

if (empty($item))
return;

if (($data = cache_get_data('light_portal_page_' . $item, 3600)) == null) {
$request = $smcFunc['db_query']('', '
SELECT page_id, title, alias, description, keywords, content, type, permissions, status, created_at, updated_at
SELECT page_id, author_id, title, alias, description, keywords, content, type, permissions, status, created_at, updated_at
FROM {db_prefix}lp_pages
WHERE ' . ($useAlias ? 'alias = {string' : 'page_id = {int') . ':item}
LIMIT 1',
Expand All @@ -825,6 +833,7 @@ public static function getData($item, $useAlias = true)

$data = array(
'id' => $row['page_id'],
'author_id' => $row['author_id'],
'title' => $row['title'],
'alias' => $row['alias'],
'description' => $row['description'],
Expand All @@ -835,7 +844,8 @@ public static function getData($item, $useAlias = true)
'status' => $row['status'],
'created_at' => $row['created_at'],
'updated_at' => $row['updated_at'],
'can_show' => Subs::canShowItem($row['permissions'])
'can_show' => Subs::canShowItem($row['permissions']),
'can_edit' => $user_info['is_admin'] || (allowedTo('light_portal_manage') && $row['author_id'] == $user_info['id'])
);
}

Expand Down
41 changes: 29 additions & 12 deletions Sources/LightPortal/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright 2019-2020 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause BSD
*
* @version 0.2
* @version 0.3
*/

if (!defined('SMF'))
Expand All @@ -31,7 +31,6 @@ public static function adminAreas(&$admin_areas)
global $sourcedir, $txt;

require_once($sourcedir . '/ManageSettings.php');

loadLanguage('ManageSettings');

// Looking for the "Forum" section... | Ищем раздел "Форум"...
Expand All @@ -43,15 +42,15 @@ public static function adminAreas(&$admin_areas)
array(
'lp_portal' => array(
'title' => $txt['lp_portal'],
'permission' => array('admin_forum', 'moderate_forum', 'light_portal_manage'),
'permission' => array('admin_forum', 'light_portal_manage'),
'areas' => array(
'lp_settings' => array(
'label' => $txt['settings'],
'function' => function () {
self::settingArea();
},
'icon' => 'features',
'permission' => array('admin_forum', 'light_portal_manage'),
'permission' => array('admin_forum'),
'subsections' => array()
),
'lp_blocks' => array(
Expand Down Expand Up @@ -110,8 +109,6 @@ public static function settingArea($return_config = false)
{
global $sourcedir, $txt, $scripturl, $db_type, $context, $modSettings;

isAllowedTo('light_portal_manage');

require_once($sourcedir . '/ManageServer.php');

$databases = self::getDatabases();
Expand All @@ -121,8 +118,6 @@ public static function settingArea($return_config = false)
'description' => sprintf($txt['lp_php_mysql_info'], LP_VERSION, phpversion(), $databases[$db_type]['name'], eval($databases[$db_type]['version_check']))
);

$context['permissions_excluded']['light_portal_manage'] = array(-1);

$context['page_title'] = $txt['lp_settings'];
$context['settings_title'] = $txt['settings'];
$context['post_url'] = $scripturl . '?action=admin;area=lp_settings;save';
Expand Down Expand Up @@ -212,9 +207,7 @@ public static function blockArea()
'edit' => 'Block::edit'
);

loadGeneralSettingParameters($subActions, 'main');

call_helper(__NAMESPACE__ . '\\' . $subActions[$_REQUEST['sa']]);
self::loadGeneralSettingParameters($subActions, 'main');
}

/**
Expand All @@ -231,7 +224,31 @@ public static function pageArea()
'edit' => 'Page::edit'
);

loadGeneralSettingParameters($subActions, 'main');
self::loadGeneralSettingParameters($subActions, 'main');
}

/**
* Calls the requested subaction if it does exist; otherwise, calls the default action
* Вызывает метод, если он существует; в противном случае вызывается метод по умолчанию
*
* @param array $subActions
* @param string $defaultAction
* @return void
*/
private static function loadGeneralSettingParameters($subActions = [], $defaultAction = null)
{
global $sourcedir, $context;

isAllowedTo('light_portal_manage');

require_once($sourcedir . '/ManageServer.php');

$context['sub_template'] = 'show_settings';

$defaultAction = $defaultAction ?: key($subActions);

$_REQUEST['sa'] = isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : $defaultAction;
$context['sub_action'] = $_REQUEST['sa'];

call_helper(__NAMESPACE__ . '\\' . $subActions[$_REQUEST['sa']]);
}
Expand Down
Loading

0 comments on commit e2d94b8

Please sign in to comment.