/** * Удаляет из строки все теги, используется как аналог strip_tags там, * где последний удаляет часть текста вместе с не валидными тегами, например * при обработке строки ">>> Hello <<<". Подробнее в задаче #151 * {@see https://github.com/altocms/altocms/issues/151} * * @param $sText * @param null $aError * @return string */ public function RemoveAllTags($sText, &$aError = null) { /** @var ITextParser $oTextParser */ $oTextParser = ModuleText::newTextParser(); return htmlspecialchars_decode($oTextParser->parse($sText, $aError)); }
/** * Поиск комментариев * */ function EventComments() { // * Ищем $aReq = $this->PrepareRequest(); $aRes = $this->PrepareResults($aReq, Config::Get('module.comment.per_page')); if (false === $aRes) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error')); return Router::Action('error'); } // * Если поиск дал результаты if ($this->bIsResults) { // * Получаем топик-объекты по списку идентификаторов $aComments = E::ModuleComment()->GetCommentsAdditionalData(array_keys($this->aSphinxRes['matches'])); // * Конфигурируем парсер $oTextParser = ModuleText::newTextParser('search'); $aErrors = array(); // * Делаем сниппеты /** @var ModuleComment_EntityComment $oComment */ foreach ($aComments as $oComment) { $oComment->setText($oTextParser->parse(E::ModuleSphinx()->GetSnippet(htmlspecialchars($oComment->getText()), 'comments', $aReq['q'], '<span class="searched-item">', '</span>'), $aErrors)); } /** * Отправляем данные в шаблон */ E::ModuleViewer()->Assign('aRes', $aRes); E::ModuleViewer()->Assign('aComments', $aComments); } }
/** * Инициализация */ public function Init() { $this->SetDefaultEvent('index'); $this->sModeOutList = C::Get('module.search.out_mode'); $this->nSnippetLength = C::Get('module.search.snippet.length'); $this->nSnippetMaxLength = C::Get('module.search.snippet.max_length'); if ($this->nSnippetMaxLength > 0 && $this->nSnippetMaxLength < $this->nSnippetLength) { $this->nSnippetMaxLength = $this->nSnippetLength; } $this->sSnippetBeforeMatch = C::Get('module.search.snippet.before_match'); $this->sSnippetAfterMatch = C::Get('module.search.snippet.after_match'); $this->sSnippetBeforeFragment = C::Get('module.search.snippet.before_fragment'); $this->sSnippetAfterFragment = C::Get('module.search.snippet.after_fragment'); $this->nSnippetMaxFragments = C::Get('module.search.snippet.max_fragments'); $this->sPatternW = C::Get('module.search.char_pattern'); $this->sPatternB = '[^' . mb_substr($this->sPatternW, 1); // '[^\wа-яА-Я\.\*-]'; // граница слова $this->sPatternX = '[^\\s' . mb_substr($this->sPatternW, 1); // '[^\s\wа-яА-Я\*-]'; // запрещеные символы без * $this->sPatternXA = '[^\\s\\*' . mb_substr($this->sPatternW, 1); // '[^\s\wа-яА-Я-]'; // запрещеные символы, в т.ч. * $this->sPatternUrl = "([a-z]+\\:\\/\\/)?"; // SCHEME $this->sPatternUrl .= "([a-z0-9+!*(),;?&=\$_.-]+(\\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass $this->sPatternUrl .= "([a-z0-9-.]*)\\.([a-z]{2,4})"; // Host or IP $this->sPatternUrl .= "(\\:[0-9]{2,5})?"; // Port $this->sPatternUrl .= "(\\/([a-z0-9+\$_-]\\.?)+)*\\/?"; // Path $this->sPatternUrl .= "(\\?[a-z+&\$_.-][a-z0-9;:@&%=+\\/\$_.-]*)?"; // GET Query $this->sPatternUrl .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor $this->bSearchStrict = C::Get('module.search.strict_search'); $this->bSkipAllTags = C::Get('module.search.skip_all_tags'); $this->iItemsPerPage = C::Get('module.search.items_per_page'); mb_internal_encoding('UTF-8'); $this->oTextParser = ModuleText::newTextParser(); // Разрешённые теги if ($this->sModeOutList === 'snippet') { $this->oTextParser->cfgAllowTags(array('a', 'img', 'object', 'param', 'embed')); } else { $this->oTextParser->cfgAllowTags(array('a', 'img', 'object', 'param', 'embed')); } // Коротие теги типа $this->oTextParser->cfgSetTagShort(array('img')); // Разрешённые параметры тегов $this->oTextParser->cfgAllowTagParams('img', array('src', 'alt' => '#text', 'title', 'align' => array('right', 'left', 'center'), 'width' => '#int', 'height' => '#int', 'hspace' => '#int', 'vspace' => '#int')); $this->oTextParser->cfgAllowTagParams('a', array('title', 'href', 'rel')); $this->oTextParser->cfgAllowTagParams('object', array('width' => '#int', 'height' => '#int', 'data' => '#link')); $this->oTextParser->cfgAllowTagParams('param', array('name' => '#text', 'value' => '#text')); $this->oTextParser->cfgAllowTagParams('embed', array('src' => '#image', 'type' => '#text', 'allowscriptaccess' => '#text', 'allowfullscreen' => '#text', 'width' => '#int', 'height' => '#int', 'flashvars' => '#text', 'wmode' => '#text')); // Параметры тегов являющиеся обязательными $this->oTextParser->cfgSetTagParamsRequired('img', 'src'); $this->oTextParser->cfgSetTagParamsRequired('a', 'href'); // Теги которые необходимо вырезать из текста вместе с контентом $this->oTextParser->cfgSetTagCutWithContent(array('script', 'iframe', 'style')); // Вложенные теги $this->oTextParser->cfgSetTagChilds('object', 'param', false, true); $this->oTextParser->cfgSetTagChilds('object', 'embed', false, false); // Отключение авто-добавления <br> $this->oTextParser->cfgSetAutoBrMode(true); $this->SetTemplateAction('index'); }