Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#659)
by
unknown
03:09
created

ToolboxController::getPageLink()   B

Complexity

Conditions 10
Paths 32

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 36
rs 7.6666
cc 10
nc 32
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 \TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Config...on\ConfigurationManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Core\Utility\MathUtility;
17
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
18
use Kitodo\Dlf\Common\Document;
19
use Kitodo\Dlf\Common\Helper;
20
use TYPO3\CMS\Core\Database\ConnectionPool;
21
use \Kitodo\Dlf\Domain\Model\SearchForm;
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Domain\Model\SearchForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
class ToolboxController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Mvc\Controller\ActionController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
{
25
    public $prefixId = 'tx_dlf';
26
    public $extKey = 'dlf';
27
28
    /**
29
     * @var ConfigurationManager
30
     */
31
    protected $configurationManager;
32
33
    /**
34
     * @var \TYPO3\CMS\Core\Log\LogManager
35
     */
36
    protected $logger;
37
38
    /**
39
     * @var
40
     */
41
    protected $extConf;
42
43
    /**
44
     * Holds the controls to add to the map
45
     *
46
     * @var array
47
     * @access protected
48
     */
49
    protected $controls = [];
50
51
    /**
52
     * SearchController constructor.
53
     * @param $configurationManager
54
     */
55
    public function __construct(ConfigurationManager $configurationManager)
56
    {
57
        $this->configurationManager = $configurationManager;
58
        $this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
59
    }
60
61
    // TODO: Needs to be placed in an abstract class
62
    /**
63
     * Loads the current document into $this->doc
64
     *
65
     * @access protected
66
     *
67
     * @return void
68
     */
69
    protected function loadDocument($requestData)
70
    {
71
        // Check for required variable.
72
        if (
73
            !empty($requestData['id'])
74
            && !empty($this->settings['pages'])
75
        ) {
76
            // Should we exclude documents from other pages than $this->settings['pages']?
77
            $pid = (!empty($this->settings['excludeOther']) ? intval($this->settings['pages']) : 0);
78
            // Get instance of \Kitodo\Dlf\Common\Document.
79
            $this->doc = Document::getInstance($requestData['id'], $pid);
0 ignored issues
show
Bug Best Practice introduced by
The property doc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
80
            if (!$this->doc->ready) {
81
                // Destroy the incomplete object.
82
                $this->doc = null;
83
                $this->logger->error('Failed to load document with UID ' . $requestData['id']);
1 ignored issue
show
Bug introduced by
The method error() does not exist on TYPO3\CMS\Core\Log\LogManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
                $this->logger->/** @scrutinizer ignore-call */ 
84
                               error('Failed to load document with UID ' . $requestData['id']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
            } else {
85
                // Set configuration PID.
86
                $this->doc->cPid = $this->settings['pages'];
87
            }
88
        } elseif (!empty($requestData['recordId'])) {
89
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
90
                ->getQueryBuilderForTable('tx_dlf_documents');
91
92
            // Get UID of document with given record identifier.
93
            $result = $queryBuilder
94
                ->select('tx_dlf_documents.uid AS uid')
95
                ->from('tx_dlf_documents')
96
                ->where(
97
                    $queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($requestData['recordId'])),
98
                    Helper::whereExpression('tx_dlf_documents')
99
                )
100
                ->setMaxResults(1)
101
                ->execute();
102
103
            if ($resArray = $result->fetch()) {
104
                $requestData['id'] = $resArray['uid'];
105
                // Set superglobal $_GET array and unset variables to avoid infinite looping.
106
                $_GET[$this->prefixId]['id'] = $requestData['id'];
107
                unset($requestData['recordId'], $_GET[$this->prefixId]['recordId']);
108
                // Try to load document.
109
                $this->loadDocument();
0 ignored issues
show
Bug introduced by
The call to Kitodo\Dlf\Controller\To...troller::loadDocument() has too few arguments starting with requestData. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
                $this->/** @scrutinizer ignore-call */ 
110
                       loadDocument();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
110
            } else {
111
                $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"');
112
            }
113
        } else {
114
            $this->logger->error('Invalid UID ' . $requestData['id'] . ' or PID ' . $this->settings['pages'] . ' for document loading');
115
        }
116
    }
117
118
    /**
119
     * Main method toolbox
120
     */
121
    public function mainAction()
122
    {
123
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
124
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
125
126
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extKey);
127
128
        // Quit without doing anything if required variable is not set.
129
        if (empty($requestData['id'])) {
130
            return '';
131
        }
132
133
        // Load current document.
134
        $this->loadDocument($requestData);
135
136
        $tools = explode(',', $this->settings['tools']);
137
        // Add the tools to the toolbox.
138
        foreach ($tools as $tool) {
139
            $tool = trim(str_replace('tx_dlf_', '', $tool));
140
            $this->$tool($requestData);
141
            $this->view->assign($tool, true);
142
        }
143
    }
