/**
  * The main method of the PlugIn
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	string		The content that is displayed on the website
  */
 public function main($content, $conf)
 {
     $this->init($conf);
     // Merge configuration with conf array of toolbox.
     $this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpDownload'])) {
         // Quit without doing anything if required variables are not set.
         return $content;
     } else {
         // Set default values if not set.
         // page may be integer or string (physical page attribute)
         if ((int) $this->piVars['page'] > 0 || empty($this->piVars['page'])) {
             $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
         } else {
             $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
         }
         $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
     }
     // Load template file.
     if (!empty($this->conf['templateFile'])) {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
     } else {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/pdf/template.tmpl'), '###TEMPLATE###');
     }
     // Get single page downloads.
     $markerArray['###PAGE###'] = $this->getPageLink();
     // Get work download.
     $markerArray['###WORK###'] = $this->getWorkLink();
     $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * The main method of the PlugIn
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	string		The content that is displayed on the website
  */
 public function main($content, $conf)
 {
     $this->init($conf);
     // Merge configuration with conf array of toolbox.
     $this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpFulltext'])) {
         // Quit without doing anything if required variables are not set.
         return $content;
     } else {
         // Set default values if not set.
         // page may be integer or string (physical page attribute)
         if ((int) $this->piVars['page'] > 0 || empty($this->piVars['page'])) {
             $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
         } else {
             $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
         }
         $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
     }
     // Load template file.
     if (!empty($this->conf['templateFile'])) {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
     } else {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/fulltext/template.tmpl'), '###TEMPLATE###');
     }
     $fullTextFile = $this->doc->physicalPagesInfo[$this->doc->physicalPages[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
     if (!empty($fullTextFile)) {
         $markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="fulltext-on:' . $this->pi_getLL('fulltext-on', '', TRUE) . ';fulltext-off:' . $this->pi_getLL('fulltext-off', '', TRUE) . '"></a>';
     } else {
         $markerArray['###FULLTEXT_SELECT###'] = $this->pi_getLL('fulltext-not-available', '', TRUE);
     }
     $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * The main method of the PlugIn
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	string		The content that is displayed on the website
  */
 public function main($content, $conf)
 {
     $this->init($conf);
     // Merge configuration with conf array of toolbox.
     $this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
     // Load current document.
     $this->loadDocument();
     // Load template file.
     if (!empty($this->conf['templateFile'])) {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
     } else {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/imagemanipulation/template.tmpl'), '###TEMPLATE###');
     }
     $markerArray['###IMAGEMANIPULATION_SELECT###'] = '<span class="tx-dlf-tools-imagetools" id="tx-dlf-tools-imagetools" data-dic="imagemanipulation-on:' . $this->pi_getLL('imagemanipulation-on', '', TRUE) . ';imagemanipulation-off:' . $this->pi_getLL('imagemanipulation-off', '', TRUE) . ';reset:' . $this->pi_getLL('reset', '', TRUE) . ';saturation:' . $this->pi_getLL('saturation', '', TRUE) . ';hue:' . $this->pi_getLL('hue', '', TRUE) . ';contrast:' . $this->pi_getLL('contrast', '', TRUE) . ';brightness:' . $this->pi_getLL('brightness', '', TRUE) . '" title="' . $this->pi_getLL('no-support', '', TRUE) . '"></span>';
     $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * Sets default plugin variables from typoscript
  * (stdWrap backport from TYPO3 6.2)
  * @see http://forge.typo3.org/issues/22045
  *
  * @access	public
  *
  * @return	void
  */
 public function pi_setPiVarDefaults()
 {
     if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
         foreach ($this->conf['_DEFAULT_PI_VARS.'] as $GPkey => $GPval) {
             if (strpos($GPkey, '.')) {
                 $GPkey = substr($GPkey, 0, -1);
             }
             if (is_array($this->conf['_DEFAULT_PI_VARS.'][$GPkey . '.']['stdWrap.'])) {
                 $GPval = $GPval ? $GPval : '';
                 $this->conf['_DEFAULT_PI_VARS.'][$GPkey] = $this->cObj->stdWrap($GPval, $this->conf['_DEFAULT_PI_VARS.'][$GPkey . '.']['stdWrap.']);
                 unset($this->conf['_DEFAULT_PI_VARS.'][$GPkey . '.']['stdWrap.']);
             }
         }
         $this->piVars = tx_dlf_helper::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'], is_array($this->piVars) ? $this->piVars : array());
     }
 }
 /**
  * Builds a collection list
  *
  * @access	protected
  *
  * @return	string		The list of collections ready to output
  */
 protected function showCollectionList()
 {
     $additionalWhere = '';
     $orderBy = 'tx_dlf_collections.label';
     // Handle collections set by configuration.
     if ($this->conf['collections']) {
         if (count(explode(',', $this->conf['collections'])) == 1 && empty($this->conf['dont_show_single'])) {
             $this->showSingleCollection(intval(trim($this->conf['collections'], ' ,')));
         }
         $additionalWhere .= ' AND tx_dlf_collections.uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ')';
         $orderBy = 'FIELD(tx_dlf_collections.uid, ' . $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']) . ')';
     }
     // Should user-defined collections be shown?
     if (empty($this->conf['show_userdefined'])) {
         $additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id=0';
     } elseif ($this->conf['show_userdefined'] > 0) {
         if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
             $additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id=' . intval($GLOBALS['TSFE']->fe_user->user['uid']);
         } else {
             $additionalWhere .= ' AND NOT tx_dlf_collections.fe_cruser_id=0';
         }
     }
     // Get collections.
     $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_collections.uid AS uid,tx_dlf_collections.label AS label,tx_dlf_collections.thumbnail AS thumbnail,tx_dlf_collections.description AS description,tx_dlf_collections.priority AS priority,COUNT(tx_dlf_documents.uid) AS titles', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . ' AND tx_dlf_documents.partof=0 AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . $additionalWhere . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_collections.uid', $orderBy, '');
     $count = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
     $content = '';
     if ($count == 1 && empty($this->conf['dont_show_single'])) {
         $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
         $this->showSingleCollection(intval($resArray['uid']));
     } elseif ($count > 0) {
         // Get number of volumes per collection.
         $resultVolumes = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dlf_collections.uid AS uid,COUNT(tx_dlf_documents.uid) AS volumes', 'tx_dlf_documents', 'tx_dlf_relations', 'tx_dlf_collections', 'AND tx_dlf_collections.pid=' . intval($this->conf['pages']) . ' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0' . tx_dlf_helper::whereClause('tx_dlf_documents') . ') AND tx_dlf_relations.ident=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations') . $additionalWhere . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_collections'), 'tx_dlf_collections.uid', '', '');
         $volumes = array();
         while ($resArrayVolumes = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resultVolumes)) {
             $volumes[$resArrayVolumes['uid']] = $resArrayVolumes['volumes'];
         }
         // Process results.
         while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
             // Generate random but unique array key taking priority into account.
             do {
                 $_key = $resArray['priority'] * 1000 + mt_rand(0, 1000);
             } while (!empty($markerArray[$_key]));
             // Merge plugin variables with new set of values.
             $additionalParams = array('collection' => $resArray['uid']);
             if (is_array($this->piVars)) {
                 $piVars = $this->piVars;
                 unset($piVars['DATA']);
                 $additionalParams = tx_dlf_helper::array_merge_recursive_overrule($piVars, $additionalParams);
             }
             // Build typolink configuration array.
             $conf = array('useCacheHash' => 1, 'parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => t3lib_div::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE));
             // Link collection's title to list view.
             $markerArray[$_key]['###TITLE###'] = $this->cObj->typoLink(htmlspecialchars($resArray['label']), $conf);
             // Add feed link if applicable.
             if (!empty($this->conf['targetFeed'])) {
                 $img = '<img src="' . t3lib_extMgm::siteRelPath($this->extKey) . 'res/icons/txdlffeeds.png" alt="' . $this->pi_getLL('feedAlt', '', TRUE) . '" title="' . $this->pi_getLL('feedTitle', '', TRUE) . '" />';
                 $markerArray[$_key]['###FEED###'] = $this->pi_linkTP($img, array($this->prefixId => array('collection' => $resArray['uid'])), FALSE, $this->conf['targetFeed']);
             } else {
                 $markerArray[$_key]['###FEED###'] = '';
             }
             // Add thumbnail.
             if (!empty($resArray['thumbnail'])) {
                 $markerArray[$_key]['###THUMBNAIL###'] = '<img alt="" title="' . htmlspecialchars($resArray['label']) . '" src="' . $resArray['thumbnail'] . '" />';
             } else {
                 $markerArray[$_key]['###THUMBNAIL###'] = '';
             }
             // Add description.
             $markerArray[$_key]['###DESCRIPTION###'] = $this->pi_RTEcssText($resArray['description']);
             // Build statistic's output.
             $labelTitles = $this->pi_getLL($resArray['titles'] > 1 ? 'titles' : 'title', '', FALSE);
             $markerArray[$_key]['###COUNT_TITLES###'] = htmlspecialchars($resArray['titles'] . $labelTitles);
             $labelVolumes = $this->pi_getLL($volumes[$resArray['uid']] > 1 ? 'volumes' : 'volume', '', FALSE);
             $markerArray[$_key]['###COUNT_VOLUMES###'] = htmlspecialchars($volumes[$resArray['uid']] . $labelVolumes);
         }
         // Randomize sorting?
         if (!empty($this->conf['randomize'])) {
             ksort($markerArray, SORT_NUMERIC);
             // Don't cache the output.
             $this->setCache(FALSE);
         }
         $entry = $this->cObj->getSubpart($this->template, '###ENTRY###');
         foreach ($markerArray as $marker) {
             $content .= $this->cObj->substituteMarkerArray($entry, $marker);
         }
         // Hook for getting custom collection hierarchies/subentries (requested by SBB).
         foreach ($this->hookObjects as $hookObj) {
             if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) {
                 $hookObj->showCollectionList_getCustomCollectionList($this, $this->conf['templateFile'], $content, $markerArray);
             }
         }
         return $this->cObj->substituteSubpart($this->template, '###ENTRY###', $content, TRUE);
     }
     return $content;
 }
 /**
  * Adds the facets menu to the search form
  *
  * @access	protected
  *
  * @return	string		HTML output of facets menu
  */
 protected function addFacetsMenu()
 {
     // Check for typoscript configuration to prevent fatal error.
     if (empty($this->conf['facetsConf.'])) {
         if (TYPO3_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->addFacetsMenu()] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING);
         }
         return '';
     }
     // Quit without doing anything if no facets are selected.
     if (empty($this->conf['facets'])) {
         return '';
     }
     // Get facets from plugin configuration.
     $facets = array();
     foreach (\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['facets'], TRUE) as $facet) {
         $facets[$facet . '_faceting'] = tx_dlf_helper::translate($facet, 'tx_dlf_metadata', $this->conf['pages']);
     }
     // Render facets menu.
     $TSconfig = array();
     $TSconfig['special'] = 'userfunction';
     $TSconfig['special.']['userFunc'] = 'tx_dlf_search->makeFacetsMenuArray';
     $TSconfig['special.']['facets'] = $facets;
     $TSconfig['special.']['limit'] = max(intval($this->conf['limitFacets']), 1);
     $TSconfig = tx_dlf_helper::array_merge_recursive_overrule($this->conf['facetsConf.'], $TSconfig);
     return $this->cObj->HMENU($TSconfig);
 }
 /**
  * Generates a navigation link
  *
  * @access	protected
  *
  * @param	string		$label: The link's text
  * @param	array		$overrulePIvars: The new set of plugin variables
  * @param	string		$aTagParams: Additional HTML attributes for link tag
  *
  * @return	string		Typolink ready to output
  */
 protected function makeLink($label, array $overrulePIvars = array(), $aTagParams = '')
 {
     // Merge plugin variables with new set of values.
     if (is_array($this->piVars)) {
         $piVars = $this->piVars;
         unset($piVars['DATA']);
         $overrulePIvars = tx_dlf_helper::array_merge_recursive_overrule($piVars, $overrulePIvars);
     }
     // Build typolink configuration array.
     $conf = array('useCacheHash' => 1, 'parameter' => $GLOBALS['TSFE']->id, 'ATagParams' => $aTagParams, 'additionalParams' => t3lib_div::implodeArrayForUrl($this->prefixId, $overrulePIvars, '', TRUE, FALSE), 'title' => $label);
     return $this->cObj->typoLink($label, $conf);
 }
 /**
  * The main method of the PlugIn
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	string		The content that is displayed on the website
  */
 public function main($content, $conf)
 {
     $this->init($conf);
     // Check for typoscript configuration to prevent fatal error.
     if (empty($this->conf['menuConf.'])) {
         if (TYPO3_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_toc->main(' . $content . ', [data])] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf);
         }
         return $content;
     }
     // Load template file.
     if (!empty($this->conf['templateFile'])) {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
     } else {
         $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toc/template.tmpl'), '###TEMPLATE###');
     }
     $TSconfig = array();
     $TSconfig['special'] = 'userfunction';
     $TSconfig['special.']['userFunc'] = 'tx_dlf_toc->makeMenuArray';
     $TSconfig = tx_dlf_helper::array_merge_recursive_overrule($this->conf['menuConf.'], $TSconfig);
     $markerArray['###TOCMENU###'] = $this->cObj->HMENU($TSconfig);
     $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }