Exception Posted June 17, 2021 Report Share Posted June 17, 2021 какая функция удаляет например ipsSpoiler из контента на страницах профиля, поиска и т.д.? Либо я туплю, но функция public static function removeElements в IPS\Text\Parser ничего не удаляет Quote Link to comment Share on other sites More sharing options...
Respected Posted June 17, 2021 Report Share Posted June 17, 2021 Движок указанной функцией обрезает теги, например здесь system/Content/Search/Index /* Strip spoilers */ $content = $object->searchIndexContent(); if ( preg_match( '#<div\s+?class=["\']ipsSpoiler["\']#', $content ) ) { $content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) ); } /* Take the HTML out of the content */ $content = trim( str_replace( \chr(0xC2) . \chr(0xA0), ' ', strip_tags( preg_replace( "/(<br(?: \/)?>|<\/p>)/i", ' ', preg_replace( "#<blockquote(?:[^>]+?)>.+?(?<!<blockquote)</blockquote>#s", " ", preg_replace( "#<script(.*?)>(.*)</script>#uis", "", ' ' . $content . ' ' ) ) ) ) ) ); Quote Link to comment Share on other sites More sharing options...
Exception Posted June 17, 2021 Author Report Share Posted June 17, 2021 3 минуты назад, Respected сказал: Движок указанной функцией обрезает теги, например здесь system/Content/Search/Index /* Strip spoilers */ $content = $object->searchIndexContent(); if ( preg_match( '#<div\s+?class=["\']ipsSpoiler["\']#', $content ) ) { $content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) ); } /* Take the HTML out of the content */ $content = trim( str_replace( \chr(0xC2) . \chr(0xA0), ' ', strip_tags( preg_replace( "/(<br(?: \/)?>|<\/p>)/i", ' ', preg_replace( "#<blockquote(?:[^>]+?)>.+?(?<!<blockquote)</blockquote>#s", " ", preg_replace( "#<script(.*?)>(.*)</script>#uis", "", ' ' . $content . ' ' ) ) ) ) ) ); тогда какой он удаляет то, что находится в ipsSpoiler ? Quote Link to comment Share on other sites More sharing options...
Respected Posted June 17, 2021 Report Share Posted June 17, 2021 Так этой строкой и удаляет $content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) ); Quote Link to comment Share on other sites More sharing options...
Exception Posted June 18, 2021 Author Report Share Posted June 18, 2021 3 часа назад, Respected сказал: Так этой строкой и удаляет $content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) ); что-то у меня локальный сервер развалился, контент не обновлялся и хук не срабатывал, а так все работает правильно. Quote Link to comment Share on other sites More sharing options...
Exception Posted June 25, 2021 Author Report Share Posted June 25, 2021 /** * Remove specific elements, useful for cleaning up content for display or truncating * * @param string $value The value to parse * @param array|string $elements Element to remove, or array of elements to remove. Can be in format "element[attribute=value]" * @return string */ public static function removeElements( $value, $elements=array( 'blockquote', 'img', 'a' ) ) { array_push($elements, 'div[class=my_spoiler]'); return parent::removeElements( $value, $elements ); } я попробовал добавить элемент глобально, он удаляет его в приложении страниц (главная страница со списком статей), но не удаляет в профиле, страниц с результатами поиска и т.д. Quote Link to comment Share on other sites More sharing options...
Exception Posted June 25, 2021 Author Report Share Posted June 25, 2021 Через truncated тоже удаляет только в приложении страниц /** * Removes HTML and optionally truncates content * * @param bool $oneLine If TRUE, will use spaces instead of line breaks. Useful if using a single line display. * @param int|null $length If supplied, and $oneLine is set to TRUE, the returned content will be truncated to this length * @return string * @note For now we are removing all HTML. If we decide to change this to remove specific tags in future, we can use \IPS\Text\Parser::removeElements( $this->content() ) */ static public function truncate( $content, $oneLine=false, $length=500 ) { $content = static::removeElements( $content, array( 'div[class=my_spoiler]' ) ); return parent::truncate( $content, $oneLine, $length ); } у меня уже мозг плавится, не понимаю как удалить в профиле и т.д. Quote Link to comment Share on other sites More sharing options...
Exception Posted June 27, 2021 Author Report Share Posted June 27, 2021 я так понял это делается через public function indexData( \IPS\Content\Searchable $object ) в IPS\Content\Search\Index как правильно захукать код, чтобы добавить в него \IPS\Text\Parser::removeElements( $content, array( 'div[class=my_spoiler]' ) ); ? Quote Link to comment Share on other sites More sharing options...
WaNted Posted June 28, 2021 Report Share Posted June 28, 2021 Глянь \IPS\Content\Search\Result::preDisplay Quote Link to comment Share on other sites More sharing options...
Exception Posted June 28, 2021 Author Report Share Posted June 28, 2021 7 часов назад, WaNted сказал: Глянь \IPS\Content\Search\Result::preDisplay там вроде везде уже отформатированный текст выводит. Я нашел обходной путь, так как в public function indexData() вызывается searchIndexContent(), я просто в IPS\Content в эту функцию запилил \IPS\Text\Parser::removeElements( $content, array( 'div[class=my_spoiler]' ) ); Quote Link to comment Share on other sites More sharing options...
Exception Posted July 1, 2021 Author Report Share Posted July 1, 2021 Не нашел рабочего хайда под новую версию ips, пришлось писать самому. Как вам идея хайда под ранг пользователя? Так как ранг пользователя гибок к настройкам, а пользователь сам решает какими путями его получить, думаю это самый топ вариант. WaNted and andros0789 2 Quote Link to comment Share on other sites More sharing options...
Dobrochas Posted September 14, 2021 Report Share Posted September 14, 2021 ZIKURIK отличная идея. А есть уже рабочая версия? Quote Link to comment Share on other sites More sharing options...
Exception Posted September 14, 2021 Author Report Share Posted September 14, 2021 38 минут назад, Dobrochas сказал: ZIKURIK отличная идея. А есть уже рабочая версия? Работает на одном из моих проектов который я запущу скорее всего на неделе. А так в паблике если и будет то будет платная версия Еще реализовал чью-то идею, кто-то хотел спойлер с редактируемым заголовком. Второй спойлер кастомный: BlackShot 1 Quote Link to comment Share on other sites More sharing options...
Dobrochas Posted October 2, 2021 Report Share Posted October 2, 2021 @ZIKURIK спойлер тоже будет платный? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.