144
145
    /**
146
     * Renders the annotation tool
147
     * @param $requestData
148
     * @return string|void
149
     */
150
    public function annotationtool($requestData) {
151
        if (
152
            $this->doc === null
153
            || $this->doc->numPages < 1
154
        ) {
155
            // Quit without doing anything if required variables are not set.
156
            return '';
157
        } else {
158
            if (!empty($requestData['logicalPage'])) {
159
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
160
                // The logical page parameter should not appear again
161
                unset($requestData['logicalPage']);
162
            }
163
            // Set default values if not set.
164
            // $requestData['page'] may be integer or string (physical structure @ID)
165
            if (
166
                (int) $requestData['page'] > 0
167
                || empty($requestData['page'])
168
            ) {
169
                $requestData['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
170
            } else {
171
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
172
            }
173
            $requestData['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
174
        }
175
176
        $annotationContainers = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['annotationContainers'];
177
        if (
178
            $annotationContainers != null
179
            && sizeof($annotationContainers) > 0
180
        ) {
181
            $this->view->assign('annotationTool', true);
182
        } else {
183
            $this->view->assign('annotationTool', false);
184
        }
185
    }
186
187
    /**
188
     * Renders the fulltext download tool
189
     * @param $requestData
190
     * @return string|void
191
     */
192
    public function fulltextdownloadtool($requestData) {
193
        if (
194
            $this->doc === null
195
            || $this->doc->numPages < 1
196
            || empty($this->extConf['fileGrpFulltext'])
197
        ) {
198
            // Quit without doing anything if required variables are not set.
199
            return '';
200
        } else {
201
            if (!empty($requestData['logicalPage'])) {
202
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
203
                // The logical page parameter should not appear again
204
                unset($requestData['logicalPage']);
205
            }
206
            // Set default values if not set.
207
            // $requestData['page'] may be integer or string (physical structure @ID)
208
            if (
209
                (int) $requestData['page'] > 0
210
                || empty($requestData['page'])
211
            ) {
212
                $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
213
            } else {
214
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
215
            }
216
            $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
217
        }
218
        // Get text download.
219
        $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
220
        while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
221
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) {
222
                $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext];
223
                break;
224
            }
225
        }
226
        if (!empty($fullTextFile)) {
227
            $this->view->assign('fulltextDownload', true);
228
        } else {
229
            $this->view->assign('fulltextDownload', false);
230
        }
231
    }
232
233
    /**
234
     * Renders the fulltext tool
235
     * @param $requestData
236
     * @return string|void
237
     */
238
    public function fulltexttool($requestData) {
239
        if (
240
            $this->doc === null
241
            || $this->doc->numPages < 1
242
            || empty($this->extConf['fileGrpFulltext'])
243
        ) {
244
            // Quit without doing anything if required variables are not set.
245
            return '';
246
        } else {
247
            if (!empty($requestData['logicalPage'])) {
248
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
249
                // The logical page parameter should not appear again
250
                unset($requestData['logicalPage']);
251
            }
252
            // Set default values if not set.
253
            // $requestData['page'] may be integer or string (physical structure @ID)
254
            if (
255
                (int) $requestData['page'] > 0
256
                || empty($requestData['page'])
257
            ) {
258
                $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
259
            } else {
260
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
261
            }
262
            $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
263
        }
264
        $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
265
        while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
266
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) {
267
                $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext];
