Skip to content

Commit

Permalink
Merge pull request #21 from dragomano/develop
Browse files Browse the repository at this point in the history
Update to 1.5
  • Loading branch information
dragomano authored Jan 1, 2021
2 parents a2454e8 + a904b2a commit 371e3c5
Show file tree
Hide file tree
Showing 145 changed files with 4,814 additions and 3,078 deletions.
4 changes: 2 additions & 2 deletions Sources/LightPortal/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* @package Light Portal
* @link https://dragomano.ru/mods/light-portal
* @author Bugo <bugo@dragomano.ru>
* @copyright 2019-2020 Bugo
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.4
* @version 1.5
*/

if (!defined('SMF'))
Expand Down
37 changes: 28 additions & 9 deletions Sources/LightPortal/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* @package Light Portal
* @link https://dragomano.ru/mods/light-portal
* @author Bugo <bugo@dragomano.ru>
* @copyright 2019-2020 Bugo
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.4
* @version 1.5
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -51,6 +51,7 @@ public function prepare()
return;

$context['lp_allowed_bbc'] = !empty($modSettings['lp_enabled_bbc_in_comments']) ? explode(',', $modSettings['lp_enabled_bbc_in_comments']) : [];
$context['lp_allowed_bbc'] = array_diff($context['lp_allowed_bbc'], array_intersect(explode(',', $modSettings['disabledBBC']), $context['lp_allowed_bbc']));

if (Helpers::request()->filled('sa')) {
switch (Helpers::request('sa')) {
Expand Down Expand Up @@ -89,7 +90,7 @@ function ($comment) {
$total_comments = sizeof($comment_tree);

$page_index_url = $context['canonical_url'];
if (!empty($modSettings['lp_frontpage_mode']) && $modSettings['lp_frontpage_mode'] == 1 && !empty($modSettings['lp_frontpage_alias']))
if (!empty($modSettings['lp_frontpage_mode']) && $modSettings['lp_frontpage_mode'] == 'chosen_page' && !empty($modSettings['lp_frontpage_alias']))
$page_index_url = $scripturl . '?action=portal';

$temp_start = Helpers::request('start');
Expand Down Expand Up @@ -119,7 +120,7 @@ function ($comment) {
*/
private function add()
{
global $smcFunc, $user_info, $context, $txt;
global $smcFunc, $sourcedir, $user_info, $context, $txt;

$args = array(
'parent_id' => FILTER_VALIDATE_INT,
Expand Down Expand Up @@ -151,6 +152,9 @@ private function add()
if (empty($page_id) || empty($message))
return;

require_once($sourcedir . '/Subs-Post.php');
preparsecode($message);

$item = $smcFunc['db_insert']('',
'{db_prefix}lp_comments',
array(
Expand Down Expand Up @@ -201,7 +205,7 @@ private function add()
'message' => empty($context['lp_allowed_bbc']) ? $message : parse_bbc($message, true, 'light_portal_comments_' . $item, $context['lp_allowed_bbc']),
'created_at' => date('Y-m-d', $time),
'created' => Helpers::getFriendlyTime($time),
'raw_message' => $message,
'raw_message' => un_preparsecode($message),
'can_edit' => true
], $counter + 1, $level + 1);

Expand Down Expand Up @@ -238,7 +242,7 @@ private function add()
*/
private function edit()
{
global $smcFunc, $context;
global $sourcedir, $smcFunc, $context;

$data = Helpers::request()->json();

Expand All @@ -251,6 +255,9 @@ private function edit()
if (empty($item) || empty($message))
return;

require_once($sourcedir . '/Subs-Post.php');
preparsecode($message);

$smcFunc['db_query']('', '
UPDATE {db_prefix}lp_comments
SET message = {string:message}
Expand Down Expand Up @@ -375,7 +382,17 @@ private function remove()
)
);

$smcFunc['lp_num_queries'] += 2;
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}user_alerts
WHERE content_type = {string:type}
AND content_id IN ({array_int:items})',
array(
'type' => 'new_comment',
'items' => $items
)
);

$smcFunc['lp_num_queries'] += 3;

Helpers::cache()->forget('page_' . $this->alias . '_comments');

Expand All @@ -392,11 +409,13 @@ private function remove()
*/
public function getAll(int $page_id = 0)
{
global $smcFunc, $context, $modSettings;
global $sourcedir, $smcFunc, $context, $modSettings;

if (empty($page_id))
return [];

require_once($sourcedir . '/Subs-Post.php');

$request = $smcFunc['db_query']('', '
SELECT com.id, com.parent_id, com.page_id, com.author_id, com.message, com.created_at, mem.real_name AS author_name
FROM {db_prefix}lp_comments AS com
Expand All @@ -421,7 +440,7 @@ public function getAll(int $page_id = 0)
'author_name' => $row['author_name'],
'avatar' => $avatar,
'message' => empty($context['lp_allowed_bbc']) ? $row['message'] : parse_bbc($row['message'], true, 'light_portal_comments_' . $page_id, $context['lp_allowed_bbc']),
'raw_message' => $row['message'],
'raw_message' => un_preparsecode($row['message']),
'created_at' => $row['created_at'],
'can_edit' => !empty($modSettings['lp_time_to_change_comments']) ? (time() - $row['created_at'] <= (int) $modSettings['lp_time_to_change_comments'] * 60) : false
);
Expand Down
8 changes: 4 additions & 4 deletions Sources/LightPortal/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* @package Light Portal
* @link https://dragomano.ru/mods/light-portal
* @author Bugo <bugo@dragomano.ru>
* @copyright 2019-2020 Bugo
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.4
* @version 1.5
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -56,7 +56,7 @@ public function getCopyrights()
{
global $scripturl;

return '<a href="https://dragomano.ru/mods/light-portal" target="_blank" rel="noopener" title="' . LP_VERSION . '">' . LP_NAME . '</a> | &copy; <a href="' . $scripturl . '?action=credits;sa=light_portal">2019&ndash;2020</a>, Bugo | Licensed under the <a href="https://github.com/dragomano/Light-Portal/blob/master/LICENSE" target="_blank" rel="noopener">GNU GPLv3</a> License';
return '<a href="https://dragomano.ru/mods/light-portal" target="_blank" rel="noopener" title="' . LP_VERSION . '">' . LP_NAME . '</a> | &copy; <a href="' . $scripturl . '?action=credits;sa=light_portal">2019&ndash;2021</a>, Bugo | Licensed under the <a href="https://github.com/dragomano/Light-Portal/blob/master/LICENSE" target="_blank" rel="noopener">GNU GPLv3</a> License';
}

/**
Expand Down Expand Up @@ -126,7 +126,7 @@ public function getComponentList()
)
);

// Adding copyrights of used plugins | Возможность добавить копирайты используемых плагинов
// Adding copyrights of used plugins
Subs::runAddons('credits', array(&$links));

$context['lp_components'] = $links;
Expand Down
74 changes: 54 additions & 20 deletions Sources/LightPortal/FrontPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

namespace Bugo\LightPortal;

use Bugo\LightPortal\Front\ArticleInterface;
use Bugo\LightPortal\Front\BoardArticle;
use Bugo\LightPortal\Front\TopicArticle;
use Bugo\LightPortal\Front\PageArticle;
use Bugo\LightPortal\Front\AbstractArticle;

/**
* FrontPage.php
*
* @package Light Portal
* @link https://dragomano.ru/mods/light-portal
* @author Bugo <bugo@dragomano.ru>
* @copyright 2019-2020 Bugo
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.4
* @version 1.5
*/

class FrontPage
Expand All @@ -37,23 +34,33 @@ public function show()
$context['lp_need_lower_case'] = $this->isLowerCaseForDates();

switch ($modSettings['lp_frontpage_mode']) {
case 1:
call_user_func(array(new Page, 'show'));
break;
case 'chosen_page':
return call_user_func(array(new Page, 'show'));

case 2:
$this->prepare(new TopicArticle);
case 'all_topics':
$this->prepare('TopicArticle');
$context['sub_template'] = 'show_topics_as_articles';
break;

case 3:
$this->prepare(new PageArticle);
case 'all_pages':
$this->prepare('PageArticle');
$context['sub_template'] = 'show_pages_as_articles';
break;

default:
$this->prepare(new BoardArticle);
case 'chosen_boards':
$this->prepare('BoardArticle');
$context['sub_template'] = 'show_boards_as_articles';
break;

case 'chosen_topics':
$this->prepare('ChosenTopicArticle');
$context['sub_template'] = 'show_topics_as_articles';
break;

case 'chosen_pages':
default:
$this->prepare('ChosenPageArticle');
$context['sub_template'] = 'show_pages_as_articles';
}

Subs::runAddons('frontCustomTemplate');
Expand All @@ -76,17 +83,29 @@ public function show()
*
* Формируем массив статей
*
* @param ArticleInterface $entity
* @param string $entity
* @return void
*/
public function prepare(ArticleInterface $entity)
public function prepare(string $entity = '')
{
global $modSettings, $context, $scripturl;

$classname = '\Bugo\LightPortal\Front\\' . $entity;

if (!class_exists($classname))
return;

$entity = AbstractArticle::load($classname);

if (!$entity instanceof AbstractArticle)
return;

$start = Helpers::request('start');
$limit = $modSettings['lp_num_items_per_page'] ?? 12;

$total_items = $entity->getTotal();
$entity->init();

$total_items = $entity->getTotalCount();

if ($start >= $total_items) {
send_http_status(404);
Expand All @@ -96,10 +115,23 @@ public function prepare(ArticleInterface $entity)

$articles = $entity->getData($start, $limit);

$articles = array_map(function ($article) use ($modSettings) {
// Post processing for articles
$articles = array_map(function ($article) use ($context, $modSettings) {
if ($context['user']['is_guest'])
$article['is_new'] = false;

if (!empty($article['date'])) {
$article['datetime'] = date('Y-m-d', $article['date']);
$article['date'] = Helpers::getFriendlyTime($article['date']);

if (!empty($modSettings['lp_frontpage_time_format'])) {
if ($modSettings['lp_frontpage_time_format'] == 1) {
$article['date'] = timeformat($article['date'], true);
} else {
$article['date'] = date($modSettings['lp_frontpage_custom_time_format'] ?? 'F j, Y', $article['date']);
}
} else {
$article['date'] = Helpers::getFriendlyTime($article['date']);
}
}

if (isset($article['title']))
Expand All @@ -117,6 +149,8 @@ public function prepare(ArticleInterface $entity)
$context['page_index'] = constructPageIndex($scripturl . '?action=portal', Helpers::request()->get('start'), $total_items, $limit);
$context['start'] = Helpers::request()->get('start');

$context['portal_next_page'] = Helpers::request('start') + $limit < $total_items ? $scripturl . '?action=portal;start=' . (Helpers::request('start') + $limit) : '';

$context['lp_frontpage_articles'] = $articles;

Subs::runAddons('frontAssets');
Expand Down
45 changes: 40 additions & 5 deletions Sources/LightPortal/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @package Light Portal
* @link https://dragomano.ru/mods/light-portal
* @author Bugo <bugo@dragomano.ru>
* @copyright 2019-2020 Bugo
* @copyright 2019-2021 Bugo
* @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
*
* @version 1.4
* @version 1.5
*/

if (!defined('SMF'))
Expand Down Expand Up @@ -270,7 +270,7 @@ public static function getFriendlyTime(int $timestamp, bool $use_user_offset = f

$current_time = time();

$tm = date('H:i', $timestamp);
$tm = date('H:i', $timestamp); // Use 'g:i a' for am/pm
$d = date('j', $timestamp);
$m = date('m', $timestamp);
$y = date('Y', $timestamp);
Expand Down Expand Up @@ -490,7 +490,7 @@ public static function isFrontpage(string $alias)
return false;

return !empty($modSettings['lp_frontpage_mode'])
&& $modSettings['lp_frontpage_mode'] == 1
&& $modSettings['lp_frontpage_mode'] == 'chosen_page'
&& !empty($modSettings['lp_frontpage_alias'])
&& $modSettings['lp_frontpage_alias'] == $alias;
}
Expand Down Expand Up @@ -659,7 +659,7 @@ public static function parseContent(string &$content, string $type = 'bbc')
ob_start();

try {
$content = html_entity_decode($content, ENT_COMPAT, $context['character_set'] ?? 'UTF-8');
$content = html_entity_decode($content, ENT_COMPAT, 'UTF-8');

eval($content);
} catch (\ParseError $p) {
Expand Down Expand Up @@ -778,4 +778,39 @@ public static function getAllTitles(string $type = 'page')

return $titles;
}

/**
* Get the total number of active pages
*
* Подсчитываем общее количество активных страниц
*
* @param bool $all - подсчитывать все страницы
* @return int
*/
public static function getNumActivePages($all = false)
{
global $user_info, $smcFunc;

if (($num_pages = self::cache()->get('num_active_pages' . ($all ? '' : ('_u' . $user_info['id'])), LP_CACHE_TIME)) === null) {
$request = $smcFunc['db_query']('', '
SELECT COUNT(page_id)
FROM {db_prefix}lp_pages
WHERE status = {int:status}' . ($user_info['is_admin'] || $all ? '' : '
AND author_id = {int:user_id}'),
array(
'status' => Page::STATUS_ACTIVE,
'user_id' => $user_info['id']
)
);

[$num_pages] = $smcFunc['db_fetch_row']($request);

$smcFunc['db_free_result']($request);
$smcFunc['lp_num_queries']++;

self::cache()->put('num_active_pages' . ($all ? '' : ('_u' . $user_info['id'])), $num_pages, LP_CACHE_TIME);
}

return (int) $num_pages;
}
}
Loading

0 comments on commit 371e3c5

Please sign in to comment.