Skip to content

Commit

Permalink
v0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomano committed Jan 22, 2020
1 parent 0049985 commit f898438
Show file tree
Hide file tree
Showing 66 changed files with 1,305 additions and 319 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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.4.1 / MariaDB 10.3.13 / PostgreSQL 9.6.12
* **Tested on:** PHP 7.3.13 / MariaDB 10.3.13 / PostgreSQL 9.6.12
* **Hooks only:** Yes
* **Languages:** English, Russian, Ukrainian

Expand Down
79 changes: 45 additions & 34 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.7
* @version 0.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -48,7 +48,7 @@ public static function display($area = 'portal')
$data['title_class'] = '';

if (empty($data['content']))
Subs::runAddons('prepareContent', array(&$data['content'], $data['type'], $data['id']));
Subs::prepareContent($data['content'], $data['type'], $data['id'], 3600);
else
Subs::parseContent($data['content'], $data['type']);

Expand Down Expand Up @@ -197,21 +197,24 @@ private static function remove()
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}lp_block_params
WHERE block_id = {int:id}',
DELETE FROM {db_prefix}lp_params
WHERE item_id = {int:id}
AND type = {string:type}',
array(
'id' => $item
'id' => $item,
'type' => 'block'
)
);
} else {
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}lp_blocks, {db_prefix}lp_block_titles, {db_prefix}lp_block_params
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_block_params ON ({db_prefix}lp_block_params.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(
'id' => $item
'type' => 'block',
'id' => $item
)
);
}
Expand Down Expand Up @@ -327,7 +330,7 @@ public static function add()

Subs::getForumLanguages();

$context['sub_template'] = 'post_block';
$context['sub_template'] = 'block_post';

self::validateData();
self::prepareFormFields();
Expand Down Expand Up @@ -366,7 +369,7 @@ public static function edit()

Subs::getForumLanguages();

$context['sub_template'] = 'post_block';
$context['sub_template'] = 'block_post';
$context['current_block'] = self::getData($item);

self::validateData();
Expand All @@ -393,13 +396,13 @@ private static function getOptions()
{
$options = [
'bbc' => [
'content' => 'sceditor'
'content' => true
],
'html' => [
'content' => 'textarea'
'content' => true
],
'php' => [
'content' => 'textarea'
'content' => true
]
];

Expand Down Expand Up @@ -651,7 +654,7 @@ private static function prepareFormFields()
);
}

