Skip to content

Commit

Permalink
Merge pull request #232 from frank-ulrich-weber/jump2logicalPage
Browse files Browse the repository at this point in the history
Jump2logicalPage
  • Loading branch information
sebastian-meyer authored Dec 20, 2017
2 parents b811c39 + 42a25ef commit b34a1c7
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 12 deletions.
48 changes: 48 additions & 0 deletions dlf/common/class.tx_dlf_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
18 changes: 18 additions & 0 deletions dlf/plugins/listview/class.tx_dlf_listview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -312,6 +318,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 = '<form action="'.$this->cObj->typoLink_URL($linkConf).'" method="get"><div><input type="hidden" name="id" value="'.$GLOBALS['TSFE']->id.'" />';

Expand Down Expand Up @@ -425,6 +437,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,
Expand Down
8 changes: 8 additions & 0 deletions dlf/plugins/navigation/class.tx_dlf_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ 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']);
// The logical page parameter should not appear
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'])) {
Expand Down
8 changes: 8 additions & 0 deletions dlf/plugins/pagegrid/class.tx_dlf_pagegrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ public function main($content, $conf) {

}

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear
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'])) {
Expand Down
8 changes: 8 additions & 0 deletions dlf/plugins/pageview/class.tx_dlf_pageview.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ public function main($content, $conf) {

} else {

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
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'])) {
Expand Down
53 changes: 41 additions & 12 deletions dlf/plugins/search/class.tx_dlf_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,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 .= ' <label for="tx-dlf-search-logical-page">' . $this->pi_getLL('label.logicalPage', '') . ': </label>';

$output .= ' <input class="tx-dlf-search-logical-page" id="tx-dlf-search-logical-page" type="text" name="' . $this->prefixId . '[logicalPage]" />';

}

return $output;

}

/**
* Creates an array for a HMENU entry of a facet value.
*
Expand Down Expand Up @@ -482,7 +506,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.
Expand Down Expand Up @@ -654,17 +679,22 @@ public function main($content, $conf) {
// Clean output buffer.
\TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers();

$additionalParams = array();

if(!empty($this->piVars['logicalPage'])) {

$additionalParams['logicalPage'] = $this->piVars['logicalPage'];

}

// Jump directly to the page view, if there is only one result and it is configured
if($results->count() == 1 && !empty($this->conf['showSingleResult'])) {

$linkConf['parameter'] = $this->conf['targetPidPageView'];

$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,
array (
'id' => $results->current()['uid'],
'highlight_word' => preg_replace('/\s\s+/', ';', $results->metadata['searchString']),
'page' => count($results[0]['subparts']) == 1?$results[0]['subparts'][0]['page']:1
), '', TRUE, FALSE);
$additionalParams['id'] = $results->current()['uid'];
$additionalParams['highlight_word'] = preg_replace('/\s\s+/', ';', $results->metadata['searchString']);
$additionalParams['page'] = count($results[0]['subparts']) == 1?$results[0]['subparts'][0]['page']:1;

} else {

Expand All @@ -673,16 +703,15 @@ public function main($content, $conf) {

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';

}

}

$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)));

Expand Down
10 changes: 10 additions & 0 deletions dlf/plugins/search/flexform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@
</config>
</TCEforms>
</suggest>
<showLogicalPageField>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.showLogicalPageField</label>
<config>
<type>check</type>
<default>0</default>
</config>
</TCEforms>
</showLogicalPageField>
<showSingleResult>
<TCEforms>
<onChange>reload</onChange>
Expand Down
4 changes: 4 additions & 0 deletions dlf/plugins/search/locallang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
<label index="tt_content.pi_flexform.targetPidPageView">Target page (with "DLF: Page View" plugin)</label>
<label index="tt_content.pi_flexform.separator">Separator for metadata in TS array</label>
<label index="tt_content.pi_flexform.templateFile">Template file</label>
<label index="tt_content.pi_flexform.showLogicalPageField">Show field for logical page?</label>
<label index="tt_content.pi_flexform.showSingleResult">Show single result in Page View?</label>
<label index="label.query">Search for:</label>
<label index="label.submit">Search</label>
<label index="label.inFulltext">in fulltext</label>
<label index="label.inMetadata">in metadata</label>
<label index="label.logicalPage">Page</label>
<label index="search">Search</label>
<label index="for"> for "%s"</label>
<label index="in"> in "%s"</label>
Expand Down Expand Up @@ -74,11 +76,13 @@
<label index="tt_content.pi_flexform.targetPidPageView">Zielseite (mit Plugin "DLF: Seitenansicht")</label>
<label index="tt_content.pi_flexform.separator">Trennzeichen für Metadaten im TS-Array</label>
<label index="tt_content.pi_flexform.templateFile">HTML-Template</label>
<label index="tt_content.pi_flexform.showLogicalPageField">Feld für logische Seite anzeigen?</label>
<label index="tt_content.pi_flexform.showSingleResult">Einzelnes Ergebnis in Seitenansicht anzeigen?</label>
<label index="label.query">Suchen nach:</label>
<label index="label.submit">Suchen</label>
<label index="label.inFulltext">im Volltext</label>
<label index="label.inMetadata">in Metadaten</label>
<label index="label.logicalPage">Seite</label>
<label index="search">Suche</label>
<label index="for"> nach "%s"</label>
<label index="in"> in "%s"</label>
Expand Down
1 change: 1 addition & 0 deletions dlf/plugins/search/template.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<label for="tx-dlf-search-query">###LABEL_QUERY###</label>
<!-- Never change the @id of this input field! Otherwise search suggestions won't work! -->
<input type="text" id="tx-dlf-search-query" name="###FIELD_QUERY###" value="###QUERY###" />
###LOGICAL_PAGE###
<!-- The following element is needed for auto-completion! -->
<div id="tx-dlf-search-suggest"></div>
<input type="submit" value="###LABEL_SUBMIT###" />
Expand Down
8 changes: 8 additions & 0 deletions dlf/plugins/toc/class.tx_dlf_toc.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ public function makeMenuArray($content, $conf) {

} else {

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
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'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public function main($content, $conf) {

} else {

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
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'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function main($content, $conf) {

} else {

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
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'])) {
Expand Down
8 changes: 8 additions & 0 deletions dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public function main($content, $conf) {

} else {

if (!empty($this->piVars['logicalPage'])) {

$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
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'])) {
Expand Down

0 comments on commit b34a1c7

Please sign in to comment.