@@ -168,23 +168,25 @@ classic: << Первая < 1 [2] 3 > Последняя >>
168168 ];
169169}
170170
171- /**
172- * var array $bpConfig
173- */
174171include ENGINE_DIR . '/data/blockpro.php ' ;
175172
176173// Объединяем массивы конфигов
174+ /** @var array $bpConfig */
177175$ cfg = array_merge ($ cfg , $ bpConfig );
178176
179177// Получаем id текущей категории при AJAX навигации
180178if ($ 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
264268if ($ 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+ // Если итоге пусто — назначим опять шаблон из конфига.
274278if ($ 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¬CatId=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 */
11531171if ($ 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