We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 20 |
Paths | 28 |
Total Lines | 163 |
Code Lines | 114 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | public function main($content, $conf) |
||
43 | { |
||
44 | $this->init($conf); |
||
45 | // Don't cache the output. |
||
46 | $this->setCache(false); |
||
47 | // Create XML document. |
||
48 | $rss = new \DOMDocument('1.0', 'utf-8'); |
||
49 | // Add mandatory root element. |
||
50 | $root = $rss->createElement('rss'); |
||
51 | $root->setAttribute('version', '2.0'); |
||
52 | // Add channel element. |
||
53 | $channel = $rss->createElement('channel'); |
||
54 | $channel->appendChild($rss->createElement('title', htmlspecialchars($this->conf['title'], ENT_NOQUOTES, 'UTF-8'))); |
||
55 | $channel->appendChild($rss->createElement('link', htmlspecialchars(GeneralUtility::locationHeaderUrl($this->pi_linkTP_keepPIvars_url()), ENT_NOQUOTES, 'UTF-8'))); |
||
56 | if (!empty($this->conf['description'])) { |
||
57 | $channel->appendChild($rss->createElement('description', htmlspecialchars($this->conf['description'], ENT_QUOTES, 'UTF-8'))); |
||
58 | } |
||
59 | |||
60 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
61 | ->getQueryBuilderForTable('tx_dlf_structures'); |
||
62 | |||
63 | $result = $queryBuilder |
||
64 | ->select('tx_dlf_libraries.label AS label') |
||
65 | ->from('tx_dlf_libraries') |
||
66 | ->where( |
||
67 | $queryBuilder->expr()->eq('tx_dlf_libraries.pid', intval($this->conf['pages'])), |
||
68 | $queryBuilder->expr()->eq('tx_dlf_libraries.uid', intval($this->conf['library'])), |
||
69 | Helper::whereExpression('tx_dlf_libraries') |
||
70 | ) |
||
71 | ->setMaxResults(1) |
||
72 | ->execute(); |
||
73 | |||
74 | $allResults = $result->fetchAll(); |
||
75 | |||
76 | if (count($allResults) === 1) { |
||
77 | $resArray = $allResults[0]; |
||
78 | $channel->appendChild($rss->createElement('copyright', htmlspecialchars($resArray['label'], ENT_NOQUOTES, 'UTF-8'))); |
||
79 | } |
||
80 | $channel->appendChild($rss->createElement('pubDate', date('r', $GLOBALS['EXEC_TIME']))); |
||
81 | $channel->appendChild($rss->createElement('generator', htmlspecialchars($this->conf['useragent'], ENT_NOQUOTES, 'UTF-8'))); |
||
82 | // Add item elements. |
||
83 | if ( |
||
84 | !$this->conf['excludeOther'] |
||
85 | || empty($this->piVars['collection']) |
||
86 | || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->conf['collections'], $this->piVars['collection']) |
||
87 | ) { |
||
88 | $additionalWhere = ''; |
||
89 | // Check for pre-selected collections. |
||
90 | if (!empty($this->piVars['collection'])) { |
||
91 | $additionalWhere = 'tx_dlf_collections.uid=' . intval($this->piVars['collection']); |
||
92 | } elseif (!empty($this->conf['collections'])) { |
||
93 | $additionalWhere = 'tx_dlf_collections.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ')'; |
||
94 | } |
||
95 | |||
96 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
97 | ->getQueryBuilderForTable('tx_dlf_documents'); |
||
98 | |||
99 | $result = $queryBuilder |
||
100 | ->select( |
||
101 | 'tx_dlf_documents.uid AS uid', |
||
102 | 'tx_dlf_documents.partof AS partof', |
||
103 | 'tx_dlf_documents.title AS title', |
||
104 | 'tx_dlf_documents.volume AS volume', |
||
105 | 'tx_dlf_documents.author AS author', |
||
106 | 'tx_dlf_documents.record_id AS guid', |
||
107 | 'tx_dlf_documents.tstamp AS tstamp', |
||
108 | 'tx_dlf_documents.crdate AS crdate' |
||
109 | ) |
||
110 | ->from('tx_dlf_documents') |
||
111 | ->join( |
||
112 | 'tx_dlf_documents', |
||
113 | 'tx_dlf_relations', |
||
114 | 'tx_dlf_documents_collections_mm', |
||
115 | $queryBuilder->expr()->eq('tx_dlf_documents.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_local')) |
||
116 | ) |
||
117 | ->join( |
||
118 | 'tx_dlf_documents_collections_mm', |
||
119 | 'tx_dlf_collections', |
||
120 | 'tx_dlf_collections', |
||
121 | $queryBuilder->expr()->eq('tx_dlf_collections.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_foreign')) |
||
122 | ) |
||
123 | ->where( |
||
124 | $queryBuilder->expr()->eq('tx_dlf_documents.pid', $queryBuilder->createNamedParameter((int)$this->conf['pages'])), |
||
125 | $queryBuilder->expr()->eq('tx_dlf_documents_collections_mm.ident', $queryBuilder->createNamedParameter('docs_colls')), |
||
126 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', $queryBuilder->createNamedParameter((int)$this->conf['pages'])), |
||
127 | $additionalWhere, |
||
128 | Helper::whereExpression('tx_dlf_documents'), |
||
129 | Helper::whereExpression('tx_dlf_collections'), |
||
130 | ) |
||
131 | ->groupBy('tx_dlf_documents.uid') |
||
132 | ->orderBy('tx_dlf_documents.tstamp', 'DESC') |
||
133 | ->setMaxResults((int)$this->conf['limit']) |
||
134 | ->execute(); |
||
135 | $rows = $result->fetchAll(); |
||
136 | |||
137 | if (count($rows) > 0) { |
||
138 | // Add each record as item element. |
||
139 | foreach ($rows as $resArray) { |
||
140 | $item = $rss->createElement('item'); |
||
141 | $title = ''; |
||
142 | // Get title of superior document. |
||
143 | if ((empty($resArray['title']) || !empty($this->conf['prependSuperiorTitle'])) |
||
144 | && !empty($resArray['partof']) |
||
145 | ) { |
||
146 | $superiorTitle = Document::getTitle($resArray['partof'], true); |
||
147 | if (!empty($superiorTitle)) { |
||
148 | $title .= '[' . $superiorTitle . ']'; |
||
149 | } |
||
150 | } |
||
151 | // Get title of document. |
||
152 | if (!empty($resArray['title'])) { |
||
153 | $title .= ' ' . $resArray['title']; |
||
154 | } |
||
155 | // Set default title if empty. |
||
156 | if (empty($title)) { |
||
157 | $title = $this->pi_getLL('noTitle'); |
||
158 | } |
||
159 | // Append volume information. |
||
160 | if (!empty($resArray['volume'])) { |
||
161 | $title .= ', ' . $this->pi_getLL('volume') . ' ' . $resArray['volume']; |
||
162 | } |
||
163 | // Is this document new or updated? |
||
164 | if ($resArray['crdate'] == $resArray['tstamp']) { |
||
165 | $title = $this->pi_getLL('new') . ' ' . trim($title); |
||
166 | } else { |
||
167 | $title = $this->pi_getLL('update') . ' ' . trim($title); |
||
168 | } |
||
169 | $item->appendChild($rss->createElement('title', htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8'))); |
||
170 | // Add link. |
||
171 | $linkConf = [ |
||
172 | 'parameter' => $this->conf['targetPid'], |
||
173 | 'forceAbsoluteUrl' => 1, |
||
174 | 'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
||
175 | 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, ['id' => $resArray['uid']], '', true, false) |
||
176 | ]; |
||
177 | $item->appendChild($rss->createElement('link', htmlspecialchars($this->cObj->typoLink_URL($linkConf), ENT_NOQUOTES, 'UTF-8'))); |
||
178 | // Add author if applicable. |
||
179 | if (!empty($resArray['author'])) { |
||
180 | $item->appendChild($rss->createElement('author', htmlspecialchars($resArray['author'], ENT_NOQUOTES, 'UTF-8'))); |
||
181 | } |
||
182 | // Add online publication date. |
||
183 | $item->appendChild($rss->createElement('pubDate', date('r', $resArray['crdate']))); |
||
184 | // Add internal record identifier. |
||
185 | $item->appendChild($rss->createElement('guid', htmlspecialchars($resArray['guid'], ENT_NOQUOTES, 'UTF-8'))); |
||
186 | $channel->appendChild($item); |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | $root->appendChild($channel); |
||
191 | // Build XML output. |
||
192 | $rss->appendChild($root); |
||
193 | $content = $rss->saveXML(); |
||
194 | // Clean output buffer. |
||
195 | ob_end_clean(); |
||
196 | // Send headers. |
||
197 | header('HTTP/1.1 200 OK'); |
||
198 | header('Cache-Control: no-cache'); |
||
199 | header('Content-Length: ' . strlen($content)); |
||
200 | header('Content-Type: application/rss+xml; charset=utf-8'); |
||
201 | header('Date: ' . date('r', $GLOBALS['EXEC_TIME'])); |
||
202 | header('Expires: ' . date('r', $GLOBALS['EXEC_TIME'])); |
||
203 | echo $content; |
||
204 | exit; |
||
205 | } |
||
207 |