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
|
|
|
/** |
13
|
|
|
* SearchInDocument tool for the plugin 'Toolbox' of the 'dlf' extension |
14
|
|
|
* |
15
|
|
|
* @author Alexander Bigga <[email protected]> |
16
|
|
|
* @package TYPO3 |
17
|
|
|
* @subpackage tx_dlf |
18
|
|
|
* @access public |
19
|
|
|
*/ |
20
|
|
|
class tx_dlf_toolsSearchindocument extends tx_dlf_plugin { |
21
|
|
|
|
22
|
|
|
public $scriptRelPath = 'plugins/toolbox/tools/searchindocument/class.tx_dlf_toolsSearchindocument.php'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The main method of the PlugIn |
26
|
|
|
* |
27
|
|
|
* @access public |
28
|
|
|
* |
29
|
|
|
* @param string $content: The PlugIn content |
30
|
|
|
* @param array $conf: The PlugIn configuration |
31
|
|
|
* |
32
|
|
|
* @return string The content that is displayed on the website |
33
|
|
|
*/ |
34
|
|
|
public function main($content, $conf) { |
35
|
|
|
|
36
|
|
|
$this->init($conf); |
37
|
|
|
|
38
|
|
|
if (!empty($this->cObj->data['conf'])) { |
39
|
|
|
// Merge configuration with conf array of toolbox. |
40
|
|
|
$this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->addSearchInDocumentJS(); |
44
|
|
|
|
45
|
|
|
// Load current document. |
46
|
|
|
$this->loadDocument(); |
47
|
|
|
|
48
|
|
|
if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpFulltext']) || empty($this->conf['solrcore'])) { |
|
|
|
|
49
|
|
|
|
50
|
|
|
// Quit without doing anything if required variables are not set. |
51
|
|
|
return $content; |
52
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
|
55
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
56
|
|
|
|
57
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
58
|
|
|
// The logical page parameter should not appear again |
59
|
|
|
unset($this->piVars['logicalPage']); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Set default values if not set. |
64
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
65
|
|
|
if ((int) $this->piVars['page'] > 0 || empty($this->piVars['page'])) { |
66
|
|
|
|
67
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
68
|
|
|
|
69
|
|
|
} else { |
70
|
|
|
|
71
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
|
|
|
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// Quit if no fulltext file is present |
78
|
|
|
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']]; |
|
|
|
|
79
|
|
|
|
80
|
|
|
if (empty($fullTextFile)) { |
81
|
|
|
|
82
|
|
|
return $content; |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Load template file. |
87
|
|
|
if (!empty($this->conf['toolTemplateFile'])) { |
88
|
|
|
|
89
|
|
|
$this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['toolTemplateFile']), '###TEMPLATE###'); |
90
|
|
|
|
91
|
|
|
} else { |
92
|
|
|
|
93
|
|
|
$this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/searchindocument/template.tmpl'), '###TEMPLATE###'); |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Configure @action URL for form. |
98
|
|
|
$linkConf = array( |
99
|
|
|
'parameter' => $GLOBALS['TSFE']->id, |
100
|
|
|
'forceAbsoluteUrl' => 1 |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$encryptedSolr = $this->getEncryptedCoreName(); |
104
|
|
|
|
105
|
|
|
// Fill markers. |
106
|
|
|
$markerArray = array( |
107
|
|
|
'###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf), |
108
|
|
|
'###LABEL_QUERY###' => $this->pi_getLL('label.query'), |
109
|
|
|
'###LABEL_DELETE_SEARCH###' => $this->pi_getLL('label.delete_search'), |
110
|
|
|
'###LABEL_LOADING###' => $this->pi_getLL('label.loading'), |
111
|
|
|
'###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'), |
112
|
|
|
'###LABEL_SEARCH_IN_DOCUMENT###' => $this->pi_getLL('label.searchInDocument'), |
113
|
|
|
'###LABEL_NEXT###' => $this->pi_getLL('label.next'), |
114
|
|
|
'###LABEL_PREVIOUS###' => $this->pi_getLL('label.previous'), |
115
|
|
|
'###LABEL_PAGE###' => $this->pi_getLL('label.logicalPage'), |
116
|
|
|
'###CURRENT_DOCUMENT###' => $this->doc->uid, |
|
|
|
|
117
|
|
|
'###SOLR_ENCRYPTED###' => isset($encryptedSolr['encrypted']) ? $encryptedSolr['encrypted'] : '', |
118
|
|
|
'###SOLR_HASH###' => isset($encryptedSolr['hash']) ? $encryptedSolr['hash'] : '', |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray); |
122
|
|
|
|
123
|
|
|
return $this->pi_wrapInBaseClass($content); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Adds the JS files necessary for search in document |
128
|
|
|
* |
129
|
|
|
* @access protected |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
protected function addSearchInDocumentJS() { |
134
|
|
|
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class); |
135
|
|
|
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/toolbox/tools/searchindocument/tx_dlf_search_in_document.js'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the encrypted Solr core name |
140
|
|
|
* |
141
|
|
|
* @access protected |
142
|
|
|
* |
143
|
|
|
* @return array with encrypted core name and hash |
144
|
|
|
*/ |
145
|
|
|
protected function getEncryptedCoreName() { |
146
|
|
|
// Get core name. |
147
|
|
|
$name = tx_dlf_helper::getIndexName($this->conf['solrcore'], 'tx_dlf_solrcores'); |
148
|
|
|
// Encrypt core name. |
149
|
|
|
if (!empty($name)) { |
150
|
|
|
$name = tx_dlf_helper::encrypt($name); |
151
|
|
|
} |
152
|
|
|
return $name; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|