public function testFromHtmlWithLi() { $sHtml = <<<EOT \t\t<ul> \t\t<li>Test1</li><li>Test2</li><li>Test3</li> \t\t</ul> EOT; $this->assertSame(array('test1', 'test2', 'test3'), StringUtil::getWords($sHtml, true)); }
public function display(Template $oTemplate, $bIsPreview = false) { $sTemplateName = $this->oPage->getTemplateNameUsed(); $sLanguageId = Session::language(); $oListTemplate = null; $oItemTemplatePrototype = null; try { $oListTemplate = new Template("search_results/{$sTemplateName}"); $oItemTemplatePrototype = new Template("search_results/{$sTemplateName}_item"); } catch (Exception $e) { $oListTemplate = new Template("search_results/default"); $oItemTemplatePrototype = new Template("search_results/default_item"); } $aResults = array(); $sWords = isset($_REQUEST['q']) ? $_REQUEST['q'] : ''; if ($sWords) { $aWords = StringUtil::getWords($sWords, false, '%'); $oSearchWordQuery = SearchIndexWordQuery::create(); foreach ($aWords as $sWord) { $sWord = Synonyms::rootFor($sWord); $sComparison = Criteria::EQUAL; if (strpos($sWord, '%') !== false) { $sComparison = Criteria::LIKE; } $oSearchWordQuery->addOr(SearchIndexWordPeer::WORD, $sWord, $sComparison); } $oSearchWordQuery->joinSearchIndex()->useQuery('SearchIndex')->joinPage()->useQuery('Page')->active(true)->filterByIsProtected(false)->endUse()->endUse(); foreach ($oSearchWordQuery->find() as $oSearchIndexWord) { $iId = $oSearchIndexWord->getSearchIndexId(); if (isset($aResults[$iId])) { $aResults[$iId] += $oSearchIndexWord->getCount(); } else { $aResults[$iId] = $oSearchIndexWord->getCount(); } } arsort($aResults); } $oListTemplate->replaceIdentifier('count', count($aResults)); $oListTemplate->replaceIdentifier('search_string', $sWords); if (count($aResults) === 0) { $oListTemplate->replaceIdentifier('no_results', TranslationPeer::getString('wns.search.no_results', null, null, array('search_string' => $sWords))); } foreach ($aResults as $iIndexId => $iCount) { $oIndex = SearchIndexQuery::create()->findPk(array($iIndexId, $sLanguageId)); if (!$oIndex || !$oIndex->getPage()) { continue; } $oItemTemplate = clone $oItemTemplatePrototype; $oIndex->renderListItem($oItemTemplate); $oItemTemplate->replaceIdentifier('count', $iCount); $oListTemplate->replaceIdentifierMultiple('items', $oItemTemplate); } $oTemplate->replaceIdentifier('search_results', $oListTemplate); }
public function getWords() { $oUsedTemplate = new Template($this->oPage->getTemplateNameUsed()); $sTemplateContents = ''; foreach ($oUsedTemplate->identifiersMatching('container', Template::$ANY_VALUE) as $oTemplateIdentifier) { if ($oTemplateIdentifier->hasParameter('declaration_only')) { // Container exists only to appear in admin area, not be rendered in frontend (at least not directly) continue; } $sTemplateContents .= $oTemplateIdentifier->__toString(); } foreach ($oUsedTemplate->identifiersMatching('autofill', Template::$ANY_VALUE) as $oTemplateIdentifier) { $sTemplateContents .= $oTemplateIdentifier->__toString(); } $sTemplate = new Template($sTemplateContents, null, true); $this->display($sTemplate, false); return StringUtil::getWords($sTemplate, true); }
/** * Returns the words for which this module should be listed in the site’s search index */ public function getWords() { return StringUtil::getWords($this->renderFrontend(), true); }
private function index(array $aPath) { $oNavigationItem = $this->oRootNavigationItem; PageNavigationItem::clearCache(); while (count($aPath) > 0) { $oNavigationItem = $oNavigationItem->namedChild(array_shift($aPath), $this->sLanguageId, true, true); } FilterModule::getFilters()->handleNavigationPathFound($this->oRootNavigationItem, $oNavigationItem); FrontendManager::$CURRENT_NAVIGATION_ITEM = $oNavigationItem; $oPageNavigationItem = $oNavigationItem; while (!$oPageNavigationItem instanceof PageNavigationItem) { $oPageNavigationItem = $oPageNavigationItem->getParent(); } FrontendManager::$CURRENT_PAGE = $oPageNavigationItem->getMe(); $oPage = FrontendManager::$CURRENT_PAGE; $bIsNotFound = false; FilterModule::getFilters()->handlePageHasBeenSet($oPage, $bIsNotFound, $oNavigationItem); FilterModule::getFilters()->handleRequestStarted(); FilterModule::getFilters()->handlePageNotFoundDetectionComplete($bIsNotFound, $oPage, $oNavigationItem, array(&$bIsNotFound)); if ($bIsNotFound) { return false; } $sDescription = $oNavigationItem->getDescription($this->sLanguageId); if ($sDescription === null) { $sDescription = $oPage->getDescription($this->sLanguageId); } $aKeywords = array(); foreach ($oPage->getConsolidatedKeywords($this->sLanguageId, true) as $sKeyword) { $aKeywords = array_merge($aKeywords, StringUtil::getWords($sKeyword)); } $sTitle = $oNavigationItem->getTitle($this->sLanguageId); $sLinkText = $oNavigationItem->getLinkText($this->sLanguageId); if (!$sLinkText) { $sLinkText = $sTitle; } $sName = $oNavigationItem->getName(); // Page type can prevent indexing if (!self::doIndex($oPage->getPageType(), $oNavigationItem)) { return false; } $oPageType = PageTypeModule::getModuleInstance($oPage->getPageType(), $oPage, $oNavigationItem); $aWords = $oPageType->getWords(); $aWords = array_merge($aWords, StringUtil::getWords($sDescription), $aKeywords, StringUtil::getWords($sTitle), StringUtil::getWords($sLinkText), array($sName)); $aPagePath = $oPage->getLink(); $aNavigationItemPath = $oNavigationItem->getLink(); $sPath = implode('/', array_diff($aNavigationItemPath, $aPagePath)); $oSearchIndex = new SearchIndex(); $oSearchIndex->setPageId($oPage->getId()); $oSearchIndex->setPath($sPath); $oSearchIndex->setLinkText($sLinkText); $oSearchIndex->setPageTitle($sTitle); $oSearchIndex->setLanguageId($this->sLanguageId); $oSearchIndex->save(); foreach ($aWords as $sWord) { $sWord = Synonyms::rootFor($sWord, $this->sLanguageId); $oSearchIndexWord = SearchIndexWordQuery::create()->filterBySearchIndex($oSearchIndex)->filterByWord($sWord)->findOne(); if ($oSearchIndexWord === null) { $oSearchIndexWord = new SearchIndexWord(); $oSearchIndexWord->setSearchIndex($oSearchIndex); $oSearchIndexWord->setWord($sWord); } else { $oSearchIndexWord->incrementCount(); } $oSearchIndexWord->save(); } return true; }
public static function getContentInfo($oLanguageObject) { $sText = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($oLanguageObject->getData())); return implode(" ", StringUtil::getWords($sText, true)); }