|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU General Public License version 3 or later. |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use \TYPO3\CMS\Extbase\Configuration\ConfigurationManager; |
|
|
|
|
|
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
17
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
18
|
|
|
|
|
19
|
|
|
class FeedsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
public $prefixId = 'tx_dlf'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ConfigurationManager |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $configurationManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \TYPO3\CMS\Core\Log\LogManager |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $logger; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* SearchController constructor. |
|
35
|
|
|
* @param $configurationManager |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(ConfigurationManager $configurationManager) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->configurationManager = $configurationManager; |
|
40
|
|
|
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
public function mainAction() |
|
47
|
|
|
{ |
|
48
|
|
|
$requestData = $this->request->getArguments(); |
|
49
|
|
|
|
|
50
|
|
|
// Create XML document. |
|
51
|
|
|
$rss = new \DOMDocument('1.0', 'utf-8'); |
|
52
|
|
|
// Add mandatory root element. |
|
53
|
|
|
$root = $rss->createElement('rss'); |
|
54
|
|
|
$root->setAttribute('version', '2.0'); |
|
55
|
|
|
// Add channel element. |
|
56
|
|
|
$channel = $rss->createElement('channel'); |
|
57
|
|
|
$channel->appendChild($rss->createElement('title', htmlspecialchars($this->settings['title'], ENT_NOQUOTES, 'UTF-8'))); |
|
58
|
|
|
|
|
59
|
|
|
$currentUri = $this->controllerContext |
|
60
|
|
|
->getUriBuilder() |
|
61
|
|
|
->reset() |
|
62
|
|
|
->setTargetPageUid($GLOBALS["TSFE"]->id) |
|
63
|
|
|
->setAddQueryString(TRUE) |
|
64
|
|
|
->buildFrontendUri(); |
|
65
|
|
|
$channel->appendChild($rss->createElement('link', htmlspecialchars(GeneralUtility::locationHeaderUrl($currentUri), ENT_NOQUOTES, 'UTF-8'))); |
|
66
|
|
|
|
|
67
|
|
|
if (!empty($this->settings['description'])) { |
|
68
|
|
|
$channel->appendChild($rss->createElement('description', htmlspecialchars($this->settings['description'], ENT_QUOTES, 'UTF-8'))); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
72
|
|
|
->getQueryBuilderForTable('tx_dlf_structures'); |
|
73
|
|
|
|
|
74
|
|
|
$result = $queryBuilder |
|
75
|
|
|
->select('tx_dlf_libraries.label AS label') |
|
76
|
|
|
->from('tx_dlf_libraries') |
|
77
|
|
|
->where( |
|
78
|
|
|
$queryBuilder->expr()->eq('tx_dlf_libraries.pid', (int)$this->settings['pages']), |
|
79
|
|
|
$queryBuilder->expr()->eq('tx_dlf_libraries.uid', (int)$this->settings['library']), |
|
80
|
|
|
Helper::whereExpression('tx_dlf_libraries') |
|
81
|
|
|
) |
|
82
|
|
|
->setMaxResults(1) |
|
83
|
|
|
->execute(); |
|
84
|
|
|
|
|
85
|
|
|
$allResults = $result->fetchAll(); |
|
86
|
|
|
|
|
87
|
|
|
if (count($allResults) === 1) { |
|
88
|
|
|
$resArray = $allResults[0]; |
|
89
|
|
|
$channel->appendChild($rss->createElement('copyright', htmlspecialchars($resArray['label'], ENT_NOQUOTES, 'UTF-8'))); |
|
90
|
|
|
} |
|
91
|
|
|
$channel->appendChild($rss->createElement('pubDate', date('r', $GLOBALS['EXEC_TIME']))); |
|
92
|
|
|
$channel->appendChild($rss->createElement('generator', htmlspecialchars($this->settings['useragent'], ENT_NOQUOTES, 'UTF-8'))); |
|
93
|
|
|
// Add item elements. |
|
94
|
|
|
if ( |
|
95
|
|
|
!$this->settings['excludeOther'] |
|
96
|
|
|
|| empty($requestData['collection']) |
|
97
|
|
|
|| GeneralUtility::inList($this->settings['collections'], $requestData['collection']) |
|
98
|
|
|
) { |
|
99
|
|
|
$additionalWhere = ''; |
|
100
|
|
|
// Check for pre-selected collections. |
|
101
|
|
|
if (!empty($requestData['collection'])) { |
|
102
|
|
|
$additionalWhere = 'tx_dlf_collections.uid=' . (int)$requestData['collection']; |
|
103
|
|
|
} elseif (!empty($this->settings['collections'])) { |
|
104
|
|
|
$additionalWhere = 'tx_dlf_collections.uid IN (' . implode(',', GeneralUtility::intExplode(',', $this->settings['collections'])) . ')'; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
108
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
|
109
|
|
|
|
|
110
|
|
|
$result = $queryBuilder |
|
111
|
|
|
->select( |
|
112
|
|
|
'tx_dlf_documents.uid AS uid', |
|
113
|
|
|
'tx_dlf_documents.partof AS partof', |
|
114
|
|
|
'tx_dlf_documents.title AS title', |
|
115
|
|
|
'tx_dlf_documents.volume AS volume', |
|
116
|
|
|
'tx_dlf_documents.author AS author', |
|
117
|
|
|
'tx_dlf_documents.record_id AS guid', |
|
118
|
|
|
'tx_dlf_documents.tstamp AS tstamp', |
|
119
|
|
|
'tx_dlf_documents.crdate AS crdate' |
|
120
|
|
|
) |
|
121
|
|
|
->from('tx_dlf_documents') |
|
122
|
|
|
->join( |
|
123
|
|
|
'tx_dlf_documents', |
|
124
|
|
|
'tx_dlf_relations', |
|
125
|
|
|
'tx_dlf_documents_collections_mm', |
|
126
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_local')) |
|
127
|
|
|
) |
|
128
|
|
|
->join( |
|
129
|
|
|
'tx_dlf_documents_collections_mm', |
|
130
|
|
|
'tx_dlf_collections', |
|
131
|
|
|
'tx_dlf_collections', |
|
132
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_foreign')) |
|
133
|
|
|
) |
|
134
|
|
|
->where( |
|
135
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.pid', $queryBuilder->createNamedParameter((int) $this->settings['pages'])), |
|
136
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents_collections_mm.ident', $queryBuilder->createNamedParameter('docs_colls')), |
|
137
|
|
|
$queryBuilder->expr()->eq('tx_dlf_collections.pid', $queryBuilder->createNamedParameter((int) $this->settings['pages'])), |
|
138
|
|
|
$additionalWhere, |
|
139
|
|
|
Helper::whereExpression('tx_dlf_documents'), |
|
140
|
|
|
Helper::whereExpression('tx_dlf_collections') |
|
141
|
|
|
) |
|
142
|
|
|
->groupBy('tx_dlf_documents.uid') |
|
143
|
|
|
->orderBy('tx_dlf_documents.tstamp', 'DESC') |
|
144
|
|
|
->setMaxResults((int) $this->settings['limit']) |
|
145
|
|
|
->execute(); |
|
146
|
|
|
$rows = $result->fetchAll(); |
|
147
|
|
|
|
|
148
|
|
|
if (count($rows) > 0) { |
|
149
|
|
|
// Add each record as item element. |
|
150
|
|
|
foreach ($rows as $resArray) { |
|
151
|
|
|
$item = $rss->createElement('item'); |
|
152
|
|
|
$title = ''; |
|
153
|
|
|
// Get title of superior document. |
|
154
|
|
|
if ((empty($resArray['title']) || !empty($this->settings['prependSuperiorTitle'])) |
|
155
|
|
|
&& !empty($resArray['partof']) |
|
156
|
|
|
) { |
|
157
|
|
|
$superiorTitle = Document::getTitle($resArray['partof'], true); |
|
|
|
|
|
|
158
|
|
|
if (!empty($superiorTitle)) { |
|
159
|
|
|
$title .= '[' . $superiorTitle . ']'; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
// Get title of document. |
|
163
|
|
|
if (!empty($resArray['title'])) { |
|
164
|
|
|
$title .= ' ' . $resArray['title']; |
|
165
|
|
|
} |
|
166
|
|
|
// Set default title if empty. |
|
167
|
|
|
if (empty($title)) { |
|
168
|
|
|
$title = $this->pi_getLL('noTitle'); |
|
169
|
|
|
} |
|
170
|
|
|
// Append volume information. |
|
171
|
|
|
if (!empty($resArray['volume'])) { |
|
172
|
|
|
$title .= ', ' . $this->pi_getLL('volume') . ' ' . $resArray['volume']; |
|
173
|
|
|
} |
|
174
|
|
|
// Is this document new or updated? |
|
175
|
|
|
if ($resArray['crdate'] == $resArray['tstamp']) { |
|
176
|
|
|
$title = $this->pi_getLL('new') . ' ' . trim($title); |
|
177
|
|
|
} else { |
|
178
|
|
|
$title = $this->pi_getLL('update') . ' ' . trim($title); |
|
179
|
|
|
} |
|
180
|
|
|
$item->appendChild($rss->createElement('title', htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8'))); |
|
181
|
|
|
// Add link. |
|
182
|
|
|
$linkConf = [ |
|
183
|
|
|
'parameter' => $this->settings['targetPid'], |
|
184
|
|
|
'forceAbsoluteUrl' => 1, |
|
185
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->settings['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
|
186
|
|
|
'additionalParams' => GeneralUtility::implodeArrayForUrl($this->prefixId, ['id' => $resArray['uid']], '', true, false) |
|
187
|
|
|
]; |
|
188
|
|
|
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */ |
|
189
|
|
|
$cObj = $this->configurationManager->getContentObject(); |
|
190
|
|
|
|
|
191
|
|
|
$item->appendChild($rss->createElement('link', htmlspecialchars($cObj->typoLink_URL($linkConf), ENT_NOQUOTES, 'UTF-8'))); |
|
192
|
|
|
// Add author if applicable. |
|
193
|
|
|
if (!empty($resArray['author'])) { |
|
194
|
|
|
$item->appendChild($rss->createElement('author', htmlspecialchars($resArray['author'], ENT_NOQUOTES, 'UTF-8'))); |
|
195
|
|
|
} |
|
196
|
|
|
// Add online publication date. |
|
197
|
|
|
$item->appendChild($rss->createElement('pubDate', date('r', $resArray['crdate']))); |
|
198
|
|
|
// Add internal record identifier. |
|
199
|
|
|
$item->appendChild($rss->createElement('guid', htmlspecialchars($resArray['guid'], ENT_NOQUOTES, 'UTF-8'))); |
|
200
|
|
|
$channel->appendChild($item); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
$root->appendChild($channel); |
|
205
|
|
|
// Build XML output. |
|
206
|
|
|
$rss->appendChild($root); |
|
207
|
|
|
$content = $rss->saveXML(); |
|
208
|
|
|
// Clean output buffer. |
|
209
|
|
|
ob_end_clean(); |
|
210
|
|
|
// Send headers. |
|
211
|
|
|
header('HTTP/1.1 200 OK'); |
|
212
|
|
|
header('Cache-Control: no-cache'); |
|
213
|
|
|
header('Content-Length: ' . strlen($content)); |
|
214
|
|
|
header('Content-Type: application/rss+xml; charset=utf-8'); |
|
215
|
|
|
header('Date: ' . date('r', $GLOBALS['EXEC_TIME'])); |
|
216
|
|
|
header('Expires: ' . date('r', $GLOBALS['EXEC_TIME'])); |
|
217
|
|
|
echo $content; |
|
218
|
|
|
exit; |
|
|
|
|
|
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
protected function pi_getLL($label) |
|
222
|
|
|
{ |
|
223
|
|
|
return $GLOBALS['TSFE']->sL('LLL:EXT:dlf/Resources/Private/Language/Feeds.xml:' . $label); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths