-
Notifications
You must be signed in to change notification settings - Fork 20
/
class.tx_mksearch_indexer_ttcontent_Templavoila.php
296 lines (270 loc) · 11 KB
/
class.tx_mksearch_indexer_ttcontent_Templavoila.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/**
* @author Hannes Bochmann <dev@dmk-ebusiness.de>
*
* Copyright notice
*
* (c) 2011 Hannes Bochmann <dev@dmk-ebusiness.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/
/**
* benötigte Klassen einbinden.
*/
/**
* takes care of tt_content with templavoila support.
*
* @todo wenn templavoila installiert ist, sollten allen elemente, die in einem tv
* container liegen in die queue gelegt werden. beim indizieren muss dann noch geprüft
* werden ob das element parents hat und diese nicht hidden sind.
*
* @author Hannes Bochmann <dev@dmk-ebusiness.de>
*/
class tx_mksearch_indexer_ttcontent_Templavoila extends tx_mksearch_indexer_ttcontent_Normal
{
/**
* The references (pids) of this element. if templavoila is
* not installed it contains only the pid of the element it self.
*
* @var array
*/
protected $aReferences = array();
/**
* The indexable references (pids) of this element. These references
* are taken to check if the element has to be deleted.
*
* @var array
*/
protected $aIndexableReferences = array();
/**
* Sets the index doc to deleted if neccessary.
*
* @param tx_rnbase_IModel $oModel
* @param tx_mksearch_interface_IndexerDocument $oIndexDoc
* @param array $aOptions
*
* @return bool
*/
protected function hasDocToBeDeleted(
tx_rnbase_IModel $oModel,
tx_mksearch_interface_IndexerDocument $oIndexDoc,
$aOptions = array()
) {
// if we got not a single reference,
// even not the element itself, it should be deleted
if (empty($this->aIndexableReferences)) {
return true;
}
// now we have to check if at least one reference
// remains that has not to be deleted.
$aStillIndexableReferences = array();
foreach ($this->aIndexableReferences as $iPid) {
// set the pid
$oModel->record['pid'] = $iPid;
if (!parent::hasDocToBeDeleted($oModel, $oIndexDoc, $aOptions)) {
// set value as key to avoid doubles
$aStillIndexableReferences[$iPid] = $iPid;
}
}
// any valid references left?
if (empty($aStillIndexableReferences)) {
return true;
} // finally set the pid of the first reference to our element
// as we can not know which array index is the first we simply use
// array_shift which returns the first off shifted element,
// our desired first one
else {
$oModel->record['pid'] = array_shift($aStillIndexableReferences);
}
return false;
}
/**
* Returns all references (pids) this element has. if templavoila is
* not installed we simply return the pid of the element.
*
* @param tx_rnbase_IModel $oModel
*
* @return array
*/
protected function getReferences(tx_rnbase_IModel $oModel)
{
$database = Tx_Rnbase_Database_Connection::getInstance();
// so we have to fetch all references
// we just need to check this table for entries for this element
$aSqlOptions = array(
'where' => 'ref_table='.$database->fullQuoteStr('tt_content', 'sys_refindex').
' AND ref_uid='.(int) $oModel->getUid().
' AND deleted=0',
'enablefieldsoff' => true,
);
$aFrom = array('sys_refindex', 'sys_refindex');
$aRows = $database->doSelect('tablename, recuid', $aFrom, $aSqlOptions);
// now we need to collect the pids of all references. either a
// reference is a page than we simply use it's pid or the
// reference is another tt_content.
// in the last case we take the pid of this element
$aReferences = array();
if (!empty($aRows)) {
foreach ($aRows as $aRow) {
if ('pages' == $aRow['tablename']) {
$aReferences[] = $aRow['recuid'];
} elseif ('tt_content' == $aRow['tablename']) {
$aSqlOptions = array(
'where' => 'tt_content.uid='.$aRow['recuid'],
// checks for being hidden/deleted are made later
'enablefieldsoff' => true,
);
$aFrom = array('tt_content', 'tt_content');
$aNewRows = $database->doSelect('tt_content.pid', $aFrom, $aSqlOptions);
$aReferences[] = $aNewRows[0]['pid'];
}
}
}
return $aReferences;
}
/**
* Prüft ob das Element speziell in einem Seitenbaum oder auf einer Seite liegt,
* der/die inkludiert oder ausgeschlossen werden soll.
* Der Entscheidungsbaum dafür ist relativ, sollte aber durch den Code
* illustriert werden.
*
* @param array $sourceRecord
* @param array $options
*
* @return bool
*/
protected function isIndexableRecord(array $sourceRecord, array $options)
{
$this->aIndexableReferences = array();
// we have to do the checks for all references and collect the indexable ones
$return = false;
if (!empty($this->aReferences)) {
foreach ($this->aReferences as $iPid) {
// set the pid
$sourceRecord['pid'] = $iPid;
if (parent::isIndexableRecord($sourceRecord, $options)) {
// as soon as we have a indexable reference we are fine
$return = true;
// collect this pid as indexable
$this->aIndexableReferences[$iPid] = $iPid;
}
}
} else {
// without any references this element is indexable but will be
// deleted later
$return = true;
}
return $return;
}
/**
* Returns the model to be indexed.
*
* @param array $rawData
* @param string $tableName
* @param array $options
*
* @return tx_mksearch_model_irfaq_Question
*/
protected function createModel(array $rawData, $tableName = null, $options = array())
{
$model = parent::createModel($rawData, $tableName, $options);
// we need all references this element has for later checks
$this->aReferences = $this->getReferences($model);
return $model;
}
/**
* fetches the content of an tv element.
*
* @return string
*/
protected function getTemplavoilaElementContent()
{
$ttContentModel = $this->getModelToIndex();
$record = $ttContentModel->getRecord();
tx_mksearch_util_Indexer::prepareTSFE($record['pid'], $options['lang']);
$this->adjustIncludeLibsPathForBe();
$templavoilaPlugin = tx_rnbase::makeInstance('tx_templavoila_pi1');
$templavoilaPlugin->cObj = tx_rnbase::makeInstance(tx_rnbase_util_Typo3Classes::getContentObjectRendererClass());
$templavoilaPlugin->cObj->data = $record;
$templavoilaPlugin->cObj->currentRecord = 'tt_content:'.$ttContentModel->getUid();
return $templavoilaPlugin->renderElement($record, 'tt_content');
}
/**
* Die Indizierung wird von verschiedenen Pfaden aus aufgerufen.
* (CLI, BE Modul, Scheduler)
* Im FE ist der Pfad immer tslib
* worauf alle includeLibs Pfade ausgerichtet sind.
* Wir haben aber nicht den immer gleichen Pfad beim
* TV rendering im BE und daher müssen wir die relativen includeLibs Pfade
* um einen Prefix ergänzen damit das inkludieren fkt.
*/
private function adjustIncludeLibsPathForBe()
{
$ts = &$GLOBALS['TSFE']->tmpl->setup['plugin.'];
foreach ($ts as $pluginConfig) {
if (!is_array($pluginConfig) ||
!isset($pluginConfig['includeLibs']) ||
// solche pfade werden später von TYPO3 korrekt aufgelöst
false !== strpos($pluginConfig['includeLibs'], 'EXT:')
) {
continue;
}
// vom fileCache werden Dateien zu erst abgerufen
$filehash = md5($pluginConfig['includeLibs']);
$GLOBALS['TSFE']->tmpl->fileCache[$filehash] =
$this->getRelativePathPrefixFromCurrentExecutionDirToWebroot().$pluginConfig['includeLibs'];
}
}
/**
* get the relative path prefix from current execution dir to webroot.
*
* @return string
*/
private function getRelativePathPrefixFromCurrentExecutionDirToWebroot()
{
// indexing via Scheduler in CLI
if (tx_rnbase_util_TYPO3::isCliMode()) {
// somewhere inside typo3 but not in webroot
if (strlen(getcwd()) > strlen(\Sys25\RnBase\Utility\Environment::getPublicPath())) {
$relativePathInsideTypo3 = str_replace(\Sys25\RnBase\Utility\Environment::getPublicPath(), '', getcwd());
// we need to find out how many levels we need to go up from here
// to the webroot
$pathParts = explode('/', $relativePathInsideTypo3);
$relativePathPrefixFromExecutionDir = str_repeat('../', count($pathParts));
} // somewhere outside typo3
elseif (strlen(getcwd()) < strlen(\Sys25\RnBase\Utility\Environment::getPublicPath())) {
$relativePathPrefixFromExecutionDir = str_replace(getcwd(), '', \Sys25\RnBase\Utility\Environment::getPublicPath());
} // inside typo3 webroot
else {
$relativePathPrefixFromExecutionDir = '';
}
} // indexing via Scheduler in BE
// script executed in /typo3
elseif (false !== strpos(\Sys25\RnBase\Utility\Environment::getCurrentScript(), 'typo3/mod.php')) {
$relativePathPrefixFromExecutionDir = '../';
} // indexing via mksearch BE module
// script executed in /typo3/sysext/cms/tslib
else {
$relativePathPrefixFromExecutionDir = '../../../../';
}
return $relativePathPrefixFromExecutionDir;
}
}
if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/mksearch/indexer/ttcontent/class.tx_mksearch_indexer_ttcontent_Templavoila.php']) {
include_once $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/mksearch/indexer/ttcontent/class.tx_mksearch_indexer_ttcontent_Templavoila.php'];
}