268
                break;
269
            }
270
        }
271
        if (!empty($fullTextFile)) {
272
            $this->view->assign('fulltext', true);
273
            $this->view->assign('activateFullTextInitially', MathUtility::forceIntegerInRange($this->settings['activateFullTextInitially'], 0, 1, 0));
274
        } else {
275
            $this->view->assign('fulltext', false);
276
        }
277
    }
278
279
    /**
280
     * Renders the image download tool
281
     * @param $requestData
282
     * @return string|void
283
     */
284
    public function imagedownloadtool($requestData) {
285
        if (
286
            $this->doc === null
287
            || $this->doc->numPages < 1
288
            || empty($this->settings['fileGrpsImageDownload'])
289
        ) {
290
            // Quit without doing anything if required variables are not set.
291
            return '';
292
        } else {
293
            if (!empty($requestData['logicalPage'])) {
294
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
295
                // The logical page parameter should not appear again
296
                unset($requestData['logicalPage']);
297
            }
298
            // Set default values if not set.
299
            // $requestData['page'] may be integer or string (physical structure @ID)
300
            if (
301
                (int) $requestData['page'] > 0
302
                || empty($requestData['page'])
303
            ) {
304
                $requestData['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
305
            } else {
306
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
307
            }
308
            $requestData['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
309
        }
310
        $imageArray = [];
311
        // Get left or single page download.
312
        if ($requestData['double'] == 1) {
313
            $imageArray['left'] = $this->getImage($requestData['page'], $this->pi_getLL('leftPage', ''));
0 ignored issues
show
Unused Code introduced by
The call to Kitodo\Dlf\Controller\To...xController::pi_getLL() has too many arguments starting with ''. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

313
            $imageArray['left'] = $this->getImage($requestData['page'], $this->/** @scrutinizer ignore-call */ pi_getLL('leftPage', ''));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
314
            $imageArray['right'] = $this->getImage($requestData['page'] + 1, $this->pi_getLL('rightPage', ''));
315
        } else {
316
            $imageArray['left'] = $this->getImage($requestData['page'], $this->pi_getLL('singlePage', ''));
317
        }
318
        $this->view->assign('imageDownload', $imageArray);
319
    }
320
321
    /**
322
     * Get image's URL and MIME type
323
     *
324
     * @access protected
325
     *
326
     * @param int $page: Page number
327
     * @param string $label: Link title and label
328
     *
329
     * @return string Link to image file with given label
330
     */
331
    protected function getImage($page, $label)
332
    {
333
        $image = [];
334
        // Get @USE value of METS fileGrp.
335
        $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']);
336
        while ($fileGrp = @array_pop($fileGrps)) {
337
            // Get image link.
338
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) {
339
                $image['url'] = $this->doc->getDownloadLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
340
                $image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
341
                switch ($image['mimetype']) {
342
                    case 'image/jpeg':
343
                        $mimetypeLabel = ' (JPG)';
344
                        break;
345
                    case 'image/tiff':
346
                        $mimetypeLabel = ' (TIFF)';
347
                        break;
348
                    default:
349
                        $mimetypeLabel = '';
350
                }
351
                $image['title'] = $label . $mimetypeLabel;
352
                break;
353
            } else {
354
                $this->logger->warning('File not found in fileGrp "' . $fileGrp . '"');
1 ignored issue
show
Bug introduced by
The method warning() does not exist on TYPO3\CMS\Core\Log\LogManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

354
                $this->logger->/** @scrutinizer ignore-call */ 
355
                               warning('File not found in fileGrp "' . $fileGrp . '"');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
355
            }
356
        }
357
        return $image;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $image returns the type array which is incompatible with the documented return type string.
Loading history...
358
    }
359
360
    /**
361
     * Renders the image manipulation tool
362
     * @param $requestData
363
     */
364
    public function imagemanipulationtool($requestData) {
365
        // Set parent element for initialization.
366
        $parentContainer = !empty($this->settings['parentContainer']) ? $this->settings['parentContainer'] : '.tx-dlf-imagemanipulationtool';
367
368
        $this->view->assign('imageManipulation', true);
369
        $this->view->assign('parentContainer', $parentContainer);
370
    }
371
372
    /**
373
     * Renders the PDF download tool
374
     * @param $requestData
375
     * @return string|void
376
     */
377
    public function pdfdownloadtool($requestData) {
378
        if (
379
            $this->doc === null
380
            || $this->doc->numPages < 1
381
            || empty($this->extConf['fileGrpDownload'])
382
        ) {
383
            // Quit without doing anything if required variables are not set.
384
            return '';
385
        } else {
386
            if (!empty($requestData['logicalPage'])) {
387
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
388
                // The logical page parameter should not appear again
389
                unset($requestData['logicalPage']);
390
            }
391
            // Set default values if not set.
392
            // $requestData['page'] may be integer or string (physical structure @ID)
393
            if (
394
                (int) $requestData['page'] > 0
395
                || empty($requestData['page'])
396
            ) {
397
                $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
398
            } else {
399
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
400
            }
401
            $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
402
        }
403
        // Get single page downloads.
404
        $this->view->assign('pageLinks', $this->getPageLink($requestData));
405
        $this->view->assign('double', $requestData['double']);
406
        // Get work download.
407
        $this->view->assign('workLink', $this->getWorkLink());
408
    }
409
410
    /**
411
     * Get page's download link
412
     *
413
     * @access protected
414
     *
415
     * @return array Link to downloadable page
416
     */
417
    protected function getPageLink($requestData)
418
    {
419
        $page1Link = '';
420
        $page2Link = '';
421
        $pageLinkArray = [];
422
        $pageNumber = $requestData['page'];
423
        $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']);
424
        // Get image link.
425
        while ($fileGrpDownload = array_shift($fileGrpsDownload)) {
426
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload])) {
427
                $page1Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload]);
