Improve rendering of meta search content (#7193)

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2024-08-30 13:48:00 +03:00 committed by GitHub
parent 5752d62c72
commit 960a58e50e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -25,6 +25,7 @@ HumHub Changelog
- Fix #7182: Fix initialization of several select2 inputs on the same page
- Fix #7187: Fix search reindexing after content deletion
- Fix #7152: Fix search starting with special characters
- Enh #7148: Improve rendering of meta search content
- Fix #7192: Deny deleting user from single group
1.16.1 (July 1, 2024)

View File

@ -10,7 +10,7 @@ namespace humhub\modules\content\search;
use humhub\interfaces\MetaSearchResultInterface;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\content\models\Content;
use humhub\modules\content\widgets\richtext\RichText;
use humhub\modules\content\widgets\richtext\converter\RichTextToHtmlConverter;
use humhub\modules\ui\icon\widgets\Icon;
use humhub\modules\user\models\User;
use Yii;
@ -46,7 +46,20 @@ class SearchRecord implements MetaSearchResultInterface
*/
public function getTitle(): string
{
return RichText::output($this->content->getContentDescription(), ['record' => $this->content->getModel()]);
$title = RichTextToHtmlConverter::process($this->content->getContentDescription());
$title = str_replace(["\r", "\n"], ' ', strip_tags($title));
// Cut text to first word contained the searched keyword
$keywordIndex = strpos($title, $this->keyword);
if ($keywordIndex) {
do {
$keywordIndex--;
$titlePart = substr($title, $keywordIndex);
} while ($keywordIndex && $titlePart[0] !== ' ');
$title = '...' . trim($titlePart);
}
return $title;
}
/**