Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

95 wiersze
3.8 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 Download tool for the plugin 'Toolbox' of the 'dlf' extension
  17. *
  18. * @author Beatrycze Volk <beatrycze.volk@slub-dresden.de>
  19. * @package TYPO3
  20. * @subpackage dlf
  21. * @access public
  22. */
  23. class FulltextDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin
  24. {
  25. public $scriptRelPath = 'Classes/Plugin/Tools/FulltextDownloadTool.php';
  26. /**
  27. * The main method of the PlugIn
  28. *
  29. * @access public
  30. *
  31. * @param string $content: The PlugIn content
  32. * @param array $conf: The PlugIn configuration
  33. *
  34. * @return string The content that is displayed on the website
  35. */
  36. public function main($content, $conf)
  37. {
  38. $this->init($conf);
  39. // Merge configuration with conf array of toolbox.
  40. if (!empty($this->cObj->data['conf'])) {
  41. $this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
  42. }
  43. // Load current document.
  44. $this->loadDocument();
  45. if (
  46. $this->doc === null
  47. || $this->doc->numPages < 1
  48. || empty($this->conf['fileGrpFulltext'])
  49. ) {
  50. // Quit without doing anything if required variables are not set.
  51. return $content;
  52. } else {
  53. if (!empty($this->piVars['logicalPage'])) {
  54. $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
  55. // The logical page parameter should not appear again
  56. unset($this->piVars['logicalPage']);
  57. }
  58. // Set default values if not set.
  59. // $this->piVars['page'] may be integer or string (physical structure @ID)
  60. if (
  61. (int) $this->piVars['page'] > 0
  62. || empty($this->piVars['page'])
  63. ) {
  64. $this->piVars['page'] = MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
  65. } else {
  66. $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
  67. }
  68. $this->piVars['double'] = MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
  69. }
  70. // Load template file.
  71. $this->getTemplate();
  72. // Get text download.
  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_DOWNLOAD###'] = '<a href="#" id="tx-dlf-tools-fulltextdownload" title="' . htmlspecialchars($this->pi_getLL('download-current-page', '')) . '">' . htmlspecialchars($this->pi_getLL('download-current-page', '')) . '</a>';
  82. } else {
  83. $markerArray['###FULLTEXT_DOWNLOAD###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>';
  84. }
  85. $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
  86. return $this->pi_wrapInBaseClass($content);
  87. }
  88. }