428
                // Get second page, too, if double page view is activated.
429
                if (
430
                    $requestData['double']
431
                    && $pageNumber < $this->doc->numPages
432
                    && !empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload])
433
                ) {
434
                    $page2Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload]);
435
                }
436
                break;
437
            }
438
        }
439
        if (
440
            empty($page1Link)
441
            && empty($page2Link)
442
        ) {
443
            $this->logger->warning('File not found in fileGrps "' . $this->extConf['fileGrpDownload'] . '"');
444
        }
445
446
        if (!empty($page1Link)) {
447
            $pageLinkArray['pageUrl1'] = $page1Link;
448
        }
449
        if (!empty($page2Link)) {
450
            $pageLinkArray['pageUrl2'] = $page2Link;
451
        }
452
        return $pageLinkArray;
453
    }
454
455
    /**
456
     * Get work's download link
457
     *
458
     * @access protected
459
     *
460
     * @return string Link to downloadable work
461
     */
462
    protected function getWorkLink()
463
    {
464
        $workLink = '';
465
        $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']);
466
        // Get work link.
467
        while ($fileGrpDownload = array_shift($fileGrpsDownload)) {
468
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload])) {
469
                $workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload]);
470
                break;
471
            } else {
472
                $details = $this->doc->getLogicalStructure($this->doc->toplevelId);
473
                if (!empty($details['files'][$fileGrpDownload])) {
474
                    $workLink = $this->doc->getFileLocation($details['files'][$fileGrpDownload]);
475
                    break;
476
                }
477
            }
478
        }
479
        if (!empty($workLink)) {
480
            $workLink = $workLink;
481
        } else {
482
            $this->logger->warning('File not found in fileGrp "' . $this->conf['settings.fileGrpDownload'] . '"');
483
        }
484
        return $workLink;
485
    }
486
487
    /**
488
     * Renders the searchInDocument tool
489
     * @param $requestData
490
     * @return string|void
491
     */