if (!empty($context['lp_block']['options']['content']) && $context['lp_block']['options']['content'] === 'textarea') {
if (!empty($context['lp_block']['options']['content']) && $context['lp_block']['type'] !== 'bbc') {
$context['posting_fields']['content']['label']['text'] = $txt['lp_block_content'];
$context['posting_fields']['content']['input'] = array(
'type' => 'textarea',
Expand All @@ -664,6 +667,11 @@ private static function prepareFormFields()

Subs::runAddons('prepareBlockFields');

foreach ($context['posting_fields'] as $item => $data) {
if ($item !== 'icon' && !empty($data['input']['after']))
$context['posting_fields'][$item]['input']['after'] = '<div class="information alternative smalltext">' . $data['input']['after'] . '</div>';
}

loadTemplate('Post');
}

Expand All @@ -678,8 +686,10 @@ private static function prepareEditor()
{
global $context;

if (!empty($context['lp_block']['options']['content']) && $context['lp_block']['options']['content'] === 'sceditor')
if (!empty($context['lp_block']['options']['content']) && $context['lp_block']['type'] === 'bbc')
Subs::createBbcEditor($context['lp_block']['content']);

Subs::runAddons('prepareEditor', array($context['lp_block']));
}

/**
Expand All @@ -706,12 +716,12 @@ private static function showPreview()
censorText($context['preview_content']);

if (empty($context['preview_content']))
Subs::runAddons('prepareContent', array(&$context['preview_content'], $context['lp_block']['type'], $context['lp_block']['id']));
Subs::prepareContent($context['preview_content'], $context['lp_block']['type']);
else
Subs::parseContent($context['preview_content'], $context['lp_block']['type']);

$context['page_title'] = $txt['preview'] . ($context['preview_title'] ? ' - ' . $context['preview_title'] : '');
$context['preview_title'] = self::getIcon() . Helpers::getPreviewTitle();
$context['preview_title'] = Helpers::getPreviewTitle(self::getIcon());
}

/**
Expand Down Expand Up @@ -824,21 +834,21 @@ public static function setData($item = null)
$parameters = [];
foreach ($context['lp_block']['options']['parameters'] as $param_name => $value) {
$parameters[] = array(
'block_id' => $item,
'name' => $param_name,
'value' => $value
'item_id' => $item,
'name' => $param_name,
'value' => $value
);
}

$smcFunc['db_insert']('',
'{db_prefix}lp_block_params',
'{db_prefix}lp_params',
array(
'block_id' => 'int',
'name' => 'string',
'value' => 'string'
'item_id' => 'int',
'name' => 'string',
'value' => 'string'
),
$parameters,
array('block_id', 'name')
array('item_id', 'name')
);
}
} else {
Expand Down Expand Up @@ -887,21 +897,21 @@ public static function setData($item = null)
$parameters = [];
foreach ($context['lp_block']['options']['parameters'] as $param_name => $value) {
$parameters[] = array(
'block_id' => $item,
'name' => $param_name,
'value' => $value
'item_id' => $item,
'name' => $param_name,
'value' => $value
);
}

$smcFunc['db_insert']('replace',
'{db_prefix}lp_block_params',
'{db_prefix}lp_params',
array(
'block_id' => 'int',
'name' => 'string',
'value' => 'string'
'item_id' => 'int',
'name' => 'string',
'value' => 'string'
),
$parameters,
array('block_id', 'name')
array('item_id', 'name')
);
}
}
Expand Down Expand Up @@ -931,9 +941,10 @@ public static function getData($item)
bt.lang, bt.title, bp.name, bp.value
FROM {db_prefix}lp_blocks AS b
LEFT JOIN {db_prefix}lp_block_titles AS bt ON (bt.block_id = b.block_id)
LEFT JOIN {db_prefix}lp_block_params AS bp ON (bp.block_id = b.block_id)
LEFT JOIN {db_prefix}lp_params AS bp ON (bp.item_id = b.block_id AND bp.type = {string:type})
WHERE b.block_id = {int:item}',
array(
'type' => 'block',
'item' => $item
)
);
Expand Down
22 changes: 11 additions & 11 deletions Sources/LightPortal/Helpers.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.7
* @version 0.8
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -63,18 +63,18 @@ public static function cleanBbcode($data)
return preg_replace('~\[[^]]+]~', '', $data);
}

/**
* Get a title for preview block
/** * Get a title for preview block
*
* Получаем заголовок блока превью
*
* @param string $prefix
* @return string
*/
public static function getPreviewTitle()
public static function getPreviewTitle($prefix = null)
{
global $context, $txt;

return self::getFloatSpan($context['preview_title'], $context['right_to_left'] ? 'right' : 'left') . self::getFloatSpan($txt['preview'], $context['right_to_left'] ? 'left' : 'right');
return self::getFloatSpan((!empty($prefix) ? $prefix . ' ' : '') . $context['preview_title'], $context['right_to_left'] ? 'right' : 'left') . self::getFloatSpan($txt['preview'], $context['right_to_left'] ? 'left' : 'right');
}

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ private static function getFloatSpan($text, $direction = 'left')
* @param array|string $str массив или строка с формами склонения (если в языке только одна форма склонения, см. rule #0)
* @return string
*/
public static function correctDeclension(int $num, $str)
public static function getCorrectDeclension(int $num, $str)
{
global $txt;

Expand Down Expand Up @@ -193,22 +193,22 @@ public static function getFriendlyTime(int $a)
$days = ($a - $time) / 60 / 60 / 24;

if ($days > 1)
return sprintf($txt['lp_remained'], self::correctDeclension((int) floor($days), $txt['lp_days_set']));
return sprintf($txt['lp_remained'], self::getCorrectDeclension((int) floor($days), $txt['lp_days_set']));

$minutes = ($a - $time) / 60 / 60;

if ($minutes > 1)
return sprintf($txt['lp_remained'], self::correctDeclension($minutes, $txt['lp_minutes_set']));
return sprintf($txt['lp_remained'], self::getCorrectDeclension($minutes, $txt['lp_minutes_set']));
else
return sprintf($txt['lp_remained'], self::correctDeclension($minutes * 60, $txt['lp_seconds_set']));
return sprintf($txt['lp_remained'], self::getCorrectDeclension($minutes * 60, $txt['lp_seconds_set']));
}

if ($last == 0)
return self::correctDeclension($sec, $txt['lp_seconds_set']) . $txt['lp_time_label_ago'];
return self::getCorrectDeclension($sec, $txt['lp_seconds_set']) . $txt['lp_time_label_ago'];
elseif ($last == 1)
return $smcFunc['ucfirst']($txt['lp_minutes_set'][0]) . $txt['lp_time_label_ago'];
elseif ($last < 55)
return self::correctDeclension((int) $last, $txt['lp_minutes_set']) . $txt['lp_time_label_ago'];
return self::getCorrectDeclension((int) $last, $txt['lp_minutes_set']) . $txt['lp_time_label_ago'];
elseif ($d.$m.$y == date('dmY', $time))
return $txt['today'] . $tm;
elseif ($d.$m.$y == date('dmY', strtotime('-1 day')))
Expand Down
4 changes: 2 additions & 2 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.7
* @version 0.8
*/

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

$lp_constants = [
'LP_VERSION' => '0.7',
'LP_VERSION' => '0.8',
'LP_NAME' => 'Light Portal',
'LP_ADDONS' => $sourcedir . '/LightPortal/addons'
];
Expand Down
Loading

0 comments on commit f898438

Please sign in to comment.