/**
  * 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'] = tx_dlf_helper::intInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
         } else {
             $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
         }
         $this->piVars['double'] = tx_dlf_helper::intInRange($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);
 }
 /**
  * Check if a connection to a Solr server could be established with the given credentials.
  *
  * @access	public
  *
  * @param	array		&$params: An array with parameters
  * @param	t3lib_tsStyleConfig		&$pObj: The parent object
  *
  * @return	string		Message informing the user of success or failure
  */
 public function checkSolrConnection(&$params, &$pObj)
 {
     // Prepend username and password to hostname.
     if (!empty($this->conf['solrUser']) && !empty($this->conf['solrPass'])) {
         $host = $this->conf['solrUser'] . ':' . $this->conf['solrPass'] . '@' . (!empty($this->conf['solrHost']) ? $this->conf['solrHost'] : 'localhost');
     } else {
         $host = !empty($this->conf['solrHost']) ? $this->conf['solrHost'] : 'localhost';
     }
     // Set port if not set.
     $port = !empty($this->conf['solrPort']) ? tx_dlf_helper::intInRange($this->conf['solrPort'], 0, 65535, 8180) : 8180;
     // Trim path and append trailing slash.
     $path = !empty($this->conf['solrPath']) ? trim($this->conf['solrPath'], '/') . '/' : '';
     // Build request URI.
     $url = 'http://' . $host . ':' . $port . '/' . $path . 'admin/cores';
     $context = stream_context_create(array('http' => array('method' => 'GET', 'user_agent' => !empty($this->conf['useragent']) ? $this->conf['useragent'] : ini_get('user_agent'))));
     // Try to connect to Solr server.
     $response = @simplexml_load_string(file_get_contents($url, FALSE, $context));
     // Check status code.
     if ($response) {
         $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]');
         if (is_array($status)) {
             $message = t3lib_div::makeInstance('t3lib_FlashMessage', sprintf($GLOBALS['LANG']->getLL('solr.status'), (string) $status[0]), $GLOBALS['LANG']->getLL('solr.connected'), $status[0] == 0 ? t3lib_FlashMessage::OK : t3lib_FlashMessage::WARNING, FALSE);
             $this->content .= $message->render();
             return $this->content;
         }
     }
     $message = t3lib_div::makeInstance('t3lib_FlashMessage', sprintf($GLOBALS['LANG']->getLL('solr.error'), $url), $GLOBALS['LANG']->getLL('solr.notConnected'), t3lib_FlashMessage::WARNING, FALSE);
     $this->content .= $message->render();
     return $this->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 = t3lib_div::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'] = tx_dlf_helper::intInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
         } else {
             $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
         }
         $this->piVars['double'] = tx_dlf_helper::intInRange($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']];
     // Get single page downloads.
     if (!empty($fullTextFile)) {
         $markerArray['###FULLTEXT_SELECT###'] = '<a class="select" title="' . $this->pi_getLL('fulltext-select', '', TRUE) . '" onclick="tx_dlf_viewer.toogleFulltextSelect();">' . $this->pi_getLL('fulltext-select', '', TRUE) . '</a>';
     } else {
         $markerArray['###FULLTEXT_SELECT###'] = $this->pi_getLL('fulltext-select', '', TRUE);
     }
     $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * This is a singleton class, thus the constructor should be private/protected
  *
  * @access	protected
  *
  * @param	string		$core: The name of the core to use
  *
  * @return	void
  */
 protected function __construct($core)
 {
     // Load class.
     if (!class_exists('Apache_Solr_Service')) {
         require_once t3lib_div::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Service.php');
     }
     // Get Solr credentials.
     $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
     $host = $conf['solrHost'] ? $conf['solrHost'] : 'localhost';
     // Prepend username and password to hostname.
     if ($conf['solrUser'] && $conf['solrPass']) {
         $host = $conf['solrUser'] . ':' . $conf['solrPass'] . '@' . $host;
     }
     // Set port if not set.
     $port = tx_dlf_helper::intInRange($conf['solrPort'], 1, 65535, 8180);
     // Append core name to path.
     $path = trim($conf['solrPath'], '/') . '/' . $core;
     // Instantiate Apache_Solr_Service class.
     $this->service = t3lib_div::makeInstance('Apache_Solr_Service', $host, $port, $path);
     // Check if connection is established.
     if ($this->service->ping() !== FALSE) {
         // Do not collapse single value arrays.
         $this->service->setCollapseSingleValueArrays = FALSE;
         // Set core name.
         $this->core = $core;
         // Instantiation successful!
         $this->ready = TRUE;
     }
 }
 /**
  * This adds an array of elements at the given position to the list
  *
  * @access	public
  *
  * @param	array		$elements: Array of elements to add to list
  * @param	integer		$position: Numeric position for including
  *
  * @return	void
  */
 public function add(array $elements, $position = -1)
 {
     // Save parameters for logging purposes.
     $_position = $position;
     $position = tx_dlf_helper::intInRange($position, 0, $this->count, $this->count);
     if (!empty($elements)) {
         array_splice($this->elements, $position, 0, $elements);
         $this->count = count($this->elements);
     }
 }
 /**
  * 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);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL || $this->doc->numPages < 1) {
         // 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'] = tx_dlf_helper::intInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
         } else {
             $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
         }
         $this->piVars['double'] = tx_dlf_helper::intInRange($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/pageview/template.tmpl'), '###TEMPLATE###');
     }
     // Get image data.
     $this->images[0] = $this->getImageUrl($this->piVars['page']);
     $this->fulltexts[0] = $this->getAltoUrl($this->piVars['page']);
     if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) {
         $this->images[1] = $this->getImageUrl($this->piVars['page'] + 1);
         $this->fulltexts[1] = $this->getAltoUrl($this->piVars['page'] + 1);
     }
     // Get the controls for the map.
     $this->controls = $this->getMapControls();
     // Fill in the template markers.
     $markerArray = array('###VIEWER_JS###' => $this->addViewerJS());
     $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);
     // Turn cache on.
     $this->setCache(TRUE);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL) {
         // Quit without doing anything if required variables are not set.
         return $content;
     } else {
         // Set default values if not set.
         if ($this->doc->numPages > 0) {
             // 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'] = tx_dlf_helper::intInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
             } else {
                 $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalPages);
             }
             $this->piVars['double'] = tx_dlf_helper::intInRange($this->piVars['double'], 0, 1, 0);
         } else {
             $this->piVars['page'] = 0;
             $this->piVars['double'] = 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/navigation/template.tmpl'), '###TEMPLATE###');
     }
     // Link to first page.
     if ($this->piVars['page'] > 1) {
         $markerArray['###FIRST###'] = $this->makeLink($this->pi_getLL('firstPage', '', TRUE), array('page' => 1));
     } else {
         $markerArray['###FIRST###'] = '<span>' . $this->pi_getLL('firstPage', '', TRUE) . '</span>';
     }
     // Link back X pages.
     if ($this->piVars['page'] > $this->conf['pageStep'] * ($this->piVars['double'] + 1)) {
         $markerArray['###BACK###'] = $this->makeLink(sprintf($this->pi_getLL('backXPages', '', TRUE), $this->conf['pageStep']), array('page' => $this->piVars['page'] - $this->conf['pageStep'] * ($this->piVars['double'] + 1)));
     } else {
         $markerArray['###BACK###'] = '<span>' . sprintf($this->pi_getLL('backXPages', '', TRUE), $this->conf['pageStep']) . '</span>';
     }
     // Link to previous page.
     if ($this->piVars['page'] > 1 + $this->piVars['double']) {
         $markerArray['###PREVIOUS###'] = $this->makeLink($this->pi_getLL('prevPage', '', TRUE), array('page' => $this->piVars['page'] - (1 + $this->piVars['double'])));
     } else {
         $markerArray['###PREVIOUS###'] = '<span>' . $this->pi_getLL('prevPage', '', TRUE) . '</span>';
     }
     // Link to next page.
     if ($this->piVars['page'] < $this->doc->numPages - $this->piVars['double']) {
         $markerArray['###NEXT###'] = $this->makeLink($this->pi_getLL('nextPage', '', TRUE), array('page' => $this->piVars['page'] + (1 + $this->piVars['double'])));
     } else {
         $markerArray['###NEXT###'] = '<span>' . $this->pi_getLL('nextPage', '', TRUE) . '</span>';
     }
     // Link forward X pages.
     if ($this->piVars['page'] <= $this->doc->numPages - $this->conf['pageStep'] * ($this->piVars['double'] + 1)) {
         $markerArray['###FORWARD###'] = $this->makeLink(sprintf($this->pi_getLL('forwardXPages', '', TRUE), $this->conf['pageStep']), array('page' => $this->piVars['page'] + $this->conf['pageStep'] * ($this->piVars['double'] + 1)));
     } else {
         $markerArray['###FORWARD###'] = '<span>' . sprintf($this->pi_getLL('forwardXPages', '', TRUE), $this->conf['pageStep']) . '</span>';
     }
     // Link to last page.
     if ($this->piVars['page'] < $this->doc->numPages) {
         $markerArray['###LAST###'] = $this->makeLink($this->pi_getLL('lastPage', '', TRUE), array('page' => $this->doc->numPages));
     } else {
         $markerArray['###LAST###'] = '<span>' . $this->pi_getLL('lastPage', '', TRUE) . '</span>';
     }
     // Add double page switcher.
     if ($this->doc->numPages > 0) {
         if (!$this->piVars['double']) {
             $markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOn', '', TRUE), array('double' => 1), 'class="tx-dlf-navigation-doubleOn"');
         } else {
             $markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOff', '', TRUE), array('double' => 0), 'class="tx-dlf-navigation-doubleOff"');
         }
         if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) {
             $markerArray['###DOUBLEPAGE+1###'] = $this->makeLink($this->pi_getLL('doublePage+1', '', TRUE), array('page' => $this->piVars['page'] + 1));
         } else {
             $markerArray['###DOUBLEPAGE+1###'] = '<span>' . $this->pi_getLL('doublePage+1', '', TRUE) . '</span>';
         }
     } else {
         $markerArray['###DOUBLEPAGE###'] = '<span>' . $this->pi_getLL('doublePageOn', '', TRUE) . '</span>';
         $markerArray['###DOUBLEPAGE+1###'] = '<span>' . $this->pi_getLL('doublePage+1', '', TRUE) . '</span>';
     }
     // Add page selector.
     $markerArray['###PAGESELECT###'] = $this->getPageSelector();
     // Add link to listview if applicable.
     $markerArray['###LINKLISTVIEW###'] = $this->getLinkToListview();
     // fill some language labels if available
     $markerArray['###ZOOM_IN###'] = $this->pi_getLL('zoom-in', '', TRUE);
     $markerArray['###ZOOM_OUT###'] = $this->pi_getLL('zoom-out', '', TRUE);
     $markerArray['###ZOOM_FULLSCREEN###'] = $this->pi_getLL('zoom-fullscreen', '', 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);
     $this->loadDocument();
     if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpThumbs'])) {
         // Quit without doing anything if required variables are not set.
         return $content;
     } else {
         // Set default values for page if not set.
         $this->piVars['pointer'] = tx_dlf_helper::intInRange($this->piVars['pointer'], 0, $this->doc->numPages, 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/pagegrid/template.tmpl'), '###TEMPLATE###');
     }
     $entryTemplate = $this->cObj->getSubpart($this->template, '###ENTRY###');
     if (empty($entryTemplate)) {
         if (TYPO3_DLOG) {
             t3lib_div::devLog('[tx_dlf_pagegrid->main(' . $content . ', [data])] No template subpart for list entry found', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf);
         }
         // Quit without doing anything if required variables are not set.
         return $content;
     }
     // Set some variable defaults.
     if (!empty($this->piVars['page'])) {
         $this->piVars['page'] = tx_dlf_helper::intInRange($this->piVars['page'], 1, $this->doc->numPages, 1);
         $this->piVars['pointer'] = intval(floor($this->piVars['page'] / $this->conf['limit']));
     }
     if (!empty($this->piVars['pointer']) && $this->piVars['pointer'] * $this->conf['limit'] + 1 <= $this->doc->numPages) {
         $this->piVars['pointer'] = max(intval($this->piVars['pointer']), 0);
     } else {
         $this->piVars['pointer'] = 0;
     }
     // Iterate through visible page set and display thumbnails.
     for ($i = $this->piVars['pointer'] * $this->conf['limit'], $j = ($this->piVars['pointer'] + 1) * $this->conf['limit']; $i < $j; $i++) {
         // +1 because page counting starts at 1.
         $number = $i + 1;
         if ($number > $this->doc->numPages) {
             break;
         } else {
             $content .= $this->getEntry($number, $entryTemplate);
         }
     }
     // Render page browser.
     $markerArray['###PAGEBROWSER###'] = $this->getPageBrowser();
     // Merge everything with template.
     $content = $this->cObj->substituteMarkerArray($this->cObj->substituteSubpart($this->template, '###ENTRY###', $content, TRUE), $markerArray);
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * This builds a menu array for HMENU
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	array		HMENU array
  */
 public function makeMenuArray($content, $conf)
 {
     $this->init($conf);
     // Load current document.
     $this->loadDocument();
     if ($this->doc === NULL) {
         // Quit without doing anything if required variables are not set.
         return array();
     } else {
         // Set default values for page if not set.
         $this->piVars['page'] = tx_dlf_helper::intInRange($this->piVars['page'], 1, $this->doc->numPages, 1);
         $this->piVars['double'] = tx_dlf_helper::intInRange($this->piVars['double'], 0, 1, 0);
     }
     $menuArray = array();
     // Does the document have physical pages or is it an external file?
     if ($this->doc->physicalPages || !tx_dlf_helper::testInt($this->doc->uid)) {
         // Get all logical units the current page is a part of.
         if (!empty($this->piVars['page']) && $this->doc->physicalPages) {
             $this->activeEntries = array_merge((array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[0]], (array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page']]]);
             if (!empty($this->piVars['double']) && $this->piVars['page'] < $this->doc->numPages) {
                 $this->activeEntries = array_merge($this->activeEntries, (array) $this->doc->smLinks['p2l'][$this->doc->physicalPages[$this->piVars['page'] + 1]]);
             }
         }
         // Go through table of contents and create all menu entries.
         foreach ($this->doc->tableOfContents as $entry) {
             $menuArray[] = $this->getMenuEntry($entry, TRUE);
         }
     } else {
         // Go through table of contents and create top-level menu entries.
         foreach ($this->doc->tableOfContents as $entry) {
             $menuArray[] = $this->getMenuEntry($entry, FALSE);
         }
         // Get all child documents from database.
         $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 . tx_dlf_helper::whereClause('tx_dlf_documents') . tx_dlf_helper::whereClause('tx_dlf_structures');
         if ($this->conf['excludeOther']) {
             $whereClause .= ' AND tx_dlf_documents.pid=' . intval($this->conf['pages']);
         }
         // Build table of contents from database.
         $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('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', 'tx_dlf_documents,tx_dlf_structures', $whereClause, '', 'tx_dlf_documents.volume_sorting', '');
         if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
             $menuArray[0]['ITEM_STATE'] = 'CURIFSUB';
             $menuArray[0]['_SUB_MENU'] = array();
             while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                 $entry = array('label' => $resArray['title'], 'type' => $resArray['type'], 'volume' => $resArray['volume'], 'pagination' => '', 'targetUid' => $resArray['uid']);
                 $menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, FALSE);
             }
         }
     }
     return $menuArray;
 }