diff --git a/typo3/sysext/indexed_search/Classes/Example/CrawlerHook.php b/typo3/sysext/indexed_search/Classes/Example/CrawlerHook.php deleted file mode 100644 index c85fbf0fb91b6b356b538557ae85dd4374522377..0000000000000000000000000000000000000000 --- a/typo3/sysext/indexed_search/Classes/Example/CrawlerHook.php +++ /dev/null @@ -1,125 +0,0 @@ -<?php -namespace TYPO3\CMS\IndexedSearch\Example; - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\IndexedSearch\Indexer; - -/** - * Index search crawler hook example - * @internal just an example, not for public use, but used as a blue-print - */ -class CrawlerHook -{ - /** - * Function is called when an indexing session starts according to the time intervals set for the indexing configuration. - * - * @return string Return a text string for the first, initiating queue entry for the crawler. - */ - public function initMessage() - { - return 'Start of Custom Example Indexing session!'; - } - - /** - * This will do two things: - * 1) Carry out actual indexing of content (one or more items) - * 2) Add one or more new entries into the crawlers queue so we are called again (another instance) for further indexing in the session (optional of course, if all indexing is done, we add no new entries) - * - * @param array $cfgRec Indexing Configuration Record (the record which holds the information that lead to this indexing session...) - * @param array $session_data Session data variable. Passed by reference. Changed content is saved and passed back upon next instance in the session. - * @param array $params Params array from the queue entry. - * @param \TYPO3\CMS\IndexedSearch\Hook\CrawlerHook $pObj Parent Object (from "indexed_search" extension) - */ - public function indexOperation($cfgRec, &$session_data, $params, &$pObj) - { - // Set up language uid, if any: - $sys_language_uid = 0; - - // Init session data array if not already: - if (!is_array($session_data)) { - $session_data = [ - 'step' => 0 - ]; - } - // Increase step counter (this is just an example of how the session data can be used - to track how many instances of indexing is left) - $session_data['step']++; - switch ((int)$session_data['step']) { - case 1: - // Indexing Example: Content accessed with GET parameters added to URL: - // Get rootline from the Indexing Record (needed because the indexer relates all search results to a position in the page tree!) [DON'T CHANGE]: - $rl = $pObj->getUidRootLineForClosestTemplate($cfgRec['pid']); - // Set up 2 example items to index: - $exampleItems = [ - [ - 'ID' => '123', - 'title' => 'Title of Example 1', - 'content' => 'Vestibulum leo turpis, fringilla sit amet, semper eget, vestibulum ut, arcu. Vestibulum mauris orci, vulputate quis, congue eget, nonummy' - ], - [ - 'ID' => 'example2', - 'title' => 'Title of Example 2', - 'content' => 'Cras tortor turpis, vulputate non, accumsan a, pretium in, magna. Cras turpis turpis, pretium pulvinar, pretium vel, nonummy eu.' - ] - ]; - // For each item, index it (this is what you might like to do in batches of like 100 items if all your content spans thousands of items!) - foreach ($exampleItems as $item) { - // Prepare the GET variables array that must be added to the page URL in order to view result: - parse_str('&itemID=' . rawurlencode($item['ID']), $GETparams); - // Prepare indexer (make instance, initialize it, set special features for indexing parameterized content - probably none of this should be changed by you) [DON'T CHANGE]: - /** @var Indexer $indexerObj */ - $indexerObj = GeneralUtility::makeInstance(Indexer::class); - $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', $rl, $GETparams); - $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); - $indexerObj->forceIndexing = true; - // Indexing the content of the item (see \TYPO3\CMS\IndexedSearch\Indexer::backend_indexAsTYPO3Page() for options) - $indexerObj->backend_indexAsTYPO3Page($item['title'], '', '', $item['content'], 'utf-8', $item['tstamp'], $item['create_date'], $item['ID']); - } - break; - case 2: - // Indexing Example: Content accessed directly in file system: - // Get rootline from the Indexing Record (needed because the indexer relates all search results to a position in the page tree!) [DON'T CHANGE]: - $rl = $pObj->getUidRootLineForClosestTemplate($cfgRec['pid']); - // Prepare indexer (make instance, initialize it, set special features for indexing parameterized content - probably none of this should be changed by you) [DON'T CHANGE]: - /** @var Indexer $indexerObj */ - $indexerObj = GeneralUtility::makeInstance(Indexer::class); - $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', $rl); - $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); - $indexerObj->hash['phash'] = -1; - // To avoid phash_t3 being written to file sections (otherwise they are removed when page is reindexed!!!) - // Index document: - $indexerObj->indexRegularDocument('fileadmin/templates/index.html', true); - break; - case 3: - // Indexing Example: Content accessed on External URLs: - // Index external URL: - /** @var Indexer $indexerObj */ - $indexerObj = GeneralUtility::makeInstance(Indexer::class); - $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', null); - $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); - $indexerObj->hash['phash'] = -1; - // To avoid phash_t3 being written to file sections (otherwise they are removed when page is reindexed!!!) - // Index external URL (HTML only): - $indexerObj->indexExternalUrl('http://www.google.com/'); - break; - } - // Finally, set entry for next indexing instance (if all steps are not completed) - if ($session_data['step'] <= 3) { - $title = 'Step #' . $session_data['step'] . ' of 3'; - // Just information field. Never mind that the field is called "url" - this is what will be shown in the "crawler" log. Could be a URL - or whatever else tells what that indexing instance will do. - $pObj->addQueueEntryForHook($cfgRec, $title); - } - } -} diff --git a/typo3/sysext/indexed_search/Classes/Example/PluginHook.php b/typo3/sysext/indexed_search/Classes/Example/PluginHook.php deleted file mode 100644 index dcc78df058fb41877a5ba3dab5f112f74b3d6dd3..0000000000000000000000000000000000000000 --- a/typo3/sysext/indexed_search/Classes/Example/PluginHook.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php -namespace TYPO3\CMS\IndexedSearch\Example; - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -/** - * Index search frontend example hook - */ -/** - * Index search frontend - EXAMPLE hook for alternative searching / display etc. - * Hooks are configured in ext_localconf.php as key => hook-reference pairs in $TYPO3_CONF_VARS['EXTCONF']['indexed_search']['pi1_hooks']. See example in ext_localconf.php for "indexed_search" - * Each hook must have an entry, the key must match the hook-key in class.tx_indexed_search.php and generally the key equals the function name in the hook object (a convention used) - * @internal just an example, not for public use, but used as a blue-print - */ -class PluginHook -{ - /** - * Is set to a reference to the parent object, "pi1/class.indexedsearch.php" - * - * @var \TYPO3\CMS\IndexedSearch\Controller\SearchFormController - */ - public $pObj; - - /** - * EXAMPLE of how you can post process the initialized values in the frontend plugin. - * The example reverses the order of elements in the ranking selector box. You can modify other values like this or add / remove items. - * - * This hook is activated by this key / value pair in ext_localconf.php - * 'initialize_postProc' => \TYPO3\CMS\IndexedSearch\Example\PluginHook::class, - */ - public function initialize_postProc() - { - $this->pObj->optValues['order'] = array_reverse($this->pObj->optValues['order']); - } - - /** - * Example of how the content displayed in the result rows can be extended or modified - * before the data is assigned to the fluid template as {resultsets}. - * The code example replaces all occurrences of the search string with the replacement - * string in the description of all rows in the result. - * - * @param array $result - * @return array - */ - public function getDisplayResults_postProc(array $result): array - { - if ($result['count'] > 0) { - foreach ($result['rows'] as $rowIndex => $row) { - $result['rows'][$rowIndex]['description'] = \str_replace('foo', 'bar', $row['description']); - } - } - return $result; - } - - /** - * Providing an alternative search algorithm! - * - * @param array $sWArr Array of search words - */ - public function getResultRows($sWArr) - { - } - - /** - * Example of how the content displayed in the result rows can be post processed before rendered into HTML. - * This example simply shows how the description field is wrapped in italics and the path is hidden by setting it blank. - * - * @param array $tmplContent Template Content (generated from result row) being processed. - * @param array $row Result row - * @param bool $headerOnly If set, the result row is a sub-row. - * @return array Template Content returned. - */ - public function prepareResultRowTemplateData_postProc($tmplContent, $row, $headerOnly) - { - $tmplContent['description'] = '<em>' . $tmplContent['description'] . '</em>'; - $tmplContent['path'] = ''; - return $tmplContent; - } -} diff --git a/typo3/sysext/indexed_search/Tests/Unit/Example/PluginHookTest.php b/typo3/sysext/indexed_search/Tests/Unit/Example/PluginHookTest.php deleted file mode 100644 index 43488e20804fe34401bd3be2a153a69adfe2f01e..0000000000000000000000000000000000000000 --- a/typo3/sysext/indexed_search/Tests/Unit/Example/PluginHookTest.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -namespace TYPO3\CMS\IndexedSearch\Tests\Unit\Example; - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -use TYPO3\CMS\IndexedSearch\Example\PluginHook; -use TYPO3\TestingFramework\Core\Unit\UnitTestCase; - -/** - * Test case - */ -class PluginHookTest extends UnitTestCase -{ - /** - * @var bool Reset singletons created by subject - */ - protected $resetSingletonInstances = true; - - /** - * @test - */ - public function getDisplayResults_postProcReturnsTheOriginalSearchResultBecauseOfMissingItems() - { - $searchResult = [ - 'count' => 0, - 'rows' => [] - ]; - - $result = (new PluginHook())->getDisplayResults_postProc($searchResult); - self::assertSame($searchResult, $result); - } - - /** - * @test - */ - public function getDisplayResults_postProcModifiesTheDescriptionInARowOfSearchResult() - { - $searchResult = [ - 'count' => 2, - 'rows' => [ - ['description' => 'I am a description field with joe and foo.'], - ['description' => 'Description will be modified to two bar. foo, bar, joe. '] - ] - ]; - - $expected = [ - 'count' => 2, - 'rows' => [ - ['description' => 'I am a description field with joe and bar.'], - ['description' => 'Description will be modified to two bar. bar, bar, joe. '] - ] - ]; - - $result = (new PluginHook())->getDisplayResults_postProc($searchResult); - self::assertSame($expected, $result); - } -}