From 7a67a0257ea8d80148158931ba926fe38e3600c4 Mon Sep 17 00:00:00 2001 From: Frank Ulrich Weber Date: Fri, 17 Nov 2017 15:47:40 +0100 Subject: [PATCH 1/2] Adds the feature to enter a logical page in addition to the search term. With this feature you can configure the search plugin to show an additional field for the logical page. The page view plugin then opens the document on the page with the first occurance of the entered logical page within the page label. --- dlf/common/class.tx_dlf_document.php | 48 +++++++++++++++++++ .../listview/class.tx_dlf_listview.php | 18 +++++++ .../navigation/class.tx_dlf_navigation.php | 7 +++ .../pagegrid/class.tx_dlf_pagegrid.php | 7 +++ .../pageview/class.tx_dlf_pageview.php | 7 +++ dlf/plugins/search/class.tx_dlf_search.php | 48 ++++++++++++++++--- dlf/plugins/search/flexform.xml | 24 ++++++++++ dlf/plugins/search/locallang.xml | 4 ++ dlf/plugins/search/template.tmpl | 1 + dlf/plugins/toc/class.tx_dlf_toc.php | 7 +++ .../fulltext/class.tx_dlf_toolsFulltext.php | 7 +++ .../class.tx_dlf_toolsImagedownload.php | 7 +++ .../tools/pdf/class.tx_dlf_toolsPdf.php | 7 +++ 13 files changed, 186 insertions(+), 6 deletions(-) diff --git a/dlf/common/class.tx_dlf_document.php b/dlf/common/class.tx_dlf_document.php index 1df919ae0..e86c9507e 100644 --- a/dlf/common/class.tx_dlf_document.php +++ b/dlf/common/class.tx_dlf_document.php @@ -115,6 +115,14 @@ final class tx_dlf_document { */ protected $hasFulltext = FALSE; + /** + * Last searched logical and physical page + * + * @var array + * @access protected + */ + protected $lastSearchedPhysicalPage = array ('logicalPage' => NULL, 'physicalPage' => NULL); + /** * This holds the documents location * @@ -898,6 +906,46 @@ public function getMetadata($id, $cPid = 0) { } + /** + * This returns the first corresponding physical page number of a given logical page label + * + * @access public + * + * @param string $logicalPage: The label (or a part of the label) of the logical page + * + * @return integer The physical page number + */ + public function getPhysicalPage($logicalPage) { + + if(!empty( $this->lastSearchedPhysicalPage['logicalPage']) && $this->lastPhysicalPageSearch['logicalPage'] == $logicalPage) { + + return $this->lastSearchedPhysicalPage['physicalPage']; + + } else { + + $physicalPage = 0; + + foreach($this->physicalStructureInfo as $page) { + + if(strpos($page['orderlabel'], $logicalPage) !== false){ + + $this->lastSearchedPhysicalPage['logicalPage'] = $logicalPage; + $this->lastSearchedPhysicalPage['physicalPage'] = $physicalPage; + + return $physicalPage; + + } + + $physicalPage++; + + } + + } + + return 1; + + } + /** * This determines a title for the given document * diff --git a/dlf/plugins/listview/class.tx_dlf_listview.php b/dlf/plugins/listview/class.tx_dlf_listview.php index d1c9ae79d..7b1961a40 100644 --- a/dlf/plugins/listview/class.tx_dlf_listview.php +++ b/dlf/plugins/listview/class.tx_dlf_listview.php @@ -193,6 +193,12 @@ protected function getEntry($number, $template) { 'page' => $this->list[$number]['page'] ); + if(!empty($this->piVars['logicalPage'])) { + + $additionalParams['logicalPage'] = $this->piVars['logicalPage']; + + } + $conf = array ( 'useCacheHash' => 1, 'parameter' => $this->conf['targetPid'], @@ -293,6 +299,12 @@ protected function getSortingForm() { 'forceAbsoluteUrl' => 1 ); + if(!empty($this->piVars['logicalPage'])) { + + $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,array('logicalPage' => $this->piVars['logicalPage']), '', TRUE, FALSE); + + } + // Build HTML form. $sorting = '
'; @@ -406,6 +418,12 @@ protected function getSubEntries($number, $template) { 'highlight_word' => preg_replace('/\s\s+/', ';', $this->list->metadata['searchString']) ); + if(!empty($this->piVars['logicalPage'])) { + + $additionalParams['logicalPage'] = $this->piVars['logicalPage']; + + } + $conf = array ( // we don't want cHash in case of search parameters 'useCacheHash' => empty($this->list->metadata['searchString']) ? 1 : 0, diff --git a/dlf/plugins/navigation/class.tx_dlf_navigation.php b/dlf/plugins/navigation/class.tx_dlf_navigation.php index 8b77c2442..66fb87e61 100644 --- a/dlf/plugins/navigation/class.tx_dlf_navigation.php +++ b/dlf/plugins/navigation/class.tx_dlf_navigation.php @@ -129,6 +129,13 @@ public function main($content, $conf) { // Set default values if not set. if ($this->doc->numPages > 0) { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/pagegrid/class.tx_dlf_pagegrid.php b/dlf/plugins/pagegrid/class.tx_dlf_pagegrid.php index cf07bf0c3..6bccdd440 100644 --- a/dlf/plugins/pagegrid/class.tx_dlf_pagegrid.php +++ b/dlf/plugins/pagegrid/class.tx_dlf_pagegrid.php @@ -223,6 +223,13 @@ public function main($content, $conf) { } + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set some variable defaults. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/pageview/class.tx_dlf_pageview.php b/dlf/plugins/pageview/class.tx_dlf_pageview.php index db173a8d8..8e1976e22 100644 --- a/dlf/plugins/pageview/class.tx_dlf_pageview.php +++ b/dlf/plugins/pageview/class.tx_dlf_pageview.php @@ -222,6 +222,13 @@ public function main($content, $conf) { } else { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/search/class.tx_dlf_search.php b/dlf/plugins/search/class.tx_dlf_search.php index d81cdc504..504f948e4 100644 --- a/dlf/plugins/search/class.tx_dlf_search.php +++ b/dlf/plugins/search/class.tx_dlf_search.php @@ -321,6 +321,30 @@ protected function addFulltextSwitch($isFulltextSearch = 0) { } + /** + * Adds the logical page field to the search form + * + * @access protected + * + * @return string HTML output of logical page field + */ + protected function addLogicalPage() { + + $output = ''; + + // Check for plugin configuration. + if (!empty($this->conf['showLogicalPageField'])) { + + $output .= ' '; + + $output .= ' '; + + } + + return $output; + + } + /** * Creates an array for a HMENU entry of a facet value. * @@ -487,7 +511,8 @@ public function main($content, $conf) { '###FIELD_DOC###' => ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all' ? $this->addCurrentDocument() : ''), '###FIELD_COLL###' => ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all' ? $this->addCurrentCollection() : ''), '###ADDITIONAL_INPUTS###' => $this->addEncryptedCoreName(), - '###FACETS_MENU###' => $this->addFacetsMenu() + '###FACETS_MENU###' => $this->addFacetsMenu(), + '###LOGICAL_PAGE###' => $this->addLogicalPage() ); // Get additional fields for extended search. @@ -657,13 +682,24 @@ public function main($content, $conf) { // Keep some plugin variables. $linkConf['parameter'] = $this->conf['targetPid']; + $additionalParams = array(); + + if(!empty($this->piVars['logicalPage'])) { + + $additionalParams['logicalPage'] = $this->piVars['logicalPage']; + + } + if (!empty($this->piVars['order'])) { - $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, - array ( - 'order' => $this->piVars['order'], - 'asc' => (!empty($this->piVars['asc']) ? '1' : '0') - ), '', TRUE, FALSE); + $additionalParams['order'] = $this->piVars['order']; + $additionalParams['asc'] = !empty($this->piVars['asc']) ? '1' : '0'; + + } + + if(count($additionalParams)) { + + $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,$additionalParams, '', TRUE, FALSE); } diff --git a/dlf/plugins/search/flexform.xml b/dlf/plugins/search/flexform.xml index e155dc188..0a68bfbe6 100644 --- a/dlf/plugins/search/flexform.xml +++ b/dlf/plugins/search/flexform.xml @@ -220,6 +220,16 @@ + + + 1 + + + check + 0 + + + 1 @@ -240,6 +250,20 @@ + + + 1 + + + group + db + pages + 1 + 1 + 1 + + + 1 diff --git a/dlf/plugins/search/locallang.xml b/dlf/plugins/search/locallang.xml index c88bb6fbb..7c09f2fa2 100644 --- a/dlf/plugins/search/locallang.xml +++ b/dlf/plugins/search/locallang.xml @@ -36,10 +36,12 @@ + + @@ -71,10 +73,12 @@ + + diff --git a/dlf/plugins/search/template.tmpl b/dlf/plugins/search/template.tmpl index 19c03f51e..7ac449ceb 100644 --- a/dlf/plugins/search/template.tmpl +++ b/dlf/plugins/search/template.tmpl @@ -12,6 +12,7 @@ + ###LOGICAL_PAGE###
diff --git a/dlf/plugins/toc/class.tx_dlf_toc.php b/dlf/plugins/toc/class.tx_dlf_toc.php index 3b86755b1..ea95d7cc5 100644 --- a/dlf/plugins/toc/class.tx_dlf_toc.php +++ b/dlf/plugins/toc/class.tx_dlf_toc.php @@ -202,6 +202,13 @@ public function makeMenuArray($content, $conf) { } else { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values for page if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php b/dlf/plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php index 1d05b209a..3d028b927 100644 --- a/dlf/plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php +++ b/dlf/plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php @@ -49,6 +49,13 @@ public function main($content, $conf) { } else { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/toolbox/tools/imagedownload/class.tx_dlf_toolsImagedownload.php b/dlf/plugins/toolbox/tools/imagedownload/class.tx_dlf_toolsImagedownload.php index fd26a7d33..969f5c1a6 100644 --- a/dlf/plugins/toolbox/tools/imagedownload/class.tx_dlf_toolsImagedownload.php +++ b/dlf/plugins/toolbox/tools/imagedownload/class.tx_dlf_toolsImagedownload.php @@ -48,6 +48,13 @@ public function main($content, $conf) { } else { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { diff --git a/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php b/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php index 4f9b50b4f..e1d92e3fe 100644 --- a/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php +++ b/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php @@ -49,6 +49,13 @@ public function main($content, $conf) { } else { + if (!empty($this->piVars['logicalPage'])) { + + $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); + unset($this->piVars['logicalPage']); + + } + // Set default values if not set. // $this->piVars['page'] may be integer or string (physical structure @ID) if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) { From 42a25efb6d7b9e5828527a74c7e17de15603ee1d Mon Sep 17 00:00:00 2001 From: Frank Ulrich Weber Date: Wed, 20 Dec 2017 13:51:10 +0100 Subject: [PATCH 2/2] Fix broken additional params within method tx_dlf_search->main() --- dlf/plugins/search/class.tx_dlf_search.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dlf/plugins/search/class.tx_dlf_search.php b/dlf/plugins/search/class.tx_dlf_search.php index cb1a0929e..b39889d4c 100644 --- a/dlf/plugins/search/class.tx_dlf_search.php +++ b/dlf/plugins/search/class.tx_dlf_search.php @@ -693,10 +693,8 @@ public function main($content, $conf) { $linkConf['parameter'] = $this->conf['targetPidPageView']; $additionalParams['id'] = $results->current()['uid']; - $additionalParams['highlight_word'] = $results->current()['uid']; - $additionalParams['page'] = $results->current()['uid']; - - $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE); + $additionalParams['highlight_word'] = preg_replace('/\s\s+/', ';', $results->metadata['searchString']); + $additionalParams['page'] = count($results[0]['subparts']) == 1?$results[0]['subparts'][0]['page']:1; } else { @@ -708,12 +706,12 @@ public function main($content, $conf) { $additionalParams['order'] = $this->piVars['order']; $additionalParams['asc'] = !empty($this->piVars['asc']) ? '1' : '0'; - $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE); - } } + $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE); + // Send headers. header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL($linkConf)));