Fix Bug #962301: Refactor the metadata handling

This commit is contained in:
Sebastian Meyer 2012-03-23 17:19:52 +01:00
parent d5fcfd23bf
commit 509ab77f1b
5 changed files with 62 additions and 12 deletions

View File

@ -631,20 +631,40 @@ class tx_dlf_document {
''
);
// We need a DOMDocument here, because SimpleXML doesn't support XPath functions properly.
$_domNode = dom_import_simplexml($this->dmdSec[$_dmdId]['xml']);
$_domXPath = new DOMXPath($_domNode->ownerDocument);
// OK, now make the XPath queries.
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) {
if ($resArray['xpath'] && ($_values = $this->dmdSec[$_dmdId]['xml']->xpath($resArray['xpath']))) {
if ($resArray['xpath'] && ($_values = $_domXPath->evaluate($resArray['xpath'], $_domNode))) {
$_metadata[$resArray['index_name']] = array ();
// Check if the XPath query returned a node list or typed result.
if ($_values instanceof DOMNodeList) {
foreach ($_values as $_value) {
if ($_values->length > 0) {
$_metadata[$resArray['index_name']][] = (string) $_value;
$_metadata[$resArray['index_name']] = array ();
foreach ($_values as $_value) {
$_metadata[$resArray['index_name']][] = trim($_value->nodeValue);
}
}
} else {
$_metadata[$resArray['index_name']][0] = trim((string) $_values);
}
}
// Set default value if applicable.
if (empty($_metadata[$resArray['index_name']][0]) && $resArray['default_value']) {
$_metadata[$resArray['index_name']] = array ($resArray['default_value']);

View File

@ -286,31 +286,29 @@ class tx_dlf_helper {
*/
public static function getLanguageName($code) {
$code = strtolower(trim($code));
$_code = strtolower(trim($code));
if (preg_match('/^[a-z]{3}$/', $code)) {
if (preg_match('/^[a-z]{3}$/', $_code)) {
$iso639 = $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath(self::$extKey).'/lib/ISO-639/iso-639-2b.xml', FALSE, TRUE);
} elseif (preg_match('/^[a-z]{2}$/', $code)) {
} elseif (preg_match('/^[a-z]{2}$/', $_code)) {
$iso639 = $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath(self::$extKey).'/lib/ISO-639/iso-639-1.xml', FALSE, TRUE);
} else {
trigger_error('Invalid language code '.strtoupper($code), E_USER_WARNING);
return $code;
}
if (!empty($iso639['default'][$code])) {
if (!empty($iso639['default'][$_code])) {
return $GLOBALS['LANG']->getLLL($code, $iso639, FALSE);
return $GLOBALS['LANG']->getLLL($_code, $iso639, FALSE);
} else {
trigger_error('Language code '.strtoupper($code).' not found', E_USER_WARNING);
trigger_error('Language code "'.$code.'" not found', E_USER_WARNING);
return $code;

View File

@ -202,11 +202,25 @@ class tx_dlf_metadata extends tx_dlf_plugin {
}
// Save original data array.
$cObjData = $this->cObj->data;
// Parse the metadata arrays.
foreach ($metadata as $_metadata) {
$markerArray['###METADATA###'] = '';
// Reset content object's data array.
$this->cObj->data = $cObjData;
// Load all the metadata values into the content object's data array.
foreach ($_metadata as $_index_name => $_value) {
$this->cObj->data[$_index_name] = implode($this->conf['separator'], $_value);
}
// Process each metadate.
foreach ($metaList as $_index_name => $_wrap) {
$hasValue = FALSE;
@ -246,6 +260,11 @@ class tx_dlf_metadata extends tx_dlf_plugin {
$_value = htmlspecialchars(tx_dlf_helper::translate($_value, 'tx_dlf_libraries', $this->conf['pages']));
// Translate ISO 639 language code.
} elseif ($_index_name == 'language' && !empty($_value)) {
$_value = htmlspecialchars(tx_dlf_helper::getLanguageName($_value));
} elseif (!empty($_value)) {
$_value = htmlspecialchars($_value);

View File

@ -96,6 +96,17 @@
</config>
</TCEforms>
</rootline>
<separator>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/metadata/locallang.xml:tt_content.pi_flexform.separator</label>
<config>
<type>input</type>
<eval>required,trim</eval>
<default>#</default>
</config>
</TCEforms>
</separator>
<templateFile>
<TCEforms>
<exclude>1</exclude>

View File

@ -10,6 +10,7 @@
<label index="tt_content.pi_flexform.solrcore">Solr Core</label>
<label index="tt_content.pi_flexform.limit">Maximum results</label>
<label index="tt_content.pi_flexform.targetPid">Target page (with "DLF: List View" plugin)</label>
<label index="tt_content.pi_flexform.separator">Separator for metadata in TS array</label>
<label index="tt_content.pi_flexform.templateFile">Template file</label>
<label index="label.query">Search for:</label>
<label index="label.submit">Search</label>
@ -21,6 +22,7 @@
<label index="tt_content.pi_flexform.solrcore">Solr Kern</label>
<label index="tt_content.pi_flexform.limit">Maximale Ergebnismenge</label>
<label index="tt_content.pi_flexform.targetPid">Zielseite (mit Plugin "DLF: Listenansicht")</label>
<label index="tt_content.pi_flexform.separator">Trennzeichen für Metadaten im TS-Array</label>
<label index="tt_content.pi_flexform.templateFile">HTML-Template</label>
<label index="label.query">Suchen nach:</label>
<label index="label.submit">Suchen</label>