492
    public function searchindocumenttool($requestData) {
493
        if (
494
            $this->doc === null
495
            || $this->doc->numPages < 1
496
            || empty($this->extConf['fileGrpFulltext'])
497
            || empty($this->settings['solrcore'])
498
        ) {
499
            // Quit without doing anything if required variables are not set.
500
            return '';
501
        } else {
502
            if (!empty($requestData['logicalPage'])) {
503
                $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']);
504
                // The logical page parameter should not appear again
505
                unset($requestData['logicalPage']);
506
            }
507
            // Set default values if not set.
508
            // $requestData['page'] may be integer or string (physical structure @ID)
509
            if (
510
                (int) $requestData['page'] > 0
511
                || empty($requestData['page'])
512
            ) {
513
                $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
514
            } else {
515
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
516
            }
517
        }
518
519
        // Quit if no fulltext file is present
520
        $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->settings['fileGrpFulltext']);
521
        while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
522
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) {
523
                $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext];
524
                break;
525
            }
526
        }
527
        if (empty($fullTextFile)) {
528
            return '';
529
        }
530
531
        // Fill markers.
532
        $viewArray = [
533
            'ACTION_URL' => $this->getActionUrl(),
534
            'LABEL_QUERY_URL' => $this->settings['queryInputName'],
535
            'LABEL_START' => $this->settings['startInputName'],
536
            'LABEL_ID' => $this->settings['idInputName'],
537
            'LABEL_PAGE_URL' => $this->settings['pageInputName'],
538
            'LABEL_HIGHLIGHT_WORD' => $this->settings['highlightWordInputName'],
539
            'LABEL_ENCRYPTED' => $this->settings['encryptedInputName'],
540
            'CURRENT_DOCUMENT' => $this->getCurrentDocumentId(),
541
            'SOLR_ENCRYPTED' => $this->getEncryptedCoreName() ? : ''
542
        ];
543
544
        $this->view->assign('searchInDocument', $viewArray);
545
    }
546
547
    /**
548
     * Get the action url for search form
549
     *
550
     * @access protected
551
     *
552
     * @return string with action url for search form
553
     */
554
    protected function getActionUrl()
555
    {
556
        // Configure @action URL for form.
557
        $uri = $this->uriBuilder->reset()
558
            ->setTargetPageUid($GLOBALS['TSFE']->id)
559
            ->setCreateAbsoluteUri(true)
560
            ->build();
561
562
        $actionUrl = $uri;
563
564
        if (!empty($this->settings['searchUrl'])) {
565
            $actionUrl = $this->settings['searchUrl'];
566
        }
567
        return $actionUrl;
568
    }
569
570
    /**
571
     * Get current document id
572
     *
573
     * @access protected
574
     *
575
     * @return string with current document id
576
     */
577
    protected function getCurrentDocumentId()
578
    {
579
        $id = $this->doc->uid;
580
581
        if (!empty($this->settings['documentIdUrlSchema'])) {
582
            $arr = explode('*', $this->settings['documentIdUrlSchema']);
583
584
            if (count($arr) == 2) {
585
                $id = explode($arr[0], $id)[0];
586
            } else if (count($arr) == 3) {
587
                $sub = substr($id, strpos($id, $arr[0]) + strlen($arr[0]), strlen($id));
588
                $id = substr($sub, 0, strpos($sub, $arr[2]));
589
            }
590
        }
591
        return $id;
592
    }
593
594
    /**
595
     * Get the encrypted Solr core name
596
     *
597
     * @access protected
598
     *
599
     * @return string with encrypted core name
600
     */
601
    protected function getEncryptedCoreName()
602
    {
603
        // Get core name.
604
        $name = Helper::getIndexNameFromUid($this->conf['settings.solrcore'], 'tx_dlf_solrcores');
605
        // Encrypt core name.
606
        if (!empty($name)) {
607
            $name = Helper::encrypt($name);
608
        }
609
        return $name;
610
    }
611
612
    /**
613
     * Translate helper function
614
     * @param $label
615
     * @return mixed
616
     */
617
    protected function pi_getLL($label)
618
    {
619
        return $GLOBALS['TSFE']->sL('LLL:EXT:dlf/Resources/Private/Language/Toolbox.xml:' . $label);
620
    }
621
}