| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * (c) Kitodo. Key to digital objects e.V. <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Kitodo\Dlf\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Kitodo\Dlf\Common\Doc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Kitodo\Dlf\Common\Helper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Kitodo\Dlf\Domain\Model\Document; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Kitodo\Dlf\Domain\Repository\DocumentRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Psr\Log\LoggerAwareInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Psr\Log\LoggerAwareTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use TYPO3\CMS\Core\Database\ConnectionPool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use TYPO3\CMS\Core\Localization\LanguageService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use TYPO3\CMS\Core\Utility\GeneralUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use TYPO3\CMS\Core\Utility\MathUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     use LoggerAwareTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @var DocumentRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     protected $documentRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param DocumentRepository $documentRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function injectDocumentRepository(DocumentRepository $documentRepository) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->documentRepository = $documentRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * This holds the current document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @var \Kitodo\Dlf\Domain\Model\Document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     protected $document; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     protected $extConf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * This holds the request parameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     protected $requestData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * This holds some common data for the fluid view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     protected $viewData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Initialize the plugin controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     protected function initialize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->requestData = GeneralUtility::_GPmerged('tx_dlf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         if (empty($this->requestData['page'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $this->requestData['page'] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         // Get extension configuration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->viewData = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'pageUid' => $GLOBALS['TSFE']->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'requestData' => $this->requestData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * Loads the current document into $this->document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param array $requestData: The request data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     protected function loadDocument($requestData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         // Try to get document format from database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if (!empty($requestData['id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $doc = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 // find document from repository by uid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 if ($this->document) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                     $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                     $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             } else if (GeneralUtility::isValidUrl($requestData['id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                 $doc = Doc::getInstance($requestData['id'], $this->settings, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 if ($doc !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                     if ($doc->recordId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                         $this->document = $this->documentRepository->findOneByRecordId($doc->recordId); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                     if ($this->document === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                         // create new dummy Document object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                         $this->document = GeneralUtility::makeInstance(Document::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                     $this->document->setLocation($requestData['id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                     $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             if ($this->document !== null && $doc !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 $this->document->setDoc($doc); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } elseif (!empty($requestData['recordId'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             if ($this->document !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                 $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                 if ($this->document !== null && $doc !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                     $this->document->setDoc($doc); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |                     $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $this->logger->error('Invalid ID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * Returns the LanguageService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @return LanguageService | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |     protected function getLanguageService(): LanguageService | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |         return $GLOBALS['LANG']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * Safely gets Parameters from request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * if they exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @param string $parameterName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @return null|string|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     protected function getParametersSafely($parameterName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         if ($this->request->hasArgument($parameterName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             return $this->request->getArgument($parameterName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      * This is the constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         $this->initialize(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 202 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 203 |  |  |  |