|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kitodo\Dlf\Plugin; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU General Public License version 3 or later. |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Plugin 'Table Of Contents' for the 'dlf' extension |
|
18
|
|
|
* |
|
19
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
20
|
|
|
* @package TYPO3 |
|
21
|
|
|
* @subpackage dlf |
|
22
|
|
|
* @access public |
|
23
|
|
|
*/ |
|
24
|
|
|
class TableOfContents extends \Kitodo\Dlf\Common\AbstractPlugin { |
|
25
|
|
|
public $scriptRelPath = 'Classes/Plugin/TableOfContents.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* This holds the active entries according to the currently selected page |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
* @access protected |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $activeEntries = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* This builds an array for one menu entry |
|
37
|
|
|
* |
|
38
|
|
|
* @access protected |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $entry: The entry's array from \Kitodo\Dlf\Common\Document->getLogicalStructure |
|
41
|
|
|
* @param boolean $recursive: Whether to include the child entries |
|
42
|
|
|
* |
|
43
|
|
|
* @return array HMENU array for menu entry |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getMenuEntry(array $entry, $recursive = FALSE) { |
|
46
|
|
|
$entryArray = []; |
|
47
|
|
|
// Set "title", "volume", "type" and "pagination" from $entry array. |
|
48
|
|
|
$entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
|
49
|
|
|
$entryArray['volume'] = $entry['volume']; |
|
50
|
|
|
$entryArray['orderlabel'] = $entry['orderlabel']; |
|
51
|
|
|
$entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->conf['pages']); |
|
52
|
|
|
$entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
|
53
|
|
|
$entryArray['_OVERRIDE_HREF'] = ''; |
|
54
|
|
|
$entryArray['doNotLinkIt'] = 1; |
|
55
|
|
|
$entryArray['ITEM_STATE'] = 'NO'; |
|
56
|
|
|
// Build menu links based on the $entry['points'] array. |
|
57
|
|
|
if (!empty($entry['points']) |
|
58
|
|
|
&& \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($entry['points'])) { |
|
59
|
|
|
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(['page' => $entry['points']], TRUE, FALSE, $this->conf['targetPid']); |
|
60
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
61
|
|
|
if ($this->conf['basketButton']) { |
|
62
|
|
|
$entryArray['basketButtonHref'] = '<a href="'.$this->pi_linkTP_keepPIvars_url(['addToBasket' => 'toc', 'logId' => $entry['id'], 'startpage' => $entry['points']], TRUE, FALSE, $this->conf['targetBasket']).'">'.$this->pi_getLL('basketButton', '', TRUE).'</a>'; |
|
63
|
|
|
} |
|
64
|
|
|
} elseif (!empty($entry['points']) |
|
65
|
|
|
&& is_string($entry['points'])) { |
|
66
|
|
|
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(['id' => $entry['points'], 'page' => 1], TRUE, FALSE, $this->conf['targetPid']); |
|
67
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
68
|
|
|
if ($this->conf['basketButton']) { |
|
69
|
|
|
$entryArray['basketButtonHref'] = '<a href="'.$this->pi_linkTP_keepPIvars_url(['addToBasket' => 'toc', 'logId' => $entry['id'], 'startpage' => $entry['points']], TRUE, FALSE, $this->conf['targetBasket']).'">'.$this->pi_getLL('basketButton', '', TRUE).'</a>'; |
|
70
|
|
|
} |
|
71
|
|
|
} elseif (!empty($entry['targetUid'])) { |
|
72
|
|
|
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(['id' => $entry['targetUid'], 'page' => 1], TRUE, FALSE, $this->conf['targetPid']); |
|
73
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
74
|
|
|
if ($this->conf['basketButton']) { |
|
75
|
|
|
$entryArray['basketButtonHref'] = '<a href="'.$this->pi_linkTP_keepPIvars_url(['addToBasket' => 'toc', 'logId' => $entry['id'], 'startpage' => $entry['targetUid']], TRUE, FALSE, $this->conf['targetBasket']).'">'.$this->pi_getLL('basketButton', '', TRUE).'</a>'; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
// Set "ITEM_STATE" to "CUR" if this entry points to current page. |
|
79
|
|
|
if (in_array($entry['id'], $this->activeEntries)) { |
|
80
|
|
|
$entryArray['ITEM_STATE'] = 'CUR'; |
|
81
|
|
|
} |
|
82
|
|
|
// Build sub-menu if available and called recursively. |
|
83
|
|
|
if ($recursive == TRUE |
|
84
|
|
|
&& !empty($entry['children'])) { |
|
85
|
|
|
// Build sub-menu only if one of the following conditions apply: |
|
86
|
|
|
// 1. "expAll" is set for menu |
|
87
|
|
|
// 2. Current menu node is in rootline |
|
88
|
|
|
// 3. Current menu node points to another file |
|
89
|
|
|
// 4. Current menu node has no corresponding images |
|
90
|
|
|
if (!empty($this->conf['menuConf.']['expAll']) |
|
91
|
|
|
|| $entryArray['ITEM_STATE'] == 'CUR' |
|
92
|
|
|
|| is_string($entry['points']) |
|
93
|
|
|
|| empty($this->doc->smLinks['l2p'][$entry['id']])) { |
|
|
|
|
|
|
94
|
|
|
$entryArray['_SUB_MENU'] = []; |
|
95
|
|
|
foreach ($entry['children'] as $child) { |
|
96
|
|
|
// Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
|
97
|
|
|
if (in_array($child['id'], $this->activeEntries)) { |
|
98
|
|
|
$entryArray['ITEM_STATE'] = 'ACT'; |
|
99
|
|
|
} |
|
100
|
|
|
$entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, TRUE); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
// Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
|
104
|
|
|
$entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'].'IFSUB'); |
|
105
|
|
|
} |
|
106
|
|
|
return $entryArray; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* The main method of the PlugIn |
|
111
|
|
|
* |
|
112
|
|
|
* @access public |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $content: The PlugIn content |
|
115
|
|
|
* @param array $conf: The PlugIn configuration |
|
116
|
|
|
* |
|
117
|
|
|
* @return string The content that is displayed on the website |
|
118
|
|
|
*/ |
|
119
|
|
|
public function main($content, $conf) { |
|
120
|
|
|
$this->init($conf); |
|
121
|
|
|
// Check for typoscript configuration to prevent fatal error. |
|
122
|
|
|
if (empty($this->conf['menuConf.'])) { |
|
123
|
|
|
Helper::devLog('Incomplete plugin configuration', DEVLOG_SEVERITY_WARNING); |
|
124
|
|
|
return $content; |
|
125
|
|
|
} |
|
126
|
|
|
// Load template file. |
|
127
|
|
|
$this->getTemplate(); |
|
128
|
|
|
$TSconfig = []; |
|
129
|
|
|
$TSconfig['special'] = 'userfunction'; |
|
130
|
|
|
$TSconfig['special.']['userFunc'] = \Kitodo\Dlf\Plugin\TableOfContents::class.'->makeMenuArray'; |
|
131
|
|
|
$TSconfig = Helper::mergeRecursiveWithOverrule($this->conf['menuConf.'], $TSconfig); |
|
132
|
|
|
$markerArray['###TOCMENU###'] = $this->cObj->cObjGetSingle('HMENU', $TSconfig); |
|
|
|
|
|
|
133
|
|
|
$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray); |
|
|
|
|
|
|
134
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* This builds a menu array for HMENU |
|
139
|
|
|
* |
|
140
|
|
|
* @access public |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $content: The PlugIn content |
|
143
|
|
|
* @param array $conf: The PlugIn configuration |
|
144
|
|
|
* |
|
145
|
|
|
* @return array HMENU array |
|
146
|
|
|
*/ |
|
147
|
|
|
public function makeMenuArray($content, $conf) { |
|
|
|
|
|
|
148
|
|
|
$this->init($conf); |
|
149
|
|
|
// Load current document. |
|
150
|
|
|
$this->loadDocument(); |
|
151
|
|
|
if ($this->doc === NULL) { |
|
152
|
|
|
// Quit without doing anything if required variables are not set. |
|
153
|
|
|
return []; |
|
154
|
|
|
} else { |
|
155
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
|
156
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
|
157
|
|
|
// The logical page parameter should not appear again |
|
158
|
|
|
unset($this->piVars['logicalPage']); |
|
159
|
|
|
} |
|
160
|
|
|
// Set default values for page if not set. |
|
161
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
162
|
|
|
if ((int) $this->piVars['page'] > 0 |
|
163
|
|
|
|| empty($this->piVars['page'])) { |
|
164
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
|
|
|
|
|
165
|
|
|
} else { |
|
166
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
169
|
|
|
} |
|
170
|
|
|
$menuArray = []; |
|
171
|
|
|
// Does the document have physical elements or is it an external file? |
|
172
|
|
|
if ($this->doc->physicalStructure |
|
|
|
|
|
|
173
|
|
|
|| !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->doc->uid)) { |
|
|
|
|
|
|
174
|
|
|
// Get all logical units the current page or track is a part of. |
|
175
|
|
|
if (!empty($this->piVars['page']) |
|
176
|
|
|
&& $this->doc->physicalStructure) { |
|
|
|
|
|
|
177
|
|
|
$this->activeEntries = array_merge((array) $this->doc->smLinks['p2l'][$this->doc->physicalStructure[0]], (array) $this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->piVars['page']]]); |
|
|
|
|
|
|
178
|
|
|
if (!empty($this->piVars['double']) |
|
179
|
|
|
&& $this->piVars['page'] < $this->doc->numPages) { |
|
180
|
|
|
$this->activeEntries = array_merge($this->activeEntries, (array) $this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->piVars['page'] + 1]]); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
// Go through table of contents and create all menu entries. |
|
184
|
|
|
foreach ($this->doc->tableOfContents as $entry) { |
|
|
|
|
|
|
185
|
|
|
$menuArray[] = $this->getMenuEntry($entry, TRUE); |
|
186
|
|
|
} |
|
187
|
|
|
} else { |
|
188
|
|
|
// Go through table of contents and create top-level menu entries. |
|
189
|
|
|
foreach ($this->doc->tableOfContents as $entry) { |
|
190
|
|
|
$menuArray[] = $this->getMenuEntry($entry, FALSE); |
|
191
|
|
|
} |
|
192
|
|
|
// Get all child documents from database. |
|
193
|
|
|
$whereClause = 'tx_dlf_documents.partof='.intval($this->doc->uid).' AND tx_dlf_documents.structure=tx_dlf_structures.uid AND tx_dlf_structures.pid='.$this->doc->pid.Helper::whereClause('tx_dlf_documents').Helper::whereClause('tx_dlf_structures'); |
|
|
|
|
|
|
194
|
|
|
if ($this->conf['excludeOther']) { |
|
195
|
|
|
$whereClause .= ' AND tx_dlf_documents.pid='.intval($this->conf['pages']); |
|
196
|
|
|
} |
|
197
|
|
|
// Build table of contents from database. |
|
198
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
199
|
|
|
'tx_dlf_documents.uid AS uid,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_structures.index_name AS type', |
|
200
|
|
|
'tx_dlf_documents,tx_dlf_structures', |
|
201
|
|
|
$whereClause, |
|
202
|
|
|
'', |
|
203
|
|
|
'tx_dlf_documents.volume_sorting' |
|
204
|
|
|
); |
|
205
|
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
|
206
|
|
|
$menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; |
|
207
|
|
|
$menuArray[0]['_SUB_MENU'] = []; |
|
208
|
|
|
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
|
209
|
|
|
$entry = [ |
|
210
|
|
|
'label' => $resArray['title'], |
|
211
|
|
|
'type' => $resArray['type'], |
|
212
|
|
|
'volume' => $resArray['volume'], |
|
213
|
|
|
'pagination' => '', |
|
214
|
|
|
'targetUid' => $resArray['uid'] |
|
215
|
|
|
]; |
|
216
|
|
|
$menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, FALSE); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
return $menuArray; |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|