Skip to content

Commit

Permalink
Merge pull request #156 from dle-modules/5.1.4
Browse files Browse the repository at this point in the history
5.1.4
  • Loading branch information
pafnuty authored May 26, 2019
2 parents 816ecdd + e12bcd0 commit 5fcb7d5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.1.4
- Исправлена работа постраничной навигации при `catId=this` (#144)
- Исправлена логика отбора похожих новостей после релиза 5.1.2 (#155)

# 5.1.3
- Обновлен шаблонизатор Fenom до актуальной версии.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DLE-BlockPro — тот самый модуль для вывода новостей!
![version](https://img.shields.io/badge/version-5.1.3-red.svg?style=flat-square "Version")
![version](https://img.shields.io/badge/version-5.1.4-red.svg?style=flat-square "Version")
![DLE](https://img.shields.io/badge/DLE-10.x-green.svg?style=flat-square "DLE Version")
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/dle-modules/DLE-BlockPro/blob/master/LICENSE)

Expand Down
2 changes: 1 addition & 1 deletion blockpro_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Описание модуля, для установщика и админки.
'moduleDescr' => 'Модуль вывода новостей для DLE',
// Версия модуля, для установщика
'moduleVersion' => '5.1.3',
'moduleVersion' => '5.1.4',
// Дата выпуска модуля, для установщика
'moduleDate' => '17.05.2019',
// Версии DLE, поддержваемые модулем, для установщика
Expand Down
2 changes: 1 addition & 1 deletion engine/inc/blockpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
define('MODULE_DIR', ENGINE_DIR . '/modules/base/admin/blockpro/');

$moduleName = 'blockpro';
$moduleVersion = '5.1.3';
$moduleVersion = '5.1.4';

$moderate = $_REQUEST['moderate'];
$moderate_checked = ($moderate) ? 'checked' : '';
Expand Down
61 changes: 40 additions & 21 deletions engine/modules/base/blockpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,25 @@ classic: << Первая < 1 [2] 3 > Последняя >>
];
}

/**
* var array $bpConfig
*/
include ENGINE_DIR . '/data/blockpro.php';

// Объединяем массивы конфигов
/** @var array $bpConfig */
$cfg = array_merge($cfg, $bpConfig);

// Получаем id текущей категории при AJAX навигации
if ($isAjaxConfig && ($cfg['catId'] == 'this' || $cfg['notCatId'] == 'this')) {
/**
* @var string $thisUrl
* @see engine/ajax/blockpro.php
*/
if (substr($thisUrl, -1, 1) == '/') {
$thisUrl = substr($thisUrl, 0, -1);
}
$thisUrl = explode('/', $thisUrl);
$thisUrl = end($thisUrl);
if (trim($thisUrl) != '') {
$category_id = get_ID($cat_info, $thisUrl);
$arThisUrl = explode('/', $thisUrl);
$thisCatName = end($arThisUrl);
if (trim($thisCatName) != '') {
$category_id = get_ID($cat_info, $thisCatName);
}
}

Expand Down Expand Up @@ -259,6 +261,8 @@ classic: << Первая < 1 [2] 3 > Последняя >>
}

$cfg['cacheNameAddon'] = array_filter($cfg['cacheNameAddon']);
// Удаляем дублирующиеся значения кеша. Может возникать при AJAX вызове с &catId=this
$cfg['cacheNameAddon'] = array_unique($cfg['cacheNameAddon']);
$cfg['cacheNameAddon'] = implode('_', $cfg['cacheNameAddon']);

if ($cfg['cacheLive']) {
Expand All @@ -270,7 +274,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
// Проверим куку пользователя и наличие параметра skin в реквесте.
$currentSiteSkin = (isset($_COOKIE['dle_skin'])) ? trim(totranslit($_COOKIE['dle_skin'], false, false)) : ((isset($_REQUEST['skin'])) ? trim(totranslit($_REQUEST['skin'], false, false)) : $config['skin']);

// Если итоге пусто — назначим опять шаблон из конфига.
// Если итоге пусто — назначим опять шаблон из конфига.
if ($currentSiteSkin == '') {
$currentSiteSkin = $config['skin'];
}
Expand Down Expand Up @@ -533,16 +537,27 @@ classic: << Первая < 1 [2] 3 > Последняя >>

}

// Необходимо учитывать категорию для вывода похожих новостей, если категорию не задал пользователь.
// https://github.com/dle-modules/DLE-BlockPro/issues/155
if (!$base->cfg['catId'] && $base->cfg['related'] && $base->dle_config['related_only_cats']) {
$base->cfg['catId'] = 'this';
}

// Эти переменные потребуются ниже, что бы корректно сформировать имя кеша, когда переданы
// &catId=this или notCatId=this
$isCatIdThis = false;
$isNotCatIdThis = false;

// Фильтрация КАТЕГОРИЙ по их ID
if ($base->cfg['catId'] == 'this' && $category_id) {
$base->cfg['catIdT'] = 'this';
$isCatIdThis = true;
$base->cfg['catId'] = ($base->cfg['subcats']) ? get_sub_cats($category_id) : ($base->cfg['thisCatOnly']) ? (int)$category_id : $category_id;
}
if ($base->cfg['notCatId'] == 'this' && $category_id) {
$base->cfg['notCatIdT'] = 'this';
$isNotCatIdThis = true;
$base->cfg['notCatId'] = ($base->cfg['notSubcats']) ? get_sub_cats($category_id) : ($base->cfg['thisCatOnly']) ? (int)$category_id : $category_id;
}
// Дублирование кода вызвано необходимостью сочетания параметра notCatId b catId
// Дублирование кода вызвано необходимостью сочетания параметра notCatId и catId
// Например: catId=this&notCatId=3
if ($base->cfg['notCatId']) {
$notCatArr = $base->getDiapazone($base->cfg['notCatId'], $base->cfg['notSubcats']);
Expand Down Expand Up @@ -584,7 +599,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
$wheres[] = 'id NOT IN (' . $notPostsArr . ')';
}
}

if ($base->cfg['postId'] && $base->cfg['related'] == '') {
$postsArr = $base->getDiapazone($base->cfg['postId']);
if ($postsArr !== '0') {
Expand Down Expand Up @@ -766,11 +781,11 @@ classic: << Первая < 1 [2] 3 > Последняя >>
} else {

$relatedId = ($base->cfg['related'] == 'this') ? $_REQUEST['newsid'] : $base->cfg['related'];
$relatedRows = 'title, short_story, full_story, xfields';
$relatedRows = 'p.title, p.short_story, p.full_story, p.xfields';
$relatedIdParsed = $base->db->parse('id = ?i', $relatedId);

$relatedBody = $base->db->getRow('SELECT id, ?p FROM ?n p LEFT JOIN ?n e ON (p.id=e.news_id) WHERE ?p', 'p.title, p.short_story, p.full_story, p.xfields, e.related_ids', PREFIX . '_post', PREFIX . '_post_extras', $relatedIdParsed);
// Фикс https://github.com/pafnuty/BlockPro/issues/78
// Фикс https://github.com/dle-modules/DLE-BlockPro/issues/78
if ($relatedBody['id']) {
/** @var bool $saveRelated */
if ($relatedBody['related_ids'] && $saveRelated) {
Expand All @@ -783,17 +798,19 @@ classic: << Первая < 1 [2] 3 > Последняя >>
$reltedFirstShow = true;
$bodyToRelated = (dle_strlen($relatedBody['full_story'], $base->dle_config['charset']) < dle_strlen($relatedBody['short_story'], $base->dle_config['charset'])) ? $relatedBody['short_story'] : $relatedBody['full_story'];

$bodyToRelated = strip_tags(stripslashes($relatedBody['title'] . ' ' . $bodyToRelated));

// Фикс для https://github.com/pafnuty/BlockPro/issues/79
// @see /engine/modules/show.full.php
if (dle_strlen($bodyToRelated, $base->dle_config['charset']) > 1000) {
$bodyToRelated = dle_substr($bodyToRelated, 0, 1000, $base->dle_config['charset']);
}

$bodyToRelated = $base->db->parse('?s', strip_tags($relatedBody['title'] . ' ' . $bodyToRelated));
$bodyToRelated = $base->db->parse('?s', $bodyToRelated);

// Добавляем улучшенный алгоритм поиска похожих новостей из DLE 13
$ext_query_fields .= ', MATCH (p.title, p.short_story, p.full_story, p.xfields) AGAINST (' . $bodyToRelated . ') as score';
$orderArr = ['score'];
$orderArr = ['score DESC'];

// Формируем условие выборки
$wheres[] = 'MATCH (' . $relatedRows . ') AGAINST (' . $bodyToRelated . ') AND id !=' . $relatedBody['id'];
Expand Down Expand Up @@ -1039,13 +1056,13 @@ classic: << Первая < 1 [2] 3 > Последняя >>
$tplArr['totalCount'] = $totalCount;

// Меняем для кеша id категории на this если параметр catId или notCatId равен this
if ($base->cfg['catIdT'] == 'this') {
$base->cfg['catId'] = $base->cfg['catIdT'];
if ($isCatIdThis) {
$base->cfg['catId'] = 'this';
}
if ($base->cfg['notCatIdT'] == 'this') {
$base->cfg['notCatId'] = $base->cfg['notCatIdT'];
if ($isNotCatIdThis) {
$base->cfg['notCatId'] = 'this';
}

// Формируем имя кеш-файла с конфигом
$pageCacheName = $base->cfg;
// Удаляем номер страницы для того, что бы не создавался новый кеш для каждого блока постранички
Expand Down Expand Up @@ -1140,6 +1157,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>

unset($stat);
}

// Создаём кеш, если требуется
if (!$base->cfg['nocache']) {
create_cache($base->cfg['cachePrefix'], $output, $cacheName, $cacheSuffix);
Expand All @@ -1152,6 +1170,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
/** @var $base */
if ($base->dle_config['files_allow']) {
if (strpos($output, '[attachment=') !== false) {
/** @var array $attachments */
$output = show_attach($output, $attachments);
}
} else {
Expand Down

0 comments on commit 5fcb7d5

Please sign in to comment.