diff --git a/Classes/Cli/CommandLineIndexer.php b/Classes/Cli/CommandLineIndexer.php
index 2aff843e..edfa8311 100644
--- a/Classes/Cli/CommandLineIndexer.php
+++ b/Classes/Cli/CommandLineIndexer.php
@@ -22,8 +22,7 @@ use Kitodo\Dlf\Common\Helper;
* @subpackage dlf
* @access public
*/
-class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineController
-{
+class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineController {
/**
* This is the return code
*
@@ -39,10 +38,8 @@ class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineControlle
*
* @return integer Return Code
*/
- public function main()
- {
- switch ((string) $this->cli_args['_DEFAULT'][1])
- {
+ public function main() {
+ switch ((string) $this->cli_args['_DEFAULT'][1]) {
// (Re-)Index a single document.
case 'index':
// Add command line arguments.
@@ -52,32 +49,26 @@ class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineControlle
// Check the command line arguments.
$this->cli_validateArgs();
if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-doc'][0])
- && !\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($this->cli_args['-doc'][0]))
- {
+ && !\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($this->cli_args['-doc'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-doc'][0].'" is not a valid document UID or URL.'.LF, TRUE);
$this->return = 1;
}
- if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-pid'][0]))
- {
+ if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-pid'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-pid'][0].'" is not a valid page UID.'.LF, TRUE);
$this->return = 1;
}
- if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-core'][0]))
- {
+ if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-core'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-core'][0].'" is not a valid core UID.'.LF, TRUE);
$this->return = 1;
}
- if ($this->return > 0)
- {
+ if ($this->return > 0) {
break;
}
// Get the document...
$doc = Document::getInstance($this->cli_args['-doc'][0], $this->cli_args['-pid'][0], TRUE);
- if ($doc->ready)
- {
+ if ($doc->ready) {
// ...and save it to the database...
- if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0])))
- {
+ if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0]))) {
$this->cli_echo('ERROR: Document "'.$this->cli_args['-doc'][0].'" not saved and indexed.'.LF, TRUE);
$this->return = 1;
}
@@ -94,18 +85,15 @@ class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineControlle
$this->cli_options[] = ['-core UID', 'UID of the Solr core the document should be added to.'];
// Check the command line arguments.
$this->cli_validateArgs();
- if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-coll'][0]))
- {
+ if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-coll'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-coll'][0].'" is not a valid collection UID.'.LF, TRUE);
$this->return = 1;
}
- if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-pid'][0]))
- {
+ if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-pid'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-pid'][0].'" is not a valid page UID.'.LF, TRUE);
$this->return = 1;
}
- if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-core'][0]))
- {
+ if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->cli_args['-core'][0])) {
$this->cli_echo('ERROR: "'.$this->cli_args['-core'][0].'" is not a valid core UID.'.LF, TRUE);
$this->return = 1;
}
@@ -127,15 +115,12 @@ class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineControlle
'',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Get the document...
$doc = Document::getInstance($resArray['uid'], $this->cli_args['-pid'][0], TRUE);
- if ($doc->ready)
- {
+ if ($doc->ready) {
// ...and save it to the database...
- if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0])))
- {
+ if (!$doc->save(intval($this->cli_args['-pid'][0]), intval($this->cli_args['-core'][0]))) {
$this->cli_echo('ERROR: Document "'.$resArray['uid'].'" not saved and indexed.'.LF, TRUE);
$this->return = 1;
}
@@ -161,8 +146,7 @@ class CommandLineIndexer extends \TYPO3\CMS\Core\Controller\CommandLineControlle
*
* @return void
*/
- public function __construct()
- {
+ public function __construct() {
// Run parent constructor.
parent::__construct();
// Set basic information about the script.
diff --git a/Classes/Common/AbstractPlugin.php b/Classes/Common/AbstractPlugin.php
index 1e548eb6..04919664 100644
--- a/Classes/Common/AbstractPlugin.php
+++ b/Classes/Common/AbstractPlugin.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @access public
* @abstract
*/
-abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
-{
+abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
public $extKey = 'dlf';
public $prefixId = 'tx_dlf';
public $scriptRelPath = 'Classes/Common/AbstractPlugin.php';
@@ -54,10 +53,8 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return void
*/
- protected function getTemplate($part = '###TEMPLATE###')
- {
- if (!empty($this->conf['templateFile']))
- {
+ protected function getTemplate($part = '###TEMPLATE###') {
+ if (!empty($this->conf['templateFile'])) {
// Load template file from configuration.
$this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), $part);
} else {
@@ -76,43 +73,36 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return void
*/
- protected function init(array $conf)
- {
+ protected function init(array $conf) {
// Read FlexForm configuration.
$flexFormConf = [];
$this->cObj->readFlexformIntoConf($this->cObj->data['pi_flexform'], $flexFormConf);
- if (!empty($flexFormConf))
- {
+ if (!empty($flexFormConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($flexFormConf, $conf);
}
// Read plugin TS configuration.
$pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][get_class($this).'.'];
- if (is_array($pluginConf))
- {
+ if (is_array($pluginConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConf, $conf);
}
// Read old plugin TS configuration.
$oldPluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_'.strtolower(get_class($this)).'.'];
- if (is_array($oldPluginConf))
- {
+ if (is_array($oldPluginConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($oldPluginConf, $conf);
}
// Read general TS configuration.
$generalConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.'];
- if (is_array($generalConf))
- {
+ if (is_array($generalConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($generalConf, $conf);
}
// Read extension configuration.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
- if (is_array($extConf))
- {
+ if (is_array($extConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($extConf, $conf);
}
// Read TYPO3_CONF_VARS configuration.
$varsConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey];
- if (is_array($varsConf))
- {
+ if (is_array($varsConf)) {
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($varsConf, $conf);
}
$this->conf = $conf;
@@ -129,12 +119,10 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return void
*/
- protected function loadDocument()
- {
+ protected function loadDocument() {
// Check for required variable.
if (!empty($this->piVars['id'])
- && !empty($this->conf['pages']))
- {
+ && !empty($this->conf['pages'])) {
// Should we exclude documents from other pages than $this->conf['pages']?
$pid = (!empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0);
// Get instance of \Kitodo\Dlf\Common\Document.
@@ -142,16 +130,14 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
if (!$this->doc->ready) {
// Destroy the incomplete object.
$this->doc = NULL;
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\AbstractPlugin->loadDocument()] Failed to load document with UID "'.$this->piVars['id'].'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
} else {
// Set configuration PID.
$this->doc->cPid = $this->conf['pages'];
}
- } elseif (!empty($this->piVars['recordId']))
- {
+ } elseif (!empty($this->piVars['recordId'])) {
// Get UID of document with given record identifier.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid',
@@ -162,8 +148,7 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) {
list ($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
// Set superglobal $_GET array and unset variables to avoid infinite looping.
$_GET[$this->prefixId]['id'] = $this->piVars['id'];
@@ -171,14 +156,12 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
// Try to load document.
$this->loadDocument();
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\AbstractPlugin->loadDocument()] Failed to load document with record ID "'.$this->piVars['recordId'].'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\AbstractPlugin->loadDocument()] Invalid UID "'.$this->piVars['id'].'" or PID "'.$this->conf['pages'].'" for document loading', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -207,14 +190,11 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return string HTML content wrapped, ready to return to the parent object.
*/
- public function pi_wrapInBaseClass($content)
- {
- if (!$GLOBALS['TSFE']->config['config']['disableWrapInBaseClass'])
- {
+ public function pi_wrapInBaseClass($content) {
+ if (!$GLOBALS['TSFE']->config['config']['disableWrapInBaseClass']) {
// Use get_class($this) instead of $this->prefixId for content wrapping because $this->prefixId is the same for all plugins.
$content = '
'.$content.'
';
- if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment'])
- {
+ if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
$content = "\n\n\n\n".$content."\n\n\n\n";
}
}
@@ -230,8 +210,7 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return array The resulting typoscript array
*/
- protected function parseTS($string = '')
- {
+ protected function parseTS($string = '') {
$parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
$parser->parse($string);
return $parser->setup;
@@ -246,15 +225,12 @@ abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
*
* @return void
*/
- protected function setCache($cache = TRUE)
- {
- if ($cache)
- {
+ protected function setCache($cache = TRUE) {
+ if ($cache) {
// Set cObject type to "USER" (default).
$this->pi_USER_INT_obj = FALSE;
$this->pi_checkCHash = TRUE;
- if (count($this->piVars))
- {
+ if (count($this->piVars)) {
// Check cHash or disable caching.
$GLOBALS['TSFE']->reqCHash();
}
diff --git a/Classes/Common/Document.php b/Classes/Common/Document.php
index 77b6abcb..6878edad 100644
--- a/Classes/Common/Document.php
+++ b/Classes/Common/Document.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @subpackage dlf
* @access public
*/
-final class Document
-{
+final class Document {
/**
* This holds the whole XML file as string for serialization purposes
* @see __sleep() / __wakeup()
@@ -350,8 +349,7 @@ final class Document
*
* @return void
*/
- public static function clearRegistry()
- {
+ public static function clearRegistry() {
// Reset registry array.
self::$registry = [];
}
@@ -365,15 +363,12 @@ final class Document
*
* @return string The file's location as URL
*/
- public function getFileLocation($id)
- {
+ public function getFileLocation($id) {
if (!empty($id)
- && ($location = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="'.$id.'"]/mets:FLocat[@LOCTYPE="URL"]')))
- {
+ && ($location = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="'.$id.'"]/mets:FLocat[@LOCTYPE="URL"]'))) {
return (string) $location[0]->attributes('http://www.w3.org/1999/xlink')->href;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getFileLocation('.$id.')] There is no file node with @ID "'.$id.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
@@ -389,15 +384,12 @@ final class Document
*
* @return string The file's MIME type
*/
- public function getFileMimeType($id)
- {
+ public function getFileMimeType($id) {
if (!empty($id)
- && ($mimetype = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="'.$id.'"]/@MIMETYPE')))
- {
+ && ($mimetype = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="'.$id.'"]/@MIMETYPE'))) {
return (string) $mimetype[0];
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getFileMimeType('.$id.')] There is no file node with @ID "'.$id.'" or no MIME type specified', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
@@ -415,21 +407,17 @@ final class Document
*
* @return \Kitodo\Dlf\Common\Document Instance of this class
*/
- public static function &getInstance($uid, $pid = 0, $forceReload = FALSE)
- {
+ public static function &getInstance($uid, $pid = 0, $forceReload = FALSE) {
// Sanitize input.
$pid = max(intval($pid), 0);
- if (!$forceReload)
- {
+ if (!$forceReload) {
$regObj = md5($uid);
if (is_object(self::$registry[$regObj])
- && self::$registry[$regObj] instanceof self)
- {
+ && self::$registry[$regObj] instanceof self) {
// Check if instance has given PID.
if (!$pid
|| !self::$registry[$regObj]->pid
- || $pid == self::$registry[$regObj]->pid)
- {
+ || $pid == self::$registry[$regObj]->pid) {
// Return singleton instance if available.
return self::$registry[$regObj];
}
@@ -437,13 +425,11 @@ final class Document
// Check the user's session...
$sessionData = Helper::loadFromSession(get_called_class());
if (is_object($sessionData[$regObj])
- && $sessionData[$regObj] instanceof self)
- {
+ && $sessionData[$regObj] instanceof self) {
// Check if instance has given PID.
if (!$pid
|| !$sessionData[$regObj]->pid
- || $pid == $sessionData[$regObj]->pid)
- {
+ || $pid == $sessionData[$regObj]->pid) {
// ...and restore registry.
self::$registry[$regObj] = $sessionData[$regObj];
return self::$registry[$regObj];
@@ -454,18 +440,15 @@ final class Document
// Create new instance...
$instance = new self($uid, $pid);
// ...and save it to registry.
- if ($instance->ready)
- {
+ if ($instance->ready) {
self::$registry[md5($instance->uid)] = $instance;
- if ($instance->uid != $instance->location)
- {
+ if ($instance->uid != $instance->location) {
self::$registry[md5($instance->location)] = $instance;
}
// Load extension configuration
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']);
// Save registry to session if caching is enabled.
- if (!empty($extConf['caching']))
- {
+ if (!empty($extConf['caching'])) {
Helper::saveToSession(self::$registry, get_class($instance));
}
}
@@ -483,33 +466,27 @@ final class Document
*
* @return array Array of the element's id, label, type and physical page indexes/mptr link
*/
- public function getLogicalStructure($id, $recursive = FALSE)
- {
+ public function getLogicalStructure($id, $recursive = FALSE) {
$details = [];
// Is the requested logical unit already loaded?
if (!$recursive
- && !empty($this->logicalUnits[$id]))
- {
+ && !empty($this->logicalUnits[$id])) {
// Yes. Return it.
return $this->logicalUnits[$id];
- } elseif (!empty($id))
- {
+ } elseif (!empty($id)) {
// Get specified logical unit.
$divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="'.$id.'"]');
} else {
// Get all logical units at top level.
$divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]/mets:div');
}
- if (!empty($divs))
- {
- if (!$recursive)
- {
+ if (!empty($divs)) {
+ if (!$recursive) {
// Get the details for the first xpath hit.
$details = $this->getLogicalStructureInfo($divs[0]);
} else {
// Walk the logical structure recursively and fill the whole table of contents.
- foreach ($divs as $div)
- {
+ foreach ($divs as $div) {
$this->tableOfContents[] = $this->getLogicalStructureInfo($div, TRUE);
}
}
@@ -527,11 +504,9 @@ final class Document
*
* @return array Array of the element's id, label, type and physical page indexes/mptr link
*/
- protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recursive = FALSE)
- {
+ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recursive = FALSE) {
// Get attributes.
- foreach ($structure->attributes() as $attribute => $value)
- {
+ foreach ($structure->attributes() as $attribute => $value) {
$attributes[$attribute] = (string) $value;
}
// Load plugin configuration.
@@ -546,11 +521,9 @@ final class Document
$details['volume'] = '';
// Set volume information only if no label is set and this is the toplevel structure element.
if (empty($details['label'])
- && $details['id'] == $this->_getToplevelId())
- {
+ && $details['id'] == $this->_getToplevelId()) {
$metadata = $this->getMetadata($details['id']);
- if (!empty($metadata['volume'][0]))
- {
+ if (!empty($metadata['volume'][0])) {
$details['volume'] = $metadata['volume'][0];
}
}
@@ -564,27 +537,22 @@ final class Document
// Get the physical page or external file this structure element is pointing at.
$details['points'] = '';
// Is there a mptr node?
- if (count($structure->children('http://www.loc.gov/METS/')->mptr))
- {
+ if (count($structure->children('http://www.loc.gov/METS/')->mptr)) {
// Yes. Get the file reference.
$details['points'] = (string) $structure->children('http://www.loc.gov/METS/')->mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
} elseif (!empty($this->physicalStructure)
- && array_key_exists($details['id'], $this->smLinks['l2p'])) // Are there any physical elements and is this logical unit linked to at least one of them?
- {
+ && array_key_exists($details['id'], $this->smLinks['l2p'])) { // Are there any physical elements and is this logical unit linked to at least one of them?
$details['points'] = max(intval(array_search($this->smLinks['l2p'][$details['id']][0], $this->physicalStructure, TRUE)), 1);
- if (!empty($this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['files'][$extConf['fileGrpThumbs']]))
- {
+ if (!empty($this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['files'][$extConf['fileGrpThumbs']])) {
$details['thumbnailId'] = $this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['files'][$extConf['fileGrpThumbs']];
}
// Get page/track number of the first page/track related to this structure element.
$details['pagination'] = $this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['orderlabel'];
- } elseif ($details['id'] == $this->_getToplevelId()) // Is this the toplevel structure element?
- {
+ } elseif ($details['id'] == $this->_getToplevelId()) { // Is this the toplevel structure element?
// Yes. Point to itself.
$details['points'] = 1;
if (!empty($this->physicalStructure)
- && !empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$extConf['fileGrpThumbs']]))
- {
+ && !empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$extConf['fileGrpThumbs']])) {
$details['thumbnailId'] = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$extConf['fileGrpThumbs']];
}
}
@@ -592,11 +560,9 @@ final class Document
$details['files'] = [];
$fileUse = $this->_getFileGrps();
// Get the file representations from fileSec node.
- foreach ($structure->children('http://www.loc.gov/METS/')->fptr as $fptr)
- {
+ foreach ($structure->children('http://www.loc.gov/METS/')->fptr as $fptr) {
// Check if file has valid @USE attribute.
- if (!empty($fileUse[(string) $fptr->attributes()->FILEID]))
- {
+ if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) {
$details['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID;
}
}
@@ -604,11 +570,9 @@ final class Document
$this->logicalUnits[$details['id']] = $details;
// Walk the structure recursively? And are there any children of the current element?
if ($recursive
- && count($structure->children('http://www.loc.gov/METS/')->div))
- {
+ && count($structure->children('http://www.loc.gov/METS/')->div)) {
$details['children'] = [];
- foreach ($structure->children('http://www.loc.gov/METS/')->div as $child)
- {
+ foreach ($structure->children('http://www.loc.gov/METS/')->div as $child) {
// Repeat for all children.
$details['children'][] = $this->getLogicalStructureInfo($child, TRUE);
}
@@ -627,30 +591,25 @@ final class Document
*
* @return array The logical structure node's parsed metadata array
*/
- public function getMetadata($id, $cPid = 0)
- {
+ public function getMetadata($id, $cPid = 0) {
// Save parameter for logging purposes.
$_cPid = $cPid;
// Make sure $cPid is a non-negative integer.
$cPid = max(intval($cPid), 0);
// If $cPid is not given, try to get it elsewhere.
if (!$cPid
- && ($this->cPid || $this->pid))
- {
+ && ($this->cPid || $this->pid)) {
// Retain current PID.
$cPid = ($this->cPid ? $this->cPid : $this->pid);
- } elseif (!$cPid)
- {
- if (TYPO3_DLOG)
- {
+ } elseif (!$cPid) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getMetadata('.$id.', '.$_cPid.')] Invalid PID "'.$cPid.'" for metadata definitions', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return [];
}
// Get metadata from parsed metadata array if available.
if (!empty($this->metadataArray[$id])
- && $this->metadataArray[0] == $cPid)
- {
+ && $this->metadataArray[0] == $cPid) {
return $this->metadataArray[$id];
}
// Initialize metadata array with empty values.
@@ -673,46 +632,38 @@ final class Document
'owner' => [],
];
// Get the logical structure node's DMDID.
- if (!empty($this->logicalUnits[$id]))
- {
+ if (!empty($this->logicalUnits[$id])) {
$dmdId = $this->logicalUnits[$id]['dmdId'];
} else {
$dmdId = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="'.$id.'"]/@DMDID');
$dmdId = (string) $dmdId[0];
}
- if (!empty($dmdId))
- {
+ if (!empty($dmdId)) {
// Load available metadata formats and dmdSecs.
$this->loadFormats();
$this->_getDmdSec();
// Is this metadata format supported?
- if (!empty($this->formats[$this->dmdSec[$dmdId]['type']]))
- {
- if (!empty($this->formats[$this->dmdSec[$dmdId]['type']]['class']))
- {
+ if (!empty($this->formats[$this->dmdSec[$dmdId]['type']])) {
+ if (!empty($this->formats[$this->dmdSec[$dmdId]['type']]['class'])) {
$class = $this->formats[$this->dmdSec[$dmdId]['type']]['class'];
// Get the metadata from class.
if (class_exists($class)
- && ($obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($class)) instanceof MetadataInterface)
- {
+ && ($obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($class)) instanceof MetadataInterface) {
$obj->extractMetadata($this->dmdSec[$dmdId]['xml'], $metadata);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getMetadata('.$id.', '.$_cPid.')] Invalid class/method "'.$class.'->extractMetadata()" for metadata format "'.$this->dmdSec[$dmdId]['type'].'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
}
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getMetadata('.$id.', '.$_cPid.')] Unsupported metadata format "'.$this->dmdSec[$dmdId]['type'].'" in dmdSec with @ID "'.$dmdId.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return [];
}
// Get the structure's type.
- if (!empty($this->logicalUnits[$id]))
- {
+ if (!empty($this->logicalUnits[$id])) {
$metadata['type'] = [$this->logicalUnits[$id]['type']];
} else {
$struct = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="'.$id.'"]/@TYPE');
@@ -737,23 +688,18 @@ final class Document
$domXPath = new \DOMXPath($domNode->ownerDocument);
$this->registerNamespaces($domXPath);
// OK, now make the XPath queries.
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Set metadata field's value(s).
if ($resArray['format'] > 0
&& !empty($resArray['xpath'])
- && ($values = $domXPath->evaluate($resArray['xpath'], $domNode)))
- {
+ && ($values = $domXPath->evaluate($resArray['xpath'], $domNode))) {
if ($values instanceof \DOMNodeList
- && $values->length > 0)
- {
+ && $values->length > 0) {
$metadata[$resArray['index_name']] = [];
- foreach ($values as $value)
- {
+ foreach ($values as $value) {
$metadata[$resArray['index_name']][] = trim((string) $value->nodeValue);
}
- } elseif (!($values instanceof \DOMNodeList))
- {
+ } elseif (!($values instanceof \DOMNodeList)) {
$metadata[$resArray['index_name']] = [trim((string) $values)];
}
}
@@ -762,43 +708,35 @@ final class Document
// Setting an empty default value creates a lot of empty fields within the index.
// These empty fields are then shown within the search facets as 'empty'.
if (empty($metadata[$resArray['index_name']][0])
- && strlen($resArray['default_value']) > 0)
- {
+ && strlen($resArray['default_value']) > 0) {
$metadata[$resArray['index_name']] = [$resArray['default_value']];
}
// Set sorting value if applicable.
if (!empty($metadata[$resArray['index_name']])
- && $resArray['is_sortable'])
- {
+ && $resArray['is_sortable']) {
if ($resArray['format'] > 0
&& !empty($resArray['xpath_sorting'])
- && ($values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode)))
- {
+ && ($values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode))) {
if ($values instanceof \DOMNodeList
- && $values->length > 0)
- {
+ && $values->length > 0) {
$metadata[$resArray['index_name'].'_sorting'][0] = trim((string) $values->item(0)->nodeValue);
- } elseif (!($values instanceof \DOMNodeList))
- {
+ } elseif (!($values instanceof \DOMNodeList)) {
$metadata[$resArray['index_name'].'_sorting'][0] = trim((string) $values);
}
}
- if (empty($metadata[$resArray['index_name'].'_sorting'][0]))
- {
+ if (empty($metadata[$resArray['index_name'].'_sorting'][0])) {
$metadata[$resArray['index_name'].'_sorting'][0] = $metadata[$resArray['index_name']][0];
}
}
}
// Set title to empty string if not present.
- if (empty($metadata['title'][0]))
- {
+ if (empty($metadata['title'][0])) {
$metadata['title'][0] = '';
$metadata['title_sorting'][0] = '';
}
// Add collections from database to toplevel element if document is already saved.
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->uid)
- && $id == $this->_getToplevelId())
- {
+ && $id == $this->_getToplevelId()) {
$result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tx_dlf_collections.index_name AS index_name',
'tx_dlf_documents',
@@ -814,10 +752,8 @@ final class Document
'',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
- if (!in_array($resArray['index_name'], $metadata['collection']))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
+ if (!in_array($resArray['index_name'], $metadata['collection'])) {
$metadata['collection'][] = $resArray['index_name'];
}
}
@@ -838,18 +774,14 @@ final class Document
*
* @return integer The physical page number
*/
- public function getPhysicalPage($logicalPage)
- {
+ public function getPhysicalPage($logicalPage) {
if (!empty($this->lastSearchedPhysicalPage['logicalPage'])
- && $this->lastSearchedPhysicalPage['logicalPage'] == $logicalPage)
- {
+ && $this->lastSearchedPhysicalPage['logicalPage'] == $logicalPage) {
return $this->lastSearchedPhysicalPage['physicalPage'];
} else {
$physicalPage = 0;
- foreach ($this->physicalStructureInfo as $page)
- {
- if (strpos($page['orderlabel'], $logicalPage) !== FALSE)
- {
+ foreach ($this->physicalStructureInfo as $page) {
+ if (strpos($page['orderlabel'], $logicalPage) !== FALSE) {
$this->lastSearchedPhysicalPage['logicalPage'] = $logicalPage;
$this->lastSearchedPhysicalPage['physicalPage'] = $physicalPage;
return $physicalPage;
@@ -869,26 +801,22 @@ final class Document
*
* @return string The physical structure node's raw text
*/
- public function getRawText($id)
- {
+ public function getRawText($id) {
$rawText = '';
// Get text from raw text array if available.
- if (!empty($this->rawTextArray[$id]))
- {
+ if (!empty($this->rawTextArray[$id])) {
return $this->rawTextArray[$id];
}
// Load fileGrps and check for fulltext files.
$this->_getFileGrps();
- if ($this->hasFulltext)
- {
+ if ($this->hasFulltext) {
// Load available text formats, ...
$this->loadFormats();
// ... physical structure ...
$this->_getPhysicalStructure();
// ... and extension configuration.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
- if (!empty($this->physicalStructureInfo[$id]))
- {
+ if (!empty($this->physicalStructureInfo[$id])) {
// Get fulltext file.
$file = $this->getFileLocation($this->physicalStructureInfo[$id]['files'][$extConf['fileGrpFulltext']]);
// Turn off libxml's error logging.
@@ -904,34 +832,28 @@ final class Document
// Get the root element's name as text format.
$textFormat = strtoupper($rawTextXml->getName());
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getRawText('.$id.')] Invalid structure node @ID "'.$id.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return $rawText;
}
// Is this text format supported?
- if (!empty($this->formats[$textFormat]))
- {
- if (!empty($this->formats[$textFormat]['class']))
- {
+ if (!empty($this->formats[$textFormat])) {
+ if (!empty($this->formats[$textFormat]['class'])) {
$class = $this->formats[$textFormat]['class'];
// Get the raw text from class.
if (class_exists($class)
- && ($obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($class)) instanceof FulltextInterface)
- {
+ && ($obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($class)) instanceof FulltextInterface) {
$rawText = $obj->getRawText($rawTextXml);
$this->rawTextArray[$id] = $rawText;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getRawText('.$id.')] Invalid class/method "'.$class.'->getRawText()" for text format "'.$textFormat.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
}
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getRawText('.$id.')] Unsupported text format "'.$textFormat.'" in physical node with @ID "'.$id.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
}
@@ -949,15 +871,13 @@ final class Document
*
* @return string The title of the document itself or a parent document
*/
- public static function getTitle($uid, $recursive = FALSE)
- {
+ public static function getTitle($uid, $recursive = FALSE) {
// Save parameter for logging purposes.
$_uid = $uid;
$title = '';
// Sanitize input.
$uid = max(intval($uid), 0);
- if ($uid)
- {
+ if ($uid) {
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.title,tx_dlf_documents.partof',
'tx_dlf_documents',
@@ -967,27 +887,23 @@ final class Document
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result))
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
// Get title information.
list ($title, $partof) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
// Search parent documents recursively for a title?
if ($recursive
&& empty($title)
&& intval($partof)
- && $partof != $uid)
- {
+ && $partof != $uid) {
$title = self::getTitle($partof, TRUE);
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getTitle('.$_uid.', ['.($recursive ? 'TRUE' : 'FALSE').'])] No document with UID "'.$uid.'" found or document not accessible', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getTitle('.$_uid.', ['.($recursive ? 'TRUE' : 'FALSE').'])] Invalid UID "'.$uid.'" for document', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -1003,16 +919,13 @@ final class Document
*
* @return array The logical structure node's parsed metadata array
*/
- public function getTitledata($cPid = 0)
- {
+ public function getTitledata($cPid = 0) {
$titledata = $this->getMetadata($this->_getToplevelId(), $cPid);
// Set record identifier for METS file if not present.
if (is_array($titledata)
- && array_key_exists('record_id', $titledata))
- {
+ && array_key_exists('record_id', $titledata)) {
if (!empty($this->recordId)
- && !in_array($this->recordId, $titledata['record_id']))
- {
+ && !in_array($this->recordId, $titledata['record_id'])) {
array_unshift($titledata['record_id'], $this->recordId);
}
}
@@ -1026,19 +939,16 @@ final class Document
*
* @return void
*/
- protected function init()
- {
+ protected function init() {
// Get METS node from XML file.
$this->registerNamespaces($this->xml);
$mets = $this->xml->xpath('//mets:mets');
- if ($mets)
- {
+ if ($mets) {
$this->mets = $mets[0];
// Register namespaces.
$this->registerNamespaces($this->mets);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->init()] No METS part found in document with UID "'.$this->uid.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -1053,16 +963,13 @@ final class Document
*
* @return boolean TRUE on success or FALSE on failure
*/
- protected function load($location)
- {
+ protected function load($location) {
// Load XML file.
- if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($location))
- {
+ if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($location)) {
// Load extension configuration
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']);
// Set user-agent to identify self when fetching XML data.
- if (!empty($extConf['useragent']))
- {
+ if (!empty($extConf['useragent'])) {
@ini_set('user_agent', $extConf['useragent']);
}
// Turn off libxml's error logging.
@@ -1076,19 +983,16 @@ final class Document
// Reset libxml's error logging.
libxml_use_internal_errors($libxmlErrors);
// Set some basic properties.
- if ($xml !== FALSE)
- {
+ if ($xml !== FALSE) {
$this->xml = $xml;
return TRUE;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->load('.$location.')] Could not load XML file from "'.$location.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->load('.$location.')] Invalid file location "'.$location.'" for document loading', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -1102,10 +1006,8 @@ final class Document
*
* @return void
*/
- protected function loadFormats()
- {
- if (!$this->formatsLoaded)
- {
+ protected function loadFormats() {
+ if (!$this->formatsLoaded) {
// Get available data formats from database.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_formats.type AS type,tx_dlf_formats.root AS root,tx_dlf_formats.namespace AS namespace,tx_dlf_formats.class AS class',
@@ -1116,8 +1018,7 @@ final class Document
'',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Update format registry.
$this->formats[$resArray['type']] = [
'rootElement' => $resArray['root'],
@@ -1138,26 +1039,21 @@ final class Document
*
* @return void
*/
- public function registerNamespaces(&$obj)
- {
+ public function registerNamespaces(&$obj) {
$this->loadFormats();
// Do we have a \SimpleXMLElement or \DOMXPath object?
- if ($obj instanceof \SimpleXMLElement)
- {
+ if ($obj instanceof \SimpleXMLElement) {
$method = 'registerXPathNamespace';
- } elseif ($obj instanceof \DOMXPath)
- {
+ } elseif ($obj instanceof \DOMXPath) {
$method = 'registerNamespace';
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->registerNamespaces(['.get_class($obj).'])] Given object is neither a SimpleXMLElement nor a DOMXPath instance', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
}
// Register metadata format's namespaces.
- foreach ($this->formats as $enc => $conf)
- {
+ foreach ($this->formats as $enc => $conf) {
$obj->$method(strtolower($enc), $conf['namespaceURI']);
}
}
@@ -1172,15 +1068,12 @@ final class Document
*
* @return boolean TRUE on success or FALSE on failure
*/
- public function save($pid = 0, $core = 0)
- {
+ public function save($pid = 0, $core = 0) {
// Save parameters for logging purposes.
$_pid = $pid;
$_core = $core;
- if (TYPO3_MODE !== 'BE')
- {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_MODE !== 'BE') {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] Saving a document is only allowed in the backend', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
@@ -1191,14 +1084,11 @@ final class Document
$core = max(intval($core), 0);
// If $pid is not given, try to get it elsewhere.
if (!$pid
- && $this->pid)
- {
+ && $this->pid) {
// Retain current PID.
$pid = $this->pid;
- } elseif (!$pid)
- {
- if (TYPO3_DLOG)
- {
+ } elseif (!$pid) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] Invalid PID "'.$pid.'" for document saving', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
@@ -1206,17 +1096,14 @@ final class Document
// Set PID for metadata definitions.
$this->cPid = $pid;
// Set UID placeholder if not updating existing record.
- if ($pid != $this->pid)
- {
+ if ($pid != $this->pid) {
$this->uid = uniqid('NEW');
}
// Get metadata array.
$metadata = $this->getTitledata($pid);
// Check for record identifier.
- if (empty($metadata['record_id'][0]))
- {
- if (TYPO3_DLOG)
- {
+ if (empty($metadata['record_id'][0])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] No record identifier found to avoid duplication', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
@@ -1234,10 +1121,8 @@ final class Document
'',
'1'
);
- if (!$GLOBALS['TYPO3_DB']->sql_num_rows($result))
- {
- if (TYPO3_DLOG)
- {
+ if (!$GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] Backend user "_cli_dlf" not found or disabled', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
@@ -1253,12 +1138,10 @@ final class Document
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result))
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
list ($structure) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] Could not identify document/structure type '.$GLOBALS['TYPO3_DB']->fullQuoteStr($metadata['type'][0], 'tx_dlf_structures'), self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return FALSE;
@@ -1276,14 +1159,11 @@ final class Document
'',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$collUid[$resArray['index_name']] = $resArray['uid'];
}
- foreach ($metadata['collection'] as $collection)
- {
- if (!empty($collUid[$collection]))
- {
+ foreach ($metadata['collection'] as $collection) {
+ if (!empty($collUid[$collection])) {
// Add existing collection's UID.
$collections[] = $collUid[$collection];
} else {
@@ -1304,8 +1184,7 @@ final class Document
unset ($collData);
// Add new collection's UID.
$collections[] = $substUid[$collNewUid];
- if (!defined('TYPO3_cliMode'))
- {
+ if (!defined('TYPO3_cliMode')) {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
htmlspecialchars(sprintf(Helper::getMessage('flash.newCollection'), $collection, $substUid[$collNewUid])),
@@ -1330,8 +1209,7 @@ final class Document
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result))
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
list ($ownerUid) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
} else {
// Insert new library.
@@ -1353,8 +1231,7 @@ final class Document
$substUid = Helper::processDB($libData);
// Add new library's UID.
$ownerUid = $substUid[$libNewUid];
- if (!defined('TYPO3_cliMode'))
- {
+ if (!defined('TYPO3_cliMode')) {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
htmlspecialchars(sprintf(Helper::getMessage('flash.newLibrary'), $owner, $ownerUid)),
@@ -1370,16 +1247,12 @@ final class Document
$partof = 0;
// Get the closest ancestor of the current document which has a MPTR child.
$parentMptr = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="'.$this->_getToplevelId().'"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr');
- if (!empty($parentMptr[0]))
- {
+ if (!empty($parentMptr[0])) {
$parentLocation = (string) $parentMptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
- if ($parentLocation != $this->location)
- {
+ if ($parentLocation != $this->location) {
$parentDoc = self::getInstance($parentLocation, $pid);
- if ($parentDoc->ready)
- {
- if ($parentDoc->pid != $pid)
- {
+ if ($parentDoc->ready) {
+ if ($parentDoc->pid != $pid) {
$parentDoc->save($pid, $core);
}
$partof = $parentDoc->uid;
@@ -1387,28 +1260,21 @@ final class Document
}
}
// Use the date of publication or title as alternative sorting metric for parts of multi-part works.
- if (!empty($partof))
- {
+ if (!empty($partof)) {
if (empty($metadata['volume'][0])
- && !empty($metadata['year'][0]))
- {
+ && !empty($metadata['year'][0])) {
$metadata['volume'] = $metadata['year'];
}
- if (empty($metadata['volume_sorting'][0]))
- {
- if (!empty($metadata['year_sorting'][0]))
- {
+ if (empty($metadata['volume_sorting'][0])) {
+ if (!empty($metadata['year_sorting'][0])) {
$metadata['volume_sorting'][0] = $metadata['year_sorting'][0];
- } elseif (!empty($metadata['year'][0]))
- {
+ } elseif (!empty($metadata['year'][0])) {
$metadata['volume_sorting'][0] = $metadata['year'][0];
}
}
// If volume_sorting is still empty, try to use title_sorting finally (workaround for newspapers)
- if (empty($metadata['volume_sorting'][0]))
- {
- if (!empty($metadata['title_sorting'][0]))
- {
+ if (empty($metadata['volume_sorting'][0])) {
+ if (!empty($metadata['title_sorting'][0])) {
$metadata['volume_sorting'][0] = $metadata['title_sorting'][0];
}
}
@@ -1426,16 +1292,12 @@ final class Document
'',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
- if (!empty($metadata[$resArray['index_name']]))
- {
- if ($resArray['is_listed'])
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
+ if (!empty($metadata[$resArray['index_name']])) {
+ if ($resArray['is_listed']) {
$listed[$resArray['index_name']] = $metadata[$resArray['index_name']];
}
- if ($resArray['is_sortable'])
- {
+ if ($resArray['is_sortable']) {
$sortable[$resArray['index_name']] = $metadata[$resArray['index_name']][0];
}
}
@@ -1470,21 +1332,18 @@ final class Document
'status' => 0,
];
// Unhide hidden documents.
- if (!empty($conf['unhideOnIndex']))
- {
+ if (!empty($conf['unhideOnIndex'])) {
$data['tx_dlf_documents'][$this->uid][$GLOBALS['TCA']['tx_dlf_documents']['ctrl']['enablecolumns']['disabled']] = 0;
}
// Process data.
$newIds = Helper::processDB($data);
// Replace placeholder with actual UID.
- if (strpos($this->uid, 'NEW') === 0)
- {
+ if (strpos($this->uid, 'NEW') === 0) {
$this->uid = $newIds[$this->uid];
$this->pid = $pid;
$this->parentId = $partof;
}
- if (!defined('TYPO3_cliMode'))
- {
+ if (!defined('TYPO3_cliMode')) {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
htmlspecialchars(sprintf(Helper::getMessage('flash.documentSaved'), $metadata['title'][0], $this->uid)),
@@ -1495,12 +1354,10 @@ final class Document
Helper::addMessage($message);
}
// Add document to index.
- if ($core)
- {
+ if ($core) {
Indexer::add($this, $core);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->save('.$_pid.', '.$_core.')] Invalid UID "'.$core.'" for Solr core', self::$extKey, SYSLOG_SEVERITY_NOTICE);
}
}
@@ -1514,8 +1371,7 @@ final class Document
*
* @return integer The PID of the metadata definitions
*/
- protected function _getCPid()
- {
+ protected function _getCPid() {
return $this->cPid;
}
@@ -1526,33 +1382,25 @@ final class Document
*
* @return array Array of dmdSecs with their IDs as array key
*/
- protected function _getDmdSec()
- {
- if (!$this->dmdSecLoaded)
- {
+ protected function _getDmdSec() {
+ if (!$this->dmdSecLoaded) {
// Get available data formats.
$this->loadFormats();
// Get dmdSec nodes from METS.
$dmdIds = $this->mets->xpath('./mets:dmdSec/@ID');
- foreach ($dmdIds as $dmdId)
- {
- if ($type = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[not(@MDTYPE="OTHER")]/@MDTYPE'))
- {
- if (!empty($this->formats[(string) $type[0]]))
- {
+ foreach ($dmdIds as $dmdId) {
+ if ($type = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[not(@MDTYPE="OTHER")]/@MDTYPE')) {
+ if (!empty($this->formats[(string) $type[0]])) {
$type = (string) $type[0];
$xml = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[@MDTYPE="'.$type.'"]/mets:xmlData/'.strtolower($type).':'.$this->formats[$type]['rootElement']);
}
- } elseif ($type = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[@MDTYPE="OTHER"]/@OTHERMDTYPE'))
- {
- if (!empty($this->formats[(string) $type[0]]))
- {
+ } elseif ($type = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[@MDTYPE="OTHER"]/@OTHERMDTYPE')) {
+ if (!empty($this->formats[(string) $type[0]])) {
$type = (string) $type[0];
$xml = $this->mets->xpath('./mets:dmdSec[@ID="'.(string) $dmdId.'"]/mets:mdWrap[@MDTYPE="OTHER"][@OTHERMDTYPE="'.$type.'"]/mets:xmlData/'.strtolower($type).':'.$this->formats[$type]['rootElement']);
}
}
- if ($xml)
- {
+ if ($xml) {
$this->dmdSec[(string) $dmdId]['type'] = $type;
$this->dmdSec[(string) $dmdId]['xml'] = $xml[0];
$this->registerNamespaces($this->dmdSec[(string) $dmdId]['xml']);
@@ -1570,46 +1418,36 @@ final class Document
*
* @return array Array of file use groups with file IDs
*/
- protected function _getFileGrps()
- {
- if (!$this->fileGrpsLoaded)
- {
+ protected function _getFileGrps() {
+ if (!$this->fileGrpsLoaded) {
// Get configured USE attributes.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
$useGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $extConf['fileGrps']);
- if (!empty($extConf['fileGrpThumbs']))
- {
+ if (!empty($extConf['fileGrpThumbs'])) {
$useGrps[] = $extConf['fileGrpThumbs'];
}
- if (!empty($extConf['fileGrpDownload']))
- {
+ if (!empty($extConf['fileGrpDownload'])) {
$useGrps[] = $extConf['fileGrpDownload'];
}
- if (!empty($extConf['fileGrpFulltext']))
- {
+ if (!empty($extConf['fileGrpFulltext'])) {
$useGrps[] = $extConf['fileGrpFulltext'];
}
- if (!empty($extConf['fileGrpAudio']))
- {
+ if (!empty($extConf['fileGrpAudio'])) {
$useGrps[] = $extConf['fileGrpAudio'];
}
// Get all file groups.
$fileGrps = $this->mets->xpath('./mets:fileSec/mets:fileGrp');
// Build concordance for configured USE attributes.
- foreach ($fileGrps as $fileGrp)
- {
- if (in_array((string) $fileGrp['USE'], $useGrps))
- {
- foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file)
- {
+ foreach ($fileGrps as $fileGrp) {
+ if (in_array((string) $fileGrp['USE'], $useGrps)) {
+ foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file) {
$this->fileGrps[(string) $file->attributes()->ID] = (string) $fileGrp['USE'];
}
}
}
// Are there any fulltext files available?
if (!empty($extConf['fileGrpFulltext'])
- && in_array($extConf['fileGrpFulltext'], $this->fileGrps))
- {
+ && in_array($extConf['fileGrpFulltext'], $this->fileGrps)) {
$this->hasFulltext = TRUE;
}
$this->fileGrpsLoaded = TRUE;
@@ -1624,11 +1462,9 @@ final class Document
*
* @return boolean Are there any fulltext files available?
*/
- protected function _getHasFulltext()
- {
+ protected function _getHasFulltext() {
// Are the fileGrps already loaded?
- if (!$this->fileGrpsLoaded)
- {
+ if (!$this->fileGrpsLoaded) {
$this->_getFileGrps();
}
return $this->hasFulltext;
@@ -1641,8 +1477,7 @@ final class Document
*
* @return string The location of the document
*/
- protected function _getLocation()
- {
+ protected function _getLocation() {
return $this->location;
}
@@ -1653,26 +1488,20 @@ final class Document
*
* @return array Array of metadata with their corresponding logical structure node ID as key
*/
- protected function _getMetadataArray()
- {
+ protected function _getMetadataArray() {
// Set metadata definitions' PID.
$cPid = ($this->cPid ? $this->cPid : $this->pid);
- if (!$cPid)
- {
- if (TYPO3_DLOG)
- {
+ if (!$cPid) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->getMetadataArray()] Invalid PID "'.$cPid.'" for metadata definitions', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return [];
}
if (!$this->metadataArrayLoaded
- || $this->metadataArray[0] != $cPid)
- {
+ || $this->metadataArray[0] != $cPid) {
// Get all logical structure nodes with metadata.
- if (($ids = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]/@ID')))
- {
- foreach ($ids as $id)
- {
+ if (($ids = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]/@ID'))) {
+ foreach ($ids as $id) {
$this->metadataArray[(string) $id] = $this->getMetadata((string) $id, $cPid);
}
}
@@ -1690,8 +1519,7 @@ final class Document
*
* @return \SimpleXMLElement The XML's METS part as \SimpleXMLElement object
*/
- protected function _getMets()
- {
+ protected function _getMets() {
return $this->mets;
}
@@ -1702,8 +1530,7 @@ final class Document
*
* @return integer The total number of pages and/or tracks
*/
- protected function _getNumPages()
- {
+ protected function _getNumPages() {
$this->_getPhysicalStructure();
return $this->numPages;
}
@@ -1715,8 +1542,7 @@ final class Document
*
* @return integer The UID of the parent document or zero if not applicable
*/
- protected function _getParentId()
- {
+ protected function _getParentId() {
return $this->parentId;
}
@@ -1727,15 +1553,12 @@ final class Document
*
* @return array Array of physical elements' id, type, label and file representations ordered by @ORDER attribute
*/
- protected function _getPhysicalStructure()
- {
+ protected function _getPhysicalStructure() {
// Is there no physical structure array yet?
- if (!$this->physicalStructureLoaded)
- {
+ if (!$this->physicalStructureLoaded) {
// Does the document have a structMap node of type "PHYSICAL"?
$elementNodes = $this->mets->xpath('./mets:structMap[@TYPE="PHYSICAL"]/mets:div[@TYPE="physSequence"]/mets:div');
- if ($elementNodes)
- {
+ if ($elementNodes) {
// Get file groups.
$fileUse = $this->_getFileGrps();
// Get the physical sequence's metadata.
@@ -1748,17 +1571,14 @@ final class Document
$this->physicalStructureInfo[$physSeq[0]]['type'] = (string) $physNode[0]['TYPE'];
$this->physicalStructureInfo[$physSeq[0]]['contentIds'] = (isset($physNode[0]['CONTENTIDS']) ? (string) $physNode[0]['CONTENTIDS'] : '');
// Get the file representations from fileSec node.
- foreach ($physNode[0]->children('http://www.loc.gov/METS/')->fptr as $fptr)
- {
+ foreach ($physNode[0]->children('http://www.loc.gov/METS/')->fptr as $fptr) {
// Check if file has valid @USE attribute.
- if (!empty($fileUse[(string) $fptr->attributes()->FILEID]))
- {
+ if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) {
$this->physicalStructureInfo[$physSeq[0]]['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID;
}
}
// Build the physical elements' array from the physical structMap node.
- foreach ($elementNodes as $elementNode)
- {
+ foreach ($elementNodes as $elementNode) {
$elements[(int) $elementNode['ORDER']] = (string) $elementNode['ID'];
$this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['id'] = (string) $elementNode['ID'];
$this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['dmdId'] = (isset($elementNode['DMDID']) ? (string) $elementNode['DMDID'] : '');
@@ -1767,18 +1587,15 @@ final class Document
$this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['type'] = (string) $elementNode['TYPE'];
$this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['contentIds'] = (isset($elementNode['CONTENTIDS']) ? (string) $elementNode['CONTENTIDS'] : '');
// Get the file representations from fileSec node.
- foreach ($elementNode->children('http://www.loc.gov/METS/')->fptr as $fptr)
- {
+ foreach ($elementNode->children('http://www.loc.gov/METS/')->fptr as $fptr) {
// Check if file has valid @USE attribute.
- if (!empty($fileUse[(string) $fptr->attributes()->FILEID]))
- {
+ if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) {
$this->physicalStructureInfo[$elements[(int) $elementNode['ORDER']]]['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID;
}
}
}
// Sort array by keys (= @ORDER).
- if (ksort($elements))
- {
+ if (ksort($elements)) {
// Set total number of pages/tracks.
$this->numPages = count($elements);
// Merge and re-index the array to get nice numeric indexes.
@@ -1797,11 +1614,9 @@ final class Document
*
* @return array Array of elements' type, label and file representations ordered by @ID attribute
*/
- protected function _getPhysicalStructureInfo()
- {
+ protected function _getPhysicalStructureInfo() {
// Is there no physical structure array yet?
- if (!$this->physicalStructureLoaded)
- {
+ if (!$this->physicalStructureLoaded) {
// Build physical structure array.
$this->_getPhysicalStructure();
}
@@ -1815,8 +1630,7 @@ final class Document
*
* @return integer The PID of the document or zero if not in database
*/
- protected function _getPid()
- {
+ protected function _getPid() {
return $this->pid;
}
@@ -1827,8 +1641,7 @@ final class Document
*
* @return boolean Is the document instantiated successfully?
*/
- protected function _getReady()
- {
+ protected function _getReady() {
return $this->ready;
}
@@ -1839,8 +1652,7 @@ final class Document
*
* @return mixed The METS file's record identifier
*/
- protected function _getRecordId()
- {
+ protected function _getRecordId() {
return $this->recordId;
}
@@ -1851,12 +1663,9 @@ final class Document
*
* @return integer The UID of the root document or zero if not applicable
*/
- protected function _getRootId()
- {
- if (!$this->rootIdLoaded)
- {
- if ($this->parentId)
- {
+ protected function _getRootId() {
+ if (!$this->rootIdLoaded) {
+ if ($this->parentId) {
$parent = self::getInstance($this->parentId, $this->pid);
$this->rootId = $parent->rootId;
}
@@ -1872,13 +1681,10 @@ final class Document
*
* @return array The links between logical and physical nodes
*/
- protected function _getSmLinks()
- {
- if (!$this->smLinksLoaded)
- {
+ protected function _getSmLinks() {
+ if (!$this->smLinksLoaded) {
$smLinks = $this->mets->xpath('./mets:structLink/mets:smLink');
- foreach ($smLinks as $smLink)
- {
+ foreach ($smLinks as $smLink) {
$this->smLinks['l2p'][(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to;
$this->smLinks['p2l'][(string) $smLink->attributes('http://www.w3.org/1999/xlink')->to][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->from;
}
@@ -1894,11 +1700,9 @@ final class Document
*
* @return array Array of structure nodes' id, label, type and physical page indexes/mptr link with original hierarchy preserved
*/
- protected function _getTableOfContents()
- {
+ protected function _getTableOfContents() {
// Is there no logical structure array yet?
- if (!$this->tableOfContentsLoaded)
- {
+ if (!$this->tableOfContentsLoaded) {
// Get all logical structures.
$this->getLogicalStructure('', TRUE);
$this->tableOfContentsLoaded = TRUE;
@@ -1915,17 +1719,13 @@ final class Document
*
* @return string The document's thumbnail location
*/
- protected function _getThumbnail($forceReload = FALSE)
- {
+ protected function _getThumbnail($forceReload = FALSE) {
if (!$this->thumbnailLoaded
- || $forceReload)
- {
+ || $forceReload) {
// Retain current PID.
$cPid = ($this->cPid ? $this->cPid : $this->pid);
- if (!$cPid)
- {
- if (TYPO3_DLOG)
- {
+ if (!$cPid) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->_getThumbnail()] Invalid PID "'.$cPid.'" for structure definitions', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
$this->thumbnailLoaded = TRUE;
@@ -1933,10 +1733,8 @@ final class Document
}
// Load extension configuration.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
- if (empty($extConf['fileGrpThumbs']))
- {
- if (TYPO3_DLOG)
- {
+ if (empty($extConf['fileGrpThumbs'])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->_getThumbnail()] No fileGrp for thumbnails specified', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
$this->thumbnailLoaded = TRUE;
@@ -1955,17 +1753,14 @@ final class Document
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
// Get desired thumbnail structure if not the toplevel structure itself.
- if (!empty($resArray['thumbnail']))
- {
+ if (!empty($resArray['thumbnail'])) {
$strctType = Helper::getIndexName($resArray['thumbnail'], 'tx_dlf_structures', $cPid);
// Check if this document has a structure element of the desired type.
$strctIds = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@TYPE="'.$strctType.'"]/@ID');
- if (!empty($strctIds))
- {
+ if (!empty($strctIds)) {
$strctId = (string) $strctIds[0];
}
}
@@ -1973,14 +1768,12 @@ final class Document
$this->_getSmLinks();
// Get thumbnail location.
if ($this->_getPhysicalStructure()
- && !empty($this->smLinks['l2p'][$strctId]))
- {
+ && !empty($this->smLinks['l2p'][$strctId])) {
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$extConf['fileGrpThumbs']]);
} else {
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$extConf['fileGrpThumbs']]);
}
- } elseif (TYPO3_DLOG)
- {
+ } elseif (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->_getThumbnail()] No structure of type "'.$metadata['type'][0].'" found in database', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
$this->thumbnailLoaded = TRUE;
@@ -1995,26 +1788,20 @@ final class Document
*
* @return string The logical structure node's ID
*/
- protected function _getToplevelId()
- {
- if (empty($this->toplevelId))
- {
+ protected function _getToplevelId() {
+ if (empty($this->toplevelId)) {
// Get all logical structure nodes with metadata, but without associated METS-Pointers.
- if (($divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]')))
- {
+ if (($divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'))) {
// Load smLinks.
$this->_getSmLinks();
- foreach ($divs as $div)
- {
+ foreach ($divs as $div) {
$id = (string) $div['ID'];
// Are there physical structure nodes for this logical structure?
- if (array_key_exists($id, $this->smLinks['l2p']))
- {
+ if (array_key_exists($id, $this->smLinks['l2p'])) {
// Yes. That's what we're looking for.
$this->toplevelId = $id;
break;
- } elseif (empty($this->toplevelId))
- {
+ } elseif (empty($this->toplevelId)) {
// No. Remember this anyway, but keep looking for a better one.
$this->toplevelId = $id;
}
@@ -2031,8 +1818,7 @@ final class Document
*
* @return mixed The UID or the URL of the document
*/
- protected function _getUid()
- {
+ protected function _getUid() {
return $this->uid;
}
@@ -2045,8 +1831,7 @@ final class Document
*
* @return void
*/
- protected function _setCPid($value)
- {
+ protected function _setCPid($value) {
$this->cPid = max(intval($value), 0);
}
@@ -2072,35 +1857,28 @@ final class Document
*
* @return void
*/
- protected function __construct($uid, $pid)
- {
+ protected function __construct($uid, $pid) {
// Prepare to check database for the requested document.
- if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid))
- {
+ if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
$whereClause = 'tx_dlf_documents.uid='.intval($uid).Helper::whereClause('tx_dlf_documents');
} else {
// Try to load METS file.
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($uid)
- && $this->load($uid))
- {
+ && $this->load($uid)) {
// Initialize core METS object.
$this->init();
- if ($this->mets !== NULL)
- {
+ if ($this->mets !== NULL) {
// Cast to string for safety reasons.
$location = (string) $uid;
// Check for METS object @ID.
- if (!empty($this->mets['OBJID']))
- {
+ if (!empty($this->mets['OBJID'])) {
$this->recordId = (string) $this->mets['OBJID'];
}
// Get hook objects.
$hookObjects = Helper::getHookObjects('Classes/Common/Document.php');
// Apply hooks.
- foreach ($hookObjects as $hookObj)
- {
- if (method_exists($hookObj, 'construct_postProcessRecordId'))
- {
+ foreach ($hookObjects as $hookObj) {
+ if (method_exists($hookObj, 'construct_postProcessRecordId')) {
$hookObj->construct_postProcessRecordId($this->xml, $this->recordId);
}
}
@@ -2113,8 +1891,7 @@ final class Document
return;
}
if (!empty($location)
- && !empty($this->recordId))
- {
+ && !empty($this->recordId)) {
// Try to match record identifier or location (both should be unique).
$whereClause = '(tx_dlf_documents.location='.$GLOBALS['TYPO3_DB']->fullQuoteStr($location, 'tx_dlf_documents').' OR tx_dlf_documents.record_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->recordId, 'tx_dlf_documents').')'.Helper::whereClause('tx_dlf_documents');
} else {
@@ -2123,8 +1900,7 @@ final class Document
}
}
// Check for PID if needed.
- if ($pid)
- {
+ if ($pid) {
$whereClause .= ' AND tx_dlf_documents.pid='.intval($pid);
}
// Get document PID and location from database.
@@ -2136,38 +1912,32 @@ final class Document
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
list ($this->uid, $this->pid, $this->recordId, $this->parentId, $this->thumbnail, $this->location) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
$this->thumbnailLoaded = TRUE;
// Load XML file if necessary...
if ($this->mets === NULL
- && $this->load($this->location))
- {
+ && $this->load($this->location)) {
// ...and set some basic properties.
$this->init();
}
// Do we have a METS object now?
- if ($this->mets !== NULL)
- {
+ if ($this->mets !== NULL) {
// Set new location if necessary.
- if (!empty($location))
- {
+ if (!empty($location)) {
$this->location = $location;
}
// Document ready!
$this->ready = TRUE;
}
- } elseif ($this->mets !== NULL)
- {
+ } elseif ($this->mets !== NULL) {
// Set location as UID for documents not in database.
$this->uid = $location;
$this->location = $location;
// Document ready!
$this->ready = TRUE;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->__construct('.$uid.', '.$pid.')] No document with UID "'.$uid.'" found or document not accessible', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -2182,14 +1952,11 @@ final class Document
*
* @return mixed Value of $this->$var
*/
- public function __get($var)
- {
+ public function __get($var) {
$method = '_get'.ucfirst($var);
if (!property_exists($this, $var)
- || !method_exists($this, $method))
- {
- if (TYPO3_DLOG)
- {
+ || !method_exists($this, $method)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->__get('.$var.')] There is no getter function for property "'.$var.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -2208,14 +1975,11 @@ final class Document
*
* @return void
*/
- public function __set($var, $value)
- {
+ public function __set($var, $value) {
$method = '_set'.ucfirst($var);
if (!property_exists($this, $var)
- || !method_exists($this, $method))
- {
- if (TYPO3_DLOG)
- {
+ || !method_exists($this, $method)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->__set('.$var.', '.$value.')] There is no setter function for property "'.$var.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
} else {
@@ -2231,8 +1995,7 @@ final class Document
*
* @return array Properties to be serialized
*/
- public function __sleep()
- {
+ public function __sleep() {
// \SimpleXMLElement objects can't be serialized, thus save the XML as string for serialization
$this->asXML = $this->xml->asXML();
return ['uid', 'pid', 'recordId', 'parentId', 'asXML'];
@@ -2245,8 +2008,7 @@ final class Document
*
* @return string String representing the METS object
*/
- public function __toString()
- {
+ public function __toString() {
$xml = new \DOMDocument('1.0', 'utf-8');
$xml->appendChild($xml->importNode(dom_import_simplexml($this->mets), TRUE));
$xml->formatOutput = TRUE;
@@ -2261,23 +2023,20 @@ final class Document
*
* @return void
*/
- public function __wakeup()
- {
+ public function __wakeup() {
// Turn off libxml's error logging.
$libxmlErrors = libxml_use_internal_errors(TRUE);
// Reload XML from string.
$xml = @simplexml_load_string($this->asXML);
// Reset libxml's error logging.
libxml_use_internal_errors($libxmlErrors);
- if ($xml !== FALSE)
- {
+ if ($xml !== FALSE) {
$this->asXML = '';
$this->xml = $xml;
// Rebuild the unserializable properties.
$this->init();
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Document->__wakeup()] Could not load XML after deserialization', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
diff --git a/Classes/Common/DocumentList.php b/Classes/Common/DocumentList.php
index f7e24ac7..2dc520bc 100644
--- a/Classes/Common/DocumentList.php
+++ b/Classes/Common/DocumentList.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @subpackage dlf
* @access public
*/
-class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Core\SingletonInterface
-{
+class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Core\SingletonInterface {
/**
* This holds the number of documents in the list
* @see \Countable
@@ -91,11 +90,9 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function add(array $elements, $position = -1)
- {
+ public function add(array $elements, $position = -1) {
$position = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($position, 0, $this->count, $this->count);
- if (!empty($elements))
- {
+ if (!empty($elements)) {
array_splice($this->elements, $position, 0, $elements);
$this->count = count($this->elements);
}
@@ -109,8 +106,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return integer The number of elements in the list
*/
- public function count()
- {
+ public function count() {
return $this->count;
}
@@ -122,14 +118,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array The current element
*/
- public function current()
- {
- if ($this->valid())
- {
+ public function current() {
+ if ($this->valid()) {
return $this->getRecord($this->elements[$this->position]);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->current()] Invalid position "'.$this->position.'" for list element', $this->extKey, SYSLOG_SEVERITY_NOTICE);
}
return;
@@ -145,14 +138,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return mixed The element's full record
*/
- protected function getRecord($element)
- {
+ protected function getRecord($element) {
if (is_array($element)
- && array_keys($element) == ['u', 'h', 's', 'p'])
- {
+ && array_keys($element) == ['u', 'h', 's', 'p']) {
// Return already processed record if possible.
- if (!empty($this->records[$element['u']]))
- {
+ if (!empty($this->records[$element['u']])) {
return $this->records[$element['u']];
}
$record = [
@@ -163,8 +153,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
];
// Check if it's a list of database records or Solr documents.
if (!empty($this->metadata['options']['source'])
- && $this->metadata['options']['source'] == 'collection')
- {
+ && $this->metadata['options']['source'] == 'collection') {
// Get document's thumbnail and metadata from database.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata',
@@ -176,38 +165,30 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
''
);
// Process results.
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Prepare document's metadata.
$metadata = unserialize($resArray['metadata']);
if (!empty($metadata['type'][0])
- && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['type'][0]))
- {
+ && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['type'][0])) {
$metadata['type'][0] = Helper::getIndexName($metadata['type'][0], 'tx_dlf_structures', $this->metadata['options']['pid']);
}
if (!empty($metadata['owner'][0])
- && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['owner'][0]))
- {
+ && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['owner'][0])) {
$metadata['owner'][0] = Helper::getIndexName($metadata['owner'][0], 'tx_dlf_libraries', $this->metadata['options']['pid']);
}
if (!empty($metadata['collection'])
- && is_array($metadata['collection']))
- {
- foreach ($metadata['collection'] as $i => $collection)
- {
- if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($collection))
- {
+ && is_array($metadata['collection'])) {
+ foreach ($metadata['collection'] as $i => $collection) {
+ if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($collection)) {
$metadata['collection'][$i] = Helper::getIndexName($metadata['collection'][$i], 'tx_dlf_collections', $this->metadata['options']['pid']);
}
}
}
// Add metadata to list element.
- if ($resArray['uid'] == $record['uid'])
- {
+ if ($resArray['uid'] == $record['uid']) {
$record['thumbnail'] = $resArray['thumbnail'];
$record['metadata'] = $metadata;
- } elseif (($key = array_search(['u' => $resArray['uid']], $record['subparts'], TRUE)) !== FALSE)
- {
+ } elseif (($key = array_search(['u' => $resArray['uid']], $record['subparts'], TRUE)) !== FALSE) {
$record['subparts'][$key] = [
'uid' => $resArray['uid'],
'page' => 1,
@@ -218,20 +199,16 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
}
}
} elseif (!empty($this->metadata['options']['source'])
- && $this->metadata['options']['source'] == 'search')
- {
- if ($this->solrConnect())
- {
+ && $this->metadata['options']['source'] == 'search') {
+ if ($this->solrConnect()) {
$params = [];
// Restrict the fields to the required ones
$params['fields'] = 'uid,id,toplevel,thumbnail,page';
- foreach ($this->solrConfig as $solr_name)
- {
+ foreach ($this->solrConfig as $solr_name) {
$params['fields'] .= ','.$solr_name;
}
// If it is a fulltext search, enable highlighting.
- if ($this->metadata['fulltextSearch'])
- {
+ if ($this->metadata['fulltextSearch']) {
$params['component'] = [
'highlighting' => [
'query' => Solr::escapeQuery($this->metadata['searchString']),
@@ -248,10 +225,8 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
// Take over existing filter queries.
$params['filterquery'] = isset($this->metadata['options']['params']['filterquery']) ? $this->metadata['options']['params']['filterquery'] : [];
// Extend filter query to get all documents with the same UID.
- foreach ($params['filterquery'] as $key => $value)
- {
- if (isset($value['query']))
- {
+ foreach ($params['filterquery'] as $key => $value) {
+ if (isset($value['query'])) {
$params['filterquery'][$key]['query'] = $value['query'].' OR toplevel:true';
}
}
@@ -265,25 +240,20 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
$selectQuery = $this->solr->service->createSelect($params);
$result = $this->solr->service->select($selectQuery);
// If it is a fulltext search, fetch the highlighting results.
- if ($this->metadata['fulltextSearch'])
- {
+ if ($this->metadata['fulltextSearch']) {
$highlighting = $result->getHighlighting();
}
// Process results.
- foreach ($result as $resArray)
- {
+ foreach ($result as $resArray) {
// Prepare document's metadata.
$metadata = [];
- foreach ($this->solrConfig as $index_name => $solr_name)
- {
- if (!empty($resArray->$solr_name))
- {
+ foreach ($this->solrConfig as $index_name => $solr_name) {
+ if (!empty($resArray->$solr_name)) {
$metadata[$index_name] = (is_array($resArray->$solr_name) ? $resArray->$solr_name : [$resArray->$solr_name]);
}
}
// Add metadata to list elements.
- if ($resArray->toplevel)
- {
+ if ($resArray->toplevel) {
$record['thumbnail'] = $resArray->thumbnail;
$record['metadata'] = $metadata;
} else {
@@ -303,8 +273,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
// Save record for later usage.
$this->records[$element['u']] = $record;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->getRecord([data])] No UID of list element to fetch full record', $this->extKey, SYSLOG_SEVERITY_NOTICE, $element);
}
$record = $element;
@@ -320,8 +289,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return integer The current position
*/
- public function key()
- {
+ public function key() {
return $this->position;
}
@@ -335,18 +303,15 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function move($position, $steps)
- {
+ public function move($position, $steps) {
// Save parameters for logging purposes.
$_position = $position;
$_steps = $steps;
$position = intval($position);
// Check if list position is valid.
if ($position < 0
- || $position >= $this->count)
- {
- if (TYPO3_DLOG)
- {
+ || $position >= $this->count) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->move('.$_position.', '.$_steps.')] Invalid position "'.$position.'" for element moving', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -354,10 +319,8 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
$steps = intval($steps);
// Check if moving given amount of steps is possible.
if (($position + $steps) < 0
- || ($position + $steps) >= $this->count)
- {
- if (TYPO3_DLOG)
- {
+ || ($position + $steps) >= $this->count) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->move('.$_position.', '.$_steps.')] Invalid steps "'.$steps.'" for moving element at position "'.$position.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -375,8 +338,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function moveUp($position)
- {
+ public function moveUp($position) {
$this->move($position, -1);
}
@@ -389,8 +351,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function moveDown($position)
- {
+ public function moveDown($position) {
$this->move($position, 1);
}
@@ -402,8 +363,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function next()
- {
+ public function next() {
$this->position++;
}
@@ -417,8 +377,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return boolean Does the given offset exist?
*/
- public function offsetExists($offset)
- {
+ public function offsetExists($offset) {
return isset($this->elements[$offset]);
}
@@ -432,14 +391,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array The element at the given offset
*/
- public function offsetGet($offset)
- {
- if ($this->offsetExists($offset))
- {
+ public function offsetGet($offset) {
+ if ($this->offsetExists($offset)) {
return $this->getRecord($this->elements[$offset]);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->offsetGet('.$offset.')] Invalid offset "'.$offset.'" for list element', $this->extKey, SYSLOG_SEVERITY_NOTICE);
}
return;
@@ -457,10 +413,8 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function offsetSet($offset, $value)
- {
- if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($offset))
- {
+ public function offsetSet($offset, $value) {
+ if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($offset)) {
$this->elements[$offset] = $value;
} else {
$this->elements[] = $value;
@@ -479,16 +433,13 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array The removed element
*/
- public function remove($position)
- {
+ public function remove($position) {
// Save parameter for logging purposes.
$_position = $position;
$position = intval($position);
if ($position < 0
- || $position >= $this->count)
- {
- if (TYPO3_DLOG)
- {
+ || $position >= $this->count) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->remove('.$_position.')] Invalid position "'.$position.'" for element removing', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -508,16 +459,13 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array The indizes of the removed elements
*/
- public function removeRange($position, $length)
- {
+ public function removeRange($position, $length) {
// Save parameter for logging purposes.
$_position = $position;
$position = intval($position);
if ($position < 0
- || $position >= $this->count)
- {
- if (TYPO3_DLOG)
- {
+ || $position >= $this->count) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->remove('.$_position.')] Invalid position "'.$position.'" for element removing', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -534,8 +482,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function reset()
- {
+ public function reset() {
$this->elements = [];
$this->records = [];
$this->metadata = [];
@@ -551,8 +498,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function rewind()
- {
+ public function rewind() {
$this->position = 0;
}
@@ -565,12 +511,10 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function save($pid = 0)
- {
+ public function save($pid = 0) {
$pid = max(intval($pid), 0);
// If no PID is given, save to the user's session instead
- if ($pid > 0)
- {
+ if ($pid > 0) {
// TODO: Liste in Datenbank speichern (inkl. Sichtbarkeit, Beschreibung, etc.)
} else {
Helper::saveToSession([$this->elements, $this->metadata], get_class($this));
@@ -584,14 +528,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return boolean TRUE on success or FALSE on failure
*/
- protected function solrConnect()
- {
+ protected function solrConnect() {
// Get Solr instance.
- if (!$this->solr)
- {
+ if (!$this->solr) {
// Connect to Solr server.
- if ($this->solr = Solr::getInstance($this->metadata['options']['core']))
- {
+ if ($this->solr = Solr::getInstance($this->metadata['options']['core'])) {
// Load index configuration.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.index_tokenized AS index_tokenized,tx_dlf_metadata.index_indexed AS index_indexed',
@@ -603,8 +544,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
'tx_dlf_metadata.sorting ASC',
''
);
- while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))
- {
+ while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$this->solrConfig[$resArray['index_name']] = $resArray['index_name'].'_'.($resArray['index_tokenized'] ? 't' : 'u').'s'.($resArray['index_indexed'] ? 'i' : 'u');
}
// Add static fields.
@@ -626,23 +566,19 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function sort($by, $asc = TRUE)
- {
+ public function sort($by, $asc = TRUE) {
$newOrder = [];
$nonSortable = [];
- foreach ($this->elements as $num => $element)
- {
+ foreach ($this->elements as $num => $element) {
// Is this element sortable?
- if (!empty($element['s'][$by]))
- {
+ if (!empty($element['s'][$by])) {
$newOrder[$element['s'][$by].str_pad($num, 6, '0', STR_PAD_LEFT)] = $element;
} else {
$nonSortable[] = $element;
}
}
// Reorder elements.
- if ($asc)
- {
+ if ($asc) {
ksort($newOrder, SORT_LOCALE_STRING);
} else {
krsort($newOrder, SORT_LOCALE_STRING);
@@ -650,12 +586,10 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
// Add non sortable elements to the end of the list.
$newOrder = array_merge(array_values($newOrder), $nonSortable);
// Check if something is missing.
- if ($this->count == count($newOrder))
- {
+ if ($this->count == count($newOrder)) {
$this->elements = $newOrder;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->sort('.$by.', ['.($asc ? 'TRUE' : 'FALSE').'])] Sorted list elements do not match unsorted elements', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -671,8 +605,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function offsetUnset($offset)
- {
+ public function offsetUnset($offset) {
unset ($this->elements[$offset]);
// Re-number the elements.
$this->elements = array_values($this->elements);
@@ -687,8 +620,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return boolean Is the current list position valid?
*/
- public function valid()
- {
+ public function valid() {
return isset($this->elements[$this->position]);
}
@@ -699,8 +631,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array The list's metadata
*/
- protected function _getMetadata()
- {
+ protected function _getMetadata() {
return $this->metadata;
}
@@ -713,8 +644,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- protected function _setMetadata(array $metadata = [])
- {
+ protected function _setMetadata(array $metadata = []) {
$this->metadata = $metadata;
}
@@ -728,22 +658,17 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function __construct(array $elements = [], array $metadata = [])
- {
+ public function __construct(array $elements = [], array $metadata = []) {
if (empty($elements)
- && empty($metadata))
- {
+ && empty($metadata)) {
// Let's check the user's session.
$sessionData = Helper::loadFromSession(get_class($this));
// Restore list from session data.
- if (is_array($sessionData))
- {
- if (is_array($sessionData[0]))
- {
+ if (is_array($sessionData)) {
+ if (is_array($sessionData[0])) {
$this->elements = $sessionData[0];
}
- if (is_array($sessionData[1]))
- {
+ if (is_array($sessionData[1])) {
$this->metadata = $sessionData[1];
}
}
@@ -776,14 +701,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return mixed Value of $this->$var
*/
- public function __get($var)
- {
+ public function __get($var) {
$method = '_get'.ucfirst($var);
if (!property_exists($this, $var)
- || !method_exists($this, $method))
- {
- if (TYPO3_DLOG)
- {
+ || !method_exists($this, $method)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->__get('.$var.')] There is no getter function for property "'.$var.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -802,14 +724,11 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function __set($var, $value)
- {
+ public function __set($var, $value) {
$method = '_set'.ucfirst($var);
if (!property_exists($this, $var)
- || !method_exists($this, $method))
- {
- if (TYPO3_DLOG)
- {
+ || !method_exists($this, $method)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentList->__set('.$var.', [data])] There is no setter function for property "'.$var.'"', $this->extKey, SYSLOG_SEVERITY_WARNING, $value);
}
} else {
@@ -825,8 +744,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return array Properties to be serialized
*/
- public function __sleep()
- {
+ public function __sleep() {
return ['elements', 'metadata'];
}
@@ -838,8 +756,7 @@ class DocumentList implements \ArrayAccess, \Countable, \Iterator, \TYPO3\CMS\Co
*
* @return void
*/
- public function __wakeup()
- {
+ public function __wakeup() {
$this->count = count($this->elements);
}
}
diff --git a/Classes/Common/DocumentTypeCheck.php b/Classes/Common/DocumentTypeCheck.php
index 63d4d165..02d3d51b 100644
--- a/Classes/Common/DocumentTypeCheck.php
+++ b/Classes/Common/DocumentTypeCheck.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @subpackage dlf
* @access public
*/
-class DocumentTypeCheck
-{
+class DocumentTypeCheck {
/**
* This holds the current document
*
@@ -62,12 +61,10 @@ class DocumentTypeCheck
*
* @return string The type of the current document
*/
- public function getDocType()
- {
+ public function getDocType() {
// Load current document.
$this->loadDocument();
- if ($this->doc === NULL)
- {
+ if ($this->doc === NULL) {
// Quit without doing anything if document not available.
return '';
}
@@ -86,12 +83,10 @@ class DocumentTypeCheck
* - children array ([0]) --> type = month
* - children array ([0], [1], [2], ...) --> type = day --> Issue
*/
- switch ($toc[0]['type'])
- {
+ switch ($toc[0]['type']) {
case 'newspaper':
$nodes_year = $this->doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]/mets:div[@TYPE="newspaper"]/mets:div[@TYPE="year"]');
- if (count($nodes_year) > 1)
- {
+ if (count($nodes_year) > 1) {
// Multiple years means this is a newspaper's anchor file.
return 'newspaper';
} else {
@@ -100,26 +95,22 @@ class DocumentTypeCheck
$nodes_issue = $this->doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]/mets:div[@TYPE="newspaper"]/mets:div[@TYPE="year"]//mets:div[@TYPE="issue"]');
$nodes_issue_current = $this->doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]/mets:div[@TYPE="newspaper"]/mets:div[@TYPE="year"]//mets:div[@TYPE="issue"]/@DMDID');
if (count($nodes_year) == 1
- && count($nodes_issue) == 0)
- {
+ && count($nodes_issue) == 0) {
// It's possible to have only one year in the newspaper's anchor file.
return 'newspaper';
} elseif (count($nodes_year) == 1
- && count($nodes_month) > 1)
- {
+ && count($nodes_month) > 1) {
// One year, multiple months means this is a year's anchor file.
return 'year';
} elseif (count($nodes_year) == 1
&& count($nodes_month) == 1
- && count($nodes_day) > 1)
- {
+ && count($nodes_day) > 1) {
// One year, one month, one or more days means this is a year's anchor file.
return 'year';
} elseif (count($nodes_year) == 1
&& count($nodes_month) == 1
&& count($nodes_day) == 1
- && count($nodes_issue_current) == 0)
- {
+ && count($nodes_issue_current) == 0) {
// One year, one month, a single day, one or more issues (but not the current one) means this is a year's anchor file.
return 'year';
} else {
@@ -140,24 +131,19 @@ class DocumentTypeCheck
*
* @return void
*/
- protected function loadDocument()
- {
+ protected function loadDocument() {
// Check for required variable.
- if (!empty($this->piVars['id']))
- {
+ if (!empty($this->piVars['id'])) {
// Get instance of \Kitodo\Dlf\Common\Document.
$this->doc = Document::getInstance($this->piVars['id']);
- if (!$this->doc->ready)
- {
+ if (!$this->doc->ready) {
// Destroy the incomplete object.
$this->doc = NULL;
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentTypeCheck->loadDocument()] Failed to load document with UID "'.$this->piVars['id'].'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
}
- } elseif (!empty($this->piVars['recordId']))
- {
+ } elseif (!empty($this->piVars['recordId'])) {
// Get UID of document with given record identifier.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid',
@@ -168,8 +154,7 @@ class DocumentTypeCheck
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) {
list ($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
// Set superglobal $_GET array.
$_GET[$this->prefixId]['id'] = $this->piVars['id'];
@@ -178,8 +163,7 @@ class DocumentTypeCheck
// Try to load document.
$this->loadDocument();
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\DocumentTypeCheck->loadDocument()] Failed to load document with record ID "'.$this->piVars['recordId'].'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
}
@@ -193,8 +177,7 @@ class DocumentTypeCheck
*
* @return void
*/
- public function __construct()
- {
+ public function __construct() {
// Load current plugin parameters.
$this->piVars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged($this->prefixId);
}
diff --git a/Classes/Common/FulltextInterface.php b/Classes/Common/FulltextInterface.php
index 3e2d3b13..c9a402bc 100644
--- a/Classes/Common/FulltextInterface.php
+++ b/Classes/Common/FulltextInterface.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @access public
* @abstract
*/
-interface FulltextInterface
-{
+interface FulltextInterface {
/**
* This extracts raw fulltext data from XML
*
diff --git a/Classes/Common/Helper.php b/Classes/Common/Helper.php
index 700bd431..7d204beb 100644
--- a/Classes/Common/Helper.php
+++ b/Classes/Common/Helper.php
@@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
* @subpackage dlf
* @access public
*/
-class Helper
-{
+class Helper {
/**
* The extension key
*
@@ -64,69 +63,54 @@ class Helper
*
* @return boolean Is $id a valid GNL identifier of the given $type?
*/
- public static function checkIdentifier($id, $type)
- {
+ public static function checkIdentifier($id, $type) {
$digits = substr($id, 0, 8);
$checksum = 0;
- for ($i = 0, $j = strlen($digits); $i < $j; $i++)
- {
+ for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
$checksum += (9 - $i) * intval(substr($digits, $i, 1));
}
$checksum = (11 - ($checksum % 11)) % 11;
- switch (strtoupper($type))
- {
+ switch (strtoupper($type)) {
case 'PPN':
case 'IDN':
case 'PND':
- if ($checksum == 10)
- {
+ if ($checksum == 10) {
$checksum = 'X';
}
- if (!preg_match('/[0-9]{8}[0-9X]{1}/i', $id))
- {
+ if (!preg_match('/[0-9]{8}[0-9X]{1}/i', $id)) {
return FALSE;
- } elseif (strtoupper(substr($id, -1, 1)) != $checksum)
- {
+ } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
case 'ZDB':
- if ($checksum == 10)
- {
+ if ($checksum == 10) {
$checksum = 'X';
}
- if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id))
- {
+ if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
return FALSE;
- } elseif (strtoupper(substr($id, -1, 1)) != $checksum)
- {
+ } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
case 'SWD':
$checksum = 11 - $checksum;
- if (!preg_match('/[0-9]{8}-[0-9]{1}/i', $id))
- {
+ if (!preg_match('/[0-9]{8}-[0-9]{1}/i', $id)) {
return FALSE;
- } elseif ($checksum == 10)
- {
+ } elseif ($checksum == 10) {
return self::checkIdentifier(($digits + 1).substr($id, -2, 2), 'SWD');
- } elseif (substr($id, -1, 1) != $checksum)
- {
+ } elseif (substr($id, -1, 1) != $checksum) {
return FALSE;
}
break;
case 'GKD':
$checksum = 11 - $checksum;
- if ($checksum == 10)
- {
+ if ($checksum == 10) {
$checksum = 'X';
}
- if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id))
- {
+ if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
return FALSE;
- } elseif (strtoupper(substr($id, -1, 1)) != $checksum)
- {
+ } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
return FALSE;
}
break;
@@ -145,31 +129,24 @@ class Helper
*
* @return mixed The decrypted value or NULL on error
*/
- public static function decrypt($encrypted, $hash)
- {
+ public static function decrypt($encrypted, $hash) {
$decrypted = NULL;
// Check for PHP extension "mcrypt".
- if (!extension_loaded('mcrypt'))
- {
- if (TYPO3_DLOG)
- {
+ if (!extension_loaded('mcrypt')) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->decrypt('.$encrypted.', '.$hash.')] PHP extension "mcrypt" not available', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
}
if (empty($encrypted)
- || empty($hash))
- {
- if (TYPO3_DLOG)
- {
+ || empty($hash)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->decrypt('.$encrypted.', '.$hash.')] Invalid parameters given for decryption', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
}
- if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']))
- {
- if (TYPO3_DLOG)
- {
+ if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->decrypt('.$encrypted.', '.$hash.')] No encryption key set in TYPO3 configuration', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
@@ -178,10 +155,8 @@ class Helper
$decrypted = mcrypt_decrypt(MCRYPT_BLOWFISH, substr($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 0, 56), base64_decode($encrypted), MCRYPT_MODE_CFB, $iv);
$salt = substr($hash, 0, 10);
$hashed = $salt.substr(sha1($salt.$decrypted), -10);
- if ($hashed !== $hash)
- {
- if (TYPO3_DLOG)
- {
+ if ($hashed !== $hash) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->decrypt('.$encrypted.', '.$hash.')] Invalid hash "'.$hash.'" given for decryption', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
@@ -199,21 +174,16 @@ class Helper
*
* @return array Array with encrypted string and control hash
*/
- public static function encrypt($string)
- {
+ public static function encrypt($string) {
// Check for PHP extension "mcrypt".
- if (!extension_loaded('mcrypt'))
- {
- if (TYPO3_DLOG)
- {
+ if (!extension_loaded('mcrypt')) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->encrypt('.$string.')] PHP extension "mcrypt" not available', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
}
- if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']))
- {
- if (TYPO3_DLOG)
- {
+ if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->encrypt('.$string.')] No encryption key set in TYPO3 configuration', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
@@ -234,8 +204,7 @@ class Helper
*/
public static function getBeUser() {
if (TYPO3_MODE === 'FE'
- || TYPO3_MODE === 'BE')
- {
+ || TYPO3_MODE === 'BE') {
// Initialize backend session with CLI user's rights.
$userObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
$userObj->dontSetCookie = TRUE;
@@ -244,8 +213,7 @@ class Helper
$userObj->backendCheckLogin();
return $userObj;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getBeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
@@ -261,8 +229,7 @@ class Helper
*
* @return string The cleaned up string
*/
- public static function getCleanString($string)
- {
+ public static function getCleanString($string) {
// Convert to lowercase.
$string = strtolower($string);
// Remove non-alphanumeric characters.
@@ -281,21 +248,16 @@ class Helper
*
* @return \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication Instance of \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication or NULL on failure
*/
- public static function getFeUser()
- {
- if (TYPO3_MODE === 'FE')
- {
+ public static function getFeUser() {
+ if (TYPO3_MODE === 'FE') {
// Check if a user is currently logged in.
- if (!empty($GLOBALS['TSFE']->loginUser))
- {
+ if (!empty($GLOBALS['TSFE']->loginUser)) {
return $GLOBALS['TSFE']->fe_user;
- } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID') !== NULL)
- {
+ } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID') !== NULL) {
return \TYPO3\CMS\Frontend\Utility\EidUtility::initFeUser();
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getFeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
@@ -311,13 +273,10 @@ class Helper
*
* @return array Array of hook objects for the class
*/
- public static function getHookObjects($scriptRelPath)
- {
+ public static function getHookObjects($scriptRelPath) {
$hookObjects = [];
- if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass']))
- {
- foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'] as $classRef)
- {
+ if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'])) {
+ foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'] as $classRef) {
$hookObjects[] = &\TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
}
}
@@ -335,26 +294,22 @@ class Helper
*
* @return string "index_name" for the given UID
*/
- public static function getIndexName($uid, $table, $pid = -1)
- {
+ public static function getIndexName($uid, $table, $pid = -1) {
// Save parameters for logging purposes.
$_uid = $uid;
$_pid = $pid;
// Sanitize input.
$uid = max(intval($uid), 0);
if (!$uid
- || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores']))
- {
- if (TYPO3_DLOG)
- {
+ || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] Invalid UID "'.$uid.'" or table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return '';
}
$where = '';
// Should we check for a specific PID, too?
- if ($pid !== -1)
- {
+ if ($pid !== -1) {
$pid = max(intval($pid), 0);
$where = ' AND '.$table.'.pid='.$pid;
}
@@ -369,13 +324,11 @@ class Helper
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
return $resArray['index_name'];
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] No "index_name" with UID "'.$uid.'" and PID "'.$pid.'" found in table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
@@ -393,24 +346,20 @@ class Helper
*
* @return string "uid" for the given index_name
*/
- public static function getIdFromIndexName($index_name, $table, $pid = -1)
- {
+ public static function getIdFromIndexName($index_name, $table, $pid = -1) {
// Save parameters for logging purposes.
$_index_name = $index_name;
$_pid = $pid;
if (!$index_name
- || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores']))
- {
- if (TYPO3_DLOG)
- {
+ || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'])) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getIdFromIndexName('.$_index_name.', '.$table.', '.$_pid.')] Invalid UID "'.$index_name.'" or table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return '';
}
$where = '';
// Should we check for a specific PID, too?
- if ($pid !== -1)
- {
+ if ($pid !== -1) {
$pid = max(intval($pid), 0);
$where = ' AND '.$table.'.pid='.$pid;
}
@@ -425,13 +374,11 @@ class Helper
'',
'1'
);
- if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)
- {
+ if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
return $resArray['uid'];
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getIdFromIndexName('.$_index_name.', '.$table.', '.$_pid.')] No UID for given "index_name" "'.$index_name.'" and PID "'.$pid.'" found in table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
@@ -447,48 +394,38 @@ class Helper
*
* @return string Localized full name of language or unchanged input
*/
- public static function getLanguageName($code)
- {
+ public static function getLanguageName($code) {
// Analyze code and set appropriate ISO table.
$isoCode = strtolower(trim($code));
- if (preg_match('/^[a-z]{3}$/', $isoCode))
- {
+ if (preg_match('/^[a-z]{3}$/', $isoCode)) {
$file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'Resources/Private/ISO-639/iso-639-2b.xml';
- } elseif (preg_match('/^[a-z]{2}$/', $isoCode))
- {
+ } elseif (preg_match('/^[a-z]{2}$/', $isoCode)) {
$file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'Resources/Private/ISO-639/iso-639-1.xml';
} else {
// No ISO code, return unchanged.
return $code;
}
// Load ISO table and get localized full name of language.
- if (TYPO3_MODE === 'FE')
- {
+ if (TYPO3_MODE === 'FE') {
$iso639 = $GLOBALS['TSFE']->readLLfile($file);
- if (!empty($iso639['default'][$isoCode]))
- {
+ if (!empty($iso639['default'][$isoCode])) {
$lang = $GLOBALS['TSFE']->getLLL($isoCode, $iso639);
}
- } elseif (TYPO3_MODE === 'BE')
- {
+ } elseif (TYPO3_MODE === 'BE') {
$iso639 = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE);
- if (!empty($iso639['default'][$isoCode]))
- {
+ if (!empty($iso639['default'][$isoCode])) {
$lang = $GLOBALS['LANG']->getLLL($isoCode, $iso639, FALSE);
}
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getLanguageName('.$code.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return $code;
}
- if (!empty($lang))
- {
+ if (!empty($lang)) {
return $lang;
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getLanguageName('.$code.')] Language code "'.$code.'" not found in ISO-639 table', self::$extKey, SYSLOG_SEVERITY_NOTICE);
}
return $code;
@@ -506,42 +443,32 @@ class Helper
*
* @return string The translated string or the given key on failure
*/
- public static function getMessage($key, $hsc = FALSE, $default = '')
- {
+ public static function getMessage($key, $hsc = FALSE, $default = '') {
// Set initial output to default value.
$translated = (string) $default;
// Load common messages file.
- if (empty(self::$messages))
- {
+ if (empty(self::$messages)) {
$file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey, 'Resources/Private/Language/FlashMessages.xml');
- if (TYPO3_MODE === 'FE')
- {
+ if (TYPO3_MODE === 'FE') {
self::$messages = $GLOBALS['TSFE']->readLLfile($file);
- } elseif (TYPO3_MODE === 'BE')
- {
+ } elseif (TYPO3_MODE === 'BE') {
self::$messages = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE);
- } elseif (TYPO3_DLOG)
- {
+ } elseif (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getMessage('.$key.', '.$default.', ['.($hsc ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
// Get translation.
- if (!empty(self::$messages['default'][$key]))
- {
- if (TYPO3_MODE === 'FE')
- {
+ if (!empty(self::$messages['default'][$key])) {
+ if (TYPO3_MODE === 'FE') {
$translated = $GLOBALS['TSFE']->getLLL($key, self::$messages);
- } elseif (TYPO3_MODE === 'BE')
- {
+ } elseif (TYPO3_MODE === 'BE') {
$translated = $GLOBALS['LANG']->getLLL($key, self::$messages, FALSE);
- } elseif (TYPO3_DLOG)
- {
+ } elseif (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getMessage('.$key.', '.$default.', ['.($hsc ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
}
// Escape HTML characters if applicable.
- if ($hsc)
- {
+ if ($hsc) {
$translated = htmlspecialchars($translated);
}
return $translated;
@@ -558,8 +485,7 @@ class Helper
*
* @return string Uniform Resource Name as string
*/
- public static function getURN($base, $id)
- {
+ public static function getURN($base, $id) {
$concordance = [
'0' => 1,
'1' => 2,
@@ -601,22 +527,18 @@ class Helper
':' => 17,
];
$urn = strtolower($base.$id);
- if (preg_match('/[^a-z0-9:-]/', $urn))
- {
- if (TYPO3_DLOG)
- {
+ if (preg_match('/[^a-z0-9:-]/', $urn)) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->getURN('.$base.', '.$id.')] Invalid chars in given parameters', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
}
$digits = '';
- for ($i = 0, $j = strlen($urn); $i < $j; $i++)
- {
+ for ($i = 0, $j = strlen($urn); $i < $j; $i++) {
$digits .= $concordance[substr($urn, $i, 1)];
}
$checksum = 0;
- for ($i = 0, $j = strlen($digits); $i < $j; $i++)
- {
+ for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
$checksum += ($i + 1) * intval(substr($digits, $i, 1));
}
$checksum = substr(intval($checksum / intval(substr($digits, -1, 1))), -1, 1);
@@ -632,8 +554,7 @@ class Helper
*
* @return boolean Is $id a valid PPN?
*/
- public static function isPPN($id)
- {
+ public static function isPPN($id) {
return self::checkIdentifier($id, 'PPN');
}
@@ -646,30 +567,24 @@ class Helper
*
* @return mixed Session value for given key or NULL on failure
*/
- public static function loadFromSession($key)
- {
+ public static function loadFromSession($key) {
// Save parameter for logging purposes.
$_key = $key;
// Cast to string for security reasons.
$key = (string) $key;
- if (!$key)
- {
- if (TYPO3_DLOG)
- {
+ if (!$key) {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->loadFromSession('.$_key.')] Invalid key "'.$key.'" for session data retrieval', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
}
// Get the session data.
- if (TYPO3_MODE === 'FE')
- {
+ if (TYPO3_MODE === 'FE') {
return $GLOBALS['TSFE']->fe_user->getKey('ses', $key);
- } elseif (TYPO3_MODE === 'BE')
- {
+ } elseif (TYPO3_MODE === 'BE') {
return $GLOBALS['BE_USER']->getSessionData($key);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->loadFromSession('.$_key.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
@@ -688,16 +603,14 @@ class Helper
*
* @return array Array of substituted "NEW..." identifiers and their actual UIDs.
*/
- public static function processDB(array $data = [], array $cmd = [], $reverseOrder = FALSE, $be_user = FALSE)
- {
+ public static function processDB(array $data = [], array $cmd = [], $reverseOrder = FALSE, $be_user = FALSE) {
// Instantiate TYPO3 core engine.
$tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
// Set some configuration variables.
$tce->stripslashes_values = FALSE;
// Get backend user for processing.
if ($be_user
- && isset($GLOBALS['BE_USER']))
- {
+ && isset($GLOBALS['BE_USER'])) {
$user = $GLOBALS['BE_USER'];
} else {
$user = self::getBeUser();
@@ -706,19 +619,16 @@ class Helper
$tce->start($data, $cmd, $user);
// Process command map first if default order is reversed.
if ($cmd
- && $reverseOrder)
- {
+ && $reverseOrder) {
$tce->process_cmdmap();
}
// Process data map.
- if ($data)
- {
+ if ($data) {
$tce->process_datamap();
}
// Process command map if processing order is not reversed.
if ($cmd
- && !$reverseOrder)
- {
+ && !$reverseOrder) {
$tce->process_cmdmap();
}
return $tce->substNEWwithIDs;
@@ -735,15 +645,12 @@ class Helper
*
* @return array Array of substituted "NEW..." identifiers and their actual UIDs.
*/
- public static function processDBasAdmin(array $data = [], array $cmd = [], $reverseOrder = FALSE)
- {
+ public static function processDBasAdmin(array $data = [], array $cmd = [], $reverseOrder = FALSE) {
if (TYPO3_MODE === 'BE'
- && $GLOBALS['BE_USER']->isAdmin())
- {
+ && $GLOBALS['BE_USER']->isAdmin()) {
return self::processDB($data, $cmd, $reverseOrder, TRUE);
} else {
- if (TYPO3_DLOG)
- {
+ if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[\Kitodo\Dlf\Common\Helper->processDBasAdmin([data->data], [data->cmd], ['.($reverseOrder ? 'TRUE' : 'FALSE').'])] Current backend user has no admin privileges', self::$extKey, SYSLOG_SEVERITY_ERROR, ['data' => $data, 'cmd' => $cmd]);
}
return [];
@@ -757,24 +664,20 @@ class Helper
*
* @return string All flash messages in the queue rendered as HTML.
*/
- public static function renderFlashMessages()
- {
+ public static function renderFlashMessages() {
$flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$content = '';
// Since TYPO3 7.4.0, \TYPO3\CMS\Core\Messaging\FlashMessageQueue::renderFlashMessages
// uses htmlspecialchars on all texts, but we have message text with HTML tags.
// Therefore we copy the implementation from 7.4.0, but remove the htmlspecialchars call.
$flashMessages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
- if (!empty($flashMessages))
- {
+ if (!empty($flashMessages)) {
$content .= '