Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

100 righe
4.2 KiB

  1. <?php
  2. /**
  3. * (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
  4. *
  5. * This file is part of the Kitodo and TYPO3 projects.
  6. *
  7. * @license GNU General Public License version 3 or later.
  8. * For the full copyright and license information, please read the
  9. * LICENSE.txt file that was distributed with this source code.
  10. */
  11. namespace Kitodo\Dlf\Plugin\Tools;
  12. use Kitodo\Dlf\Common\Helper;
  13. use TYPO3\CMS\Core\Utility\GeneralUtility;
  14. use TYPO3\CMS\Core\Utility\MathUtility;
  15. /**
  16. * Fulltext tool for the plugin 'Toolbox' of the 'dlf' extension
  17. *
  18. * @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
  19. * @author Alexander Bigga <alexander.bigga@slub-dresden.de>
  20. * @package TYPO3
  21. * @subpackage dlf
  22. * @access public
  23. */
  24. class FulltextTool extends \Kitodo\Dlf\Common\AbstractPlugin
  25. {
  26. public $scriptRelPath = 'Classes/Plugin/Tools/FulltextTool.php';
  27. /**
  28. * The main method of the PlugIn
  29. *
  30. * @access public
  31. *
  32. * @param string $content: The PlugIn content
  33. * @param array $conf: The PlugIn configuration
  34. *
  35. * @return string The content that is displayed on the website
  36. */
  37. public function main($content, $conf)
  38. {
  39. $this->init($conf);
  40. // Merge configuration with conf array of toolbox.
  41. if (!empty($this->cObj->data['conf'])) {
  42. $this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
  43. }
  44. // Load current document.
  45. $this->loadDocument();
  46. if (
  47. $this->doc === null
  48. || $this->doc->numPages < 1
  49. || empty($this->conf['fileGrpFulltext'])
  50. ) {
  51. // Quit without doing anything if required variables are not set.
  52. return $content;
  53. } else {
  54. if (!empty($this->piVars['logicalPage'])) {
  55. $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
  56. // The logical page parameter should not appear again
  57. unset($this->piVars['logicalPage']);
  58. }
  59. // Set default values if not set.
  60. // $this->piVars['page'] may be integer or string (physical structure @ID)
  61. if (
  62. (int) $this->piVars['page'] > 0
  63. || empty($this->piVars['page'])
  64. ) {
  65. $this->piVars['page'] = MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
  66. } else {
  67. $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
  68. }
  69. $this->piVars['double'] = MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
  70. }
  71. // Load template file.
  72. $this->getTemplate();
  73. $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->conf['fileGrpFulltext']);
  74. while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
  75. if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext])) {
  76. $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext];
  77. break;
  78. }
  79. }
  80. if (!empty($fullTextFile)) {
  81. $markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="'
  82. . 'fulltext:' . htmlspecialchars($this->pi_getLL('fulltext', ''))
  83. . ';fulltext-on:' . htmlspecialchars($this->pi_getLL('fulltext-on', ''))
  84. . ';fulltext-off:' . htmlspecialchars($this->pi_getLL('fulltext-off', ''))
  85. . ';activate-full-text-initially:' . MathUtility::forceIntegerInRange($this->conf['activateFullTextInitially'], 0, 1, 0)
  86. . ';full-text-scroll-element:' . $this->conf['fullTextScrollElement']
  87. . ';search-hl-parameters:' . $this->conf['searchHlParameters'] . '">&nbsp;</a>';
  88. } else {
  89. $markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>';
  90. }
  91. $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
  92. return $this->pi_wrapInBaseClass($content);
  93. }
  94. }