Update code style
This commit is contained in:
parent
425aedde5a
commit
b3887bdbad
|
@ -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.
|
||||
|
|
|
@ -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 = '<div class="tx-dlf-'.get_class($this).'">'.$content.'</div>';
|
||||
if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment'])
|
||||
{
|
||||
if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
|
||||
$content = "\n\n<!-- BEGIN: Content of extension '".$this->extKey."', plugin '".get_class($this)."' -->\n\n".$content."\n\n<!-- END: Content of extension '".$this->extKey."', plugin '".get_class($this)."' -->\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();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ namespace Kitodo\Dlf\Common;
|
|||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
interface FulltextInterface
|
||||
{
|
||||
interface FulltextInterface {
|
||||
/**
|
||||
* This extracts raw fulltext data from XML
|
||||
*
|
||||
|
|
|
@ -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)
|
||||