Skip to content

Commit 5fcb7d5

Browse files
authored
Merge pull request #156 from dle-modules/5.1.4
5.1.4
2 parents 816ecdd + e12bcd0 commit 5fcb7d5

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 5.1.4
2+
- Исправлена работа постраничной навигации при `catId=this` (#144)
3+
- Исправлена логика отбора похожих новостей после релиза 5.1.2 (#155)
4+
15
# 5.1.3
26
- Обновлен шаблонизатор Fenom до актуальной версии.
37

README.md

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

blockpro_install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Описание модуля, для установщика и админки.
1616
'moduleDescr' => 'Модуль вывода новостей для DLE',
1717
// Версия модуля, для установщика
18-
'moduleVersion' => '5.1.3',
18+
'moduleVersion' => '5.1.4',
1919
// Дата выпуска модуля, для установщика
2020
'moduleDate' => '17.05.2019',
2121
// Версии DLE, поддержваемые модулем, для установщика

engine/inc/blockpro.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
define('MODULE_DIR', ENGINE_DIR . '/modules/base/admin/blockpro/');
3030

3131
$moduleName = 'blockpro';
32-
$moduleVersion = '5.1.3';
32+
$moduleVersion = '5.1.4';
3333

3434
$moderate = $_REQUEST['moderate'];
3535
$moderate_checked = ($moderate) ? 'checked' : '';

engine/modules/base/blockpro.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,25 @@ classic: << Первая < 1 [2] 3 > Последняя >>
168168
];
169169
}
170170

171-
/**
172-
* var array $bpConfig
173-
*/
174171
include ENGINE_DIR . '/data/blockpro.php';
175172

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

179177
// Получаем id текущей категории при AJAX навигации
180178
if ($isAjaxConfig && ($cfg['catId'] == 'this' || $cfg['notCatId'] == 'this')) {
179+
/**
180+
* @var string $thisUrl
181+
* @see engine/ajax/blockpro.php
182+
*/
181183
if (substr($thisUrl, -1, 1) == '/') {
182184
$thisUrl = substr($thisUrl, 0, -1);
183185
}
184-
$thisUrl = explode('/', $thisUrl);
185-
$thisUrl = end($thisUrl);
186-
if (trim($thisUrl) != '') {
187-
$category_id = get_ID($cat_info, $thisUrl);
186+
$arThisUrl = explode('/', $thisUrl);
187+
$thisCatName = end($arThisUrl);
188+
if (trim($thisCatName) != '') {
189+
$category_id = get_ID($cat_info, $thisCatName);
188190
}
189191
}
190192

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

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

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

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

534538
}
535539

540+
// Необходимо учитывать категорию для вывода похожих новостей, если категорию не задал пользователь.
541+
// https://github.com/dle-modules/DLE-BlockPro/issues/155
542+
if (!$base->cfg['catId'] && $base->cfg['related'] && $base->dle_config['related_only_cats']) {
543+
$base->cfg['catId'] = 'this';
544+
}
545+
546+
// Эти переменные потребуются ниже, что бы корректно сформировать имя кеша, когда переданы
547+
// &catId=this или notCatId=this
548+
$isCatIdThis = false;
549+
$isNotCatIdThis = false;
550+
536551
// Фильтрация КАТЕГОРИЙ по их ID
537552
if ($base->cfg['catId'] == 'this' && $category_id) {
538-
$base->cfg['catIdT'] = 'this';
553+
$isCatIdThis = true;
539554
$base->cfg['catId'] = ($base->cfg['subcats']) ? get_sub_cats($category_id) : ($base->cfg['thisCatOnly']) ? (int)$category_id : $category_id;
540555
}
541556
if ($base->cfg['notCatId'] == 'this' && $category_id) {
542-
$base->cfg['notCatIdT'] = 'this';
557+
$isNotCatIdThis = true;
543558
$base->cfg['notCatId'] = ($base->cfg['notSubcats']) ? get_sub_cats($category_id) : ($base->cfg['thisCatOnly']) ? (int)$category_id : $category_id;
544559
}
545-
// Дублирование кода вызвано необходимостью сочетания параметра notCatId b catId
560+
// Дублирование кода вызвано необходимостью сочетания параметра notCatId и catId
546561
// Например: catId=this&notCatId=3
547562
if ($base->cfg['notCatId']) {
548563
$notCatArr = $base->getDiapazone($base->cfg['notCatId'], $base->cfg['notSubcats']);
@@ -584,7 +599,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
584599
$wheres[] = 'id NOT IN (' . $notPostsArr . ')';
585600
}
586601
}
587-
602+
588603
if ($base->cfg['postId'] && $base->cfg['related'] == '') {
589604
$postsArr = $base->getDiapazone($base->cfg['postId']);
590605
if ($postsArr !== '0') {
@@ -766,11 +781,11 @@ classic: << Первая < 1 [2] 3 > Последняя >>
766781
} else {
767782

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

772787
$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);
773-
// Фикс https://github.com/pafnuty/BlockPro/issues/78
788+
// Фикс https://github.com/dle-modules/DLE-BlockPro/issues/78
774789
if ($relatedBody['id']) {
775790
/** @var bool $saveRelated */
776791
if ($relatedBody['related_ids'] && $saveRelated) {
@@ -783,17 +798,19 @@ classic: << Первая < 1 [2] 3 > Последняя >>
783798
$reltedFirstShow = true;
784799
$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'];
785800

801+
$bodyToRelated = strip_tags(stripslashes($relatedBody['title'] . ' ' . $bodyToRelated));
802+
786803
// Фикс для https://github.com/pafnuty/BlockPro/issues/79
787804
// @see /engine/modules/show.full.php
788805
if (dle_strlen($bodyToRelated, $base->dle_config['charset']) > 1000) {
789806
$bodyToRelated = dle_substr($bodyToRelated, 0, 1000, $base->dle_config['charset']);
790807
}
791808

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

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

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

10411058
// Меняем для кеша id категории на this если параметр catId или notCatId равен this
1042-
if ($base->cfg['catIdT'] == 'this') {
1043-
$base->cfg['catId'] = $base->cfg['catIdT'];
1059+
if ($isCatIdThis) {
1060+
$base->cfg['catId'] = 'this';
10441061
}
1045-
if ($base->cfg['notCatIdT'] == 'this') {
1046-
$base->cfg['notCatId'] = $base->cfg['notCatIdT'];
1062+
if ($isNotCatIdThis) {
1063+
$base->cfg['notCatId'] = 'this';
10471064
}
1048-
1065+
10491066
// Формируем имя кеш-файла с конфигом
10501067
$pageCacheName = $base->cfg;
10511068
// Удаляем номер страницы для того, что бы не создавался новый кеш для каждого блока постранички
@@ -1140,6 +1157,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
11401157

11411158
unset($stat);
11421159
}
1160+
11431161
// Создаём кеш, если требуется
11441162
if (!$base->cfg['nocache']) {
11451163
create_cache($base->cfg['cachePrefix'], $output, $cacheName, $cacheSuffix);
@@ -1152,6 +1170,7 @@ classic: << Первая < 1 [2] 3 > Последняя >>
11521170
/** @var $base */
11531171
if ($base->dle_config['files_allow']) {
11541172
if (strpos($output, '[attachment=') !== false) {
1173+
/** @var array $attachments */
11551174
$output = show_attach($output, $attachments);
11561175
}
11571176
} else {

0 commit comments

Comments
 (0)