| Conditions | 39 |
| Paths | > 20000 |
| Total Lines | 214 |
| Code Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 193 | protected function printMetadata(array $metadataArray) { |
||
| 194 | |||
| 195 | // Load template file. |
||
| 196 | if (!empty($this->conf['templateFile'])) { |
||
| 197 | |||
| 198 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###'); |
||
| 199 | |||
| 200 | } else { |
||
| 201 | |||
| 202 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/metadata/template.tmpl'), '###TEMPLATE###'); |
||
| 203 | |||
| 204 | } |
||
| 205 | |||
| 206 | $output = ''; |
||
| 207 | |||
| 208 | $subpart['block'] = $this->cObj->getSubpart($this->template, '###BLOCK###'); |
||
| 209 | |||
| 210 | // Get list of metadata to show. |
||
| 211 | $metaList = array (); |
||
| 212 | |||
| 213 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 214 | 'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.wrap AS wrap', |
||
| 215 | 'tx_dlf_metadata', |
||
| 216 | 'tx_dlf_metadata.pid='.intval($this->conf['pages']).tx_dlf_helper::whereClause('tx_dlf_metadata').' AND (sys_language_uid IN (-1,0) OR (sys_language_uid = '.$GLOBALS['TSFE']->sys_language_uid.' AND l18n_parent = 0))', |
||
| 217 | '', |
||
| 218 | 'tx_dlf_metadata.sorting', |
||
| 219 | '' |
||
| 220 | ); |
||
| 221 | |||
| 222 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 223 | |||
| 224 | if (is_array($resArray) && $resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) { |
||
| 225 | |||
| 226 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_metadata', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 227 | |||
| 228 | } |
||
| 229 | |||
| 230 | if ($resArray) { |
||
| 231 | // get correct language uid for translated realurl link |
||
| 232 | $link_uid = ($resArray['_LOCALIZED_UID']) ? $resArray['_LOCALIZED_UID'] : $resArray['uid']; |
||
| 233 | |||
| 234 | // do stuff with the row entry data like built HTML or prepare further usage |
||
| 235 | if ($this->conf['showFull'] || $resArray['is_listed']) { |
||
| 236 | |||
| 237 | $metaList[$resArray['index_name']] = array ( |
||
| 238 | 'wrap' => $resArray['wrap'], |
||
| 239 | 'label' => tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages']) |
||
| 240 | ); |
||
| 241 | |||
| 242 | } |
||
| 243 | |||
| 244 | } |
||
| 245 | |||
| 246 | } |
||
| 247 | |||
| 248 | // Get list of collections to show. |
||
| 249 | $collList = array (); |
||
| 250 | |||
| 251 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 252 | 'tx_dlf_collections.index_name AS index_name', |
||
| 253 | 'tx_dlf_collections', |
||
| 254 | 'tx_dlf_collections.pid='.intval($this->conf['pages']).tx_dlf_helper::whereClause('tx_dlf_collections'), |
||
| 255 | '', |
||
| 256 | '', |
||
| 257 | '' |
||
| 258 | ); |
||
| 259 | |||
| 260 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 261 | |||
| 262 | $collList[] = $resArray['index_name']; |
||
| 263 | |||
| 264 | } |
||
| 265 | |||
| 266 | // Save original data array. |
||
| 267 | $cObjData = $this->cObj->data; |
||
| 268 | |||
| 269 | // Parse the metadata arrays. |
||
| 270 | foreach ($metadataArray as $metadata) { |
||
| 271 | |||
| 272 | $markerArray['###METADATA###'] = ''; |
||
| 273 | |||
| 274 | // Reset content object's data array. |
||
| 275 | $this->cObj->data = $cObjData; |
||
| 276 | |||
| 277 | // Load all the metadata values into the content object's data array. |
||
| 278 | foreach ($metadata as $index_name => $value) { |
||
| 279 | |||
| 280 | if (is_array($value)) { |
||
| 281 | |||
| 282 | $this->cObj->data[$index_name] = implode($this->conf['separator'], $value); |
||
| 283 | |||
| 284 | } else { |
||
| 285 | |||
| 286 | $this->cObj->data[$index_name] = $value; |
||
| 287 | |||
| 288 | } |
||
| 289 | |||
| 290 | } |
||
| 291 | |||
| 292 | // Process each metadate. |
||
| 293 | foreach ($metaList as $index_name => $metaConf) { |
||
| 294 | |||
| 295 | $parsedValue = ''; |
||
| 296 | |||
| 297 | $fieldwrap = $this->parseTS($metaConf['wrap']); |
||
| 298 | |||
| 299 | do { |
||
| 300 | |||
| 301 | $value = @array_shift($metadata[$index_name]); |
||
| 302 | |||
| 303 | if ($index_name == 'title') { |
||
| 304 | |||
| 305 | // Get title of parent document if needed. |
||
| 306 | if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) { |
||
| 307 | |||
| 308 | $superiorTitle = tx_dlf_document::getTitle($this->doc->parentId, TRUE); |
||
| 309 | |||
| 310 | if (!empty($superiorTitle)) { |
||
| 311 | |||
| 312 | $value = '['.$superiorTitle.']'; |
||
| 313 | |||
| 314 | } |
||
| 315 | |||
| 316 | } |
||
| 317 | |||
| 318 | if (!empty($value)) { |
||
| 319 | |||
| 320 | $value = htmlspecialchars($value); |
||
| 321 | |||
| 322 | // Link title to pageview. |
||
| 323 | if ($this->conf['linkTitle'] && $metadata['_id']) { |
||
| 324 | |||
| 325 | $details = $this->doc->getLogicalStructure($metadata['_id']); |
||
| 326 | |||
| 327 | $value = $this->pi_linkTP($value, array ($this->prefixId => array ('id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1))), TRUE, $this->conf['targetPid']); |
||
| 328 | |||
| 329 | } |
||
| 330 | |||
| 331 | } |
||
| 332 | |||
| 333 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 334 | |||
| 335 | // Translate name of holding library. |
||
| 336 | $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages'])); |
||
| 337 | |||
| 338 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 339 | |||
| 340 | // Translate document type. |
||
| 341 | $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages'])); |
||
| 342 | |||
| 343 | } elseif ($index_name == 'collection' && !empty($value)) { |
||
| 344 | |||
| 345 | // Check if collections isn't hidden. |
||
| 346 | if (in_array($value, $collList)) { |
||
| 347 | |||
| 348 | // Translate collection. |
||
| 349 | $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_collections', $this->conf['pages'])); |
||
| 350 | |||
| 351 | } else { |
||
| 352 | |||
| 353 | $value = ''; |
||
| 354 | |||
| 355 | } |
||
| 356 | |||
| 357 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 358 | |||
| 359 | // Translate ISO 639 language code. |
||
| 360 | $value = htmlspecialchars(tx_dlf_helper::getLanguageName($value)); |
||
| 361 | |||
| 362 | } elseif (!empty($value)) { |
||
| 363 | |||
| 364 | // Sanitize value for output. |
||
| 365 | $value = htmlspecialchars($value); |
||
| 366 | |||
| 367 | } |
||
| 368 | |||
| 369 | // Hook for getting a customized value (requested by SBB). |
||
| 370 | foreach ($this->hookObjects as $hookObj) { |
||
| 371 | |||
| 372 | if (method_exists($hookObj, 'printMetadata_customizeMetadata')) { |
||
| 373 | |||
| 374 | $hookObj->printMetadata_customizeMetadata($value); |
||
| 375 | |||
| 376 | } |
||
| 377 | |||
| 378 | } |
||
| 379 | |||
| 380 | $value = $this->cObj->stdWrap($value, $fieldwrap['value.']); |
||
| 381 | |||
| 382 | if (!empty($value)) { |
||
| 383 | |||
| 384 | $parsedValue .= $value; |
||
| 385 | |||
| 386 | } |
||
| 387 | |||
| 388 | } while (count($metadata[$index_name])); |
||
| 389 | |||
| 390 | if (!empty($parsedValue)) { |
||
| 391 | |||
| 392 | $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']); |
||
| 393 | |||
| 394 | $field .= $parsedValue; |
||
| 395 | |||
| 396 | $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']); |
||
| 397 | |||
| 398 | } |
||
| 399 | |||
| 400 | } |
||
| 401 | |||
| 402 | $output .= $this->cObj->substituteMarkerArray($subpart['block'], $markerArray); |
||
| 403 | |||
| 404 | } |
||
| 405 | |||
| 406 | return $this->cObj->substituteSubpart($this->template, '###BLOCK###', $output, TRUE); |
||
| 407 | |||
| 411 |