Commit d1be317e authored by Henrik Ziegenhain's avatar Henrik Ziegenhain
Browse files

[TASK] Initial commit

parents
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
# TS/JS-Files
[*.{ts, js}]
indent_size = 2
# JSON-Files
[*.json]
indent_style = tab
# ReST-Files
[*.rst]
indent_size = 3
max_line_length = 80
# YAML-Files
[*.{yaml, yml}]
indent_size = 2
# package.json
# .travis.yml
[{package.json, .travis.yml}]
indent_size = 2
# TypoScript
[*.{typoscript, tsconfig}]
indent_size = 2
# XLF-Files
[*.xlf]
indent_style = tab
# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2
# .htaccess
[{_.htaccess, .htaccess}]
indent_style = tab
.idea
.vagrant
vendor
cachegrind.out.*
.build
/*.txt
*.zip
*.log
/gource*
/Documentation-GENERATED-temp/
\ No newline at end of file
<?php
declare(strict_types=1);
/**
* This file is part of the "kesearch_shortcut_indexer" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Hziegenhain\KesearchShortcutIndexer;
use TeaminmediasPluswerk\KeSearch\Indexer\Types\Page;
/**
* This class adds field from tt_content to the list of fields
*/
class ShortcutContentFields
{
/** @var string field to fetch */
private $column = 'records';
/**
* Add the field to list
*
* @param string $fields
* @param Page $pageIndexer
*/
public function modifyPageContentFields(&$fields, $pageIndexer)
{
if ($this->getColumn()) {
$fields .= "," . $this->getColumn();
}
}
/**
* @return string
*/
public function getColumn(): string
{
return $this->column;
}
/**
* @param string $column
*/
public function setColumn(string $column): void
{
$this->column = $column;
}
}
<?php
declare(strict_types=1);
/**
* This file is part of the "kesearch_shortcut_indexer" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Hziegenhain\KesearchShortcutIndexer;
use TeaminmediasPluswerk\KeSearch\Indexer\Types\Page;
use TeaminmediasPluswerk\KeSearch\Lib\Db;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use Zwo3\MaskKesearchIndexer\AdditionalContentFields;
/**
* This class provides a possibility to index 'shortcut' elements in your indexer
*/
class ShortcutContentFromContentElement
{
/**
* @param string $bodytext
* @param array $ttContentRow
* @param Page $pageIndexer
*/
public function modifyContentFromContentElement(string &$bodytext, array $ttContentRow, $pageIndexer)
{
$shortcutContentField = new ShortcutContentFields();
$column = $shortcutContentField->getColumn();
if (!empty($ttContentRow[$column]) && $ttContentRow['CType'] === 'shortcut') {
// get related records
$records = $this->resolveRecordList($ttContentRow[$column]);
$bodytext .= $this->getContentFromRelatedRecords($records, $pageIndexer);
// add the content to bodytext
$bodytext .= strip_tags($ttContentRow[$column]);
}
}
/**
* @param string $recordsList
* @return array
*/
protected function resolveRecordList($recordsList = ''): array
{
$records = [];
$relations = GeneralUtility::trimExplode(',', $recordsList);
foreach ($relations as $val) {
// Extract table name and id. [tablename]_[id]
// where table name MIGHT contain "_", hence the reversion of the string!
$val = strrev($val);
$parts = explode('_', $val, 2);
$theId = strrev($parts[0]);
// Check that the id IS an integer:
if (MathUtility::canBeInterpretedAsInteger($theId)) {
// Get the table name: If a part of the exploded string, use that.
$theTable = strrev(trim($parts[1]));
$records[] = [
'table' => $theTable,
'uid' => $theId
];
}
}
return $records;
}
/**
* @param array $records
* @return string
*/
private function getContentFromRelatedRecords($records, $pageIndexer)
{
$bodytext = '';
if (empty($records)) {
return $bodytext;
}
foreach ($records as $record) {
$queryBuilder = Db::getQueryBuilder($record['table']);
$rows = $queryBuilder
->select(...['bodytext', 'CType'])
->from($record['table'])
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->quote($record['uid'], \PDO::PARAM_INT)
)
)
->execute()->fetchAll();
foreach ($rows as $row) {
foreach ($row as $fieldname => $content) {
if (empty($content)) {
continue;
}
// spaces between field contents
if (!empty($bodytext)) {
$bodytext .= ' ';
}
// do not include CType value to index
if ($fieldname !== 'CType') {
$bodytext .= strip_tags($content);
}
// Instantiate EXT:mask_kesearch_indexer, if present, to allow indexing of EXT:mask contents
if (
ExtensionManagementUtility::isLoaded('mask_kesearch_indexer') &&
$fieldname === 'CType' && !stripos($content, 'mask_')
) {
$rows = $queryBuilder
->select('*')
->from($record['table'])
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->quote($record['uid'], \PDO::PARAM_INT)
)
)
->execute()->fetchAll();
$maskKesearchIndexer = GeneralUtility::makeInstance(AdditionalContentFields::class);
$bodytext .= $maskKesearchIndexer->modifyContentFromContentElement(
$bodytext,
$rows[0],
$pageIndexer
);
}
}
}
}
return $bodytext;
}
}
# kesearch_shortcut_indexer
## What is EXT:kesearch_shortcut_indexer?
As the extension key suggests, it is an indexer for shortcut elements with ke_search
## Installation
Just install it the common ways. It hooks up in page-/content-indexer. You can install EXT:kesearch_shortcut_indexer in
TYPO3 CMS using the [TER](https://extensions.typo3.org/extension/kesearch_shortcut_indexer/)
or use composer to fetch EXT:kesearch_shortcut_indexer
from [packagist](https://packagist.org/packages/hziegenhain/kesearch-shortcut-indexer):
```
composer req hziegenhain/kesearch-shortcut-indexer
```
## Documentation
Add 'shortcut' to the content elements, which should be indexed in the indexer config.
## How to contribute?
Just fork this repository and create a pull request to the **master** branch. Please also describe why you've submitted
your patch. If you have any questions feel free to contact me.
## Thanks
This extension is heavily inspired by EXT:mask_kesearch_indexer by Gregor Agnes (zwo3). Thank you very much, Gregor.
{
"name": "hziegenhain/kesearch_shortcut_indexer",
"authors": [
{
"name": "Henrik Ziegenhain",
"role": "Developer"
}
],
"type": "typo3-cms-extension",
"description": "ke_search Indexer for shortcut elements",
"keywords": [
"TYPO3",
"extension",
"ke_search",
"shortcut",
"indexer"
],
"license": [
"GPL-2.0-or-later"
],
"require": {
"typo3/cms-core": "^9.5 || ^10.4",
"teaminmedias-pluswerk/ke_search": "^3.1.0"
},
"require-dev": {
"roave/security-advisories": "dev-master"
},
"suggest": {
"typo3/scheduler": "^9.5 || ^10.4"
},
"replace": {
"hziegenhain/kesearch_shortcut_indexer": "self.version"
},
"autoload": {
"psr-4": {
"Hziegenhain\\KesearchShortcutIndexer\\": "Classes/"
}
}
}
<?php
/***************************************************************
* Extension Manager/Repository config file for ext "kesearch_shortcut_indexer".
*
* Auto generated 29-11-2020 14:45
*
* Manual updates:
* Only the data in the array - everything else is removed by next
* writing. "version" and "dependencies" must not be touched!
***************************************************************/
$EM_CONF[$_EXTKEY] = [
'title' => 'KeSearch Indexer for Shortcut Elements',
'description' => 'Indexer for shortcut elements, can handle mask records as well',
'category' => 'backend',
'version' => '1.0.0',
'state' => 'stable',
'author' => 'Henrik Ziegenhain',
'author_email' => 'henrik@hziegenhain.de',
'author_company' => '',
'constraints' => [
'depends' => [
'typo3' => '9.5.0-10.4.99',
'ke_search' => '3.1.0-3.99.99',
],
'conflicts' => [
],
'suggests' => [
],
],
'uploadfolder' => false,
'createDirs' => null,
'clearcacheonload' => false,
];
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<rect y="0" fill="#25939D" width="64" height="64"/>
<path fill="#FFFFFF" d="M29.2,20.5v15.3c0,0.7-0.6,1.3-1.3,1.3l0,0v11.5c0,0.7-0.6,1.3-1.3,1.3H16.4c-0.7,0-1.3-0.6-1.3-1.3V38.4
l5-17.4c0.1-0.3,0.3-0.5,0.6-0.5L29.2,20.5L29.2,20.5z M35.5,20.5v14h-5.1v-14H35.5z M50.9,38.4v10.2c0,0.7-0.6,1.3-1.3,1.3H39.4
c-0.7,0-1.3-0.6-1.3-1.3V37.1c-0.7,0-1.3-0.6-1.3-1.3V20.5h8.5c0.3,0,0.5,0.2,0.6,0.5L50.9,38.4z M29.8,14.8v4.5h-7v-4.5
c0-0.4,0.3-0.6,0.6-0.6h5.7C29.5,14.1,29.8,14.4,29.8,14.8L29.8,14.8z M43.2,14.8v4.5h-7v-4.5c0-0.4,0.3-0.6,0.6-0.6h5.7
C42.9,14.1,43.2,14.4,43.2,14.8L43.2,14.8z"/>
</svg>
\ No newline at end of file
<?php
defined('TYPO3_MODE') or die();
// encapsulate all locally defined variables
(function () {
// Register hooks for indexing additional fields for shortcut CE.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyPageContentFields'][] =
\Hziegenhain\KesearchShortcutIndexer\ShortcutContentFields::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyContentFromContentElement'][] =
\Hziegenhain\KesearchShortcutIndexer\ShortcutContentFromContentElement::class;
})();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment