/**
  * The main method of the PlugIn
  *
  * @access	public
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  *
  * @return	void
  */
 public function main($content = '', $conf = array())
 {
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('encrypted') != '' && \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('hashed') != '') {
         $core = tx_dlf_helper::decrypt(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('encrypted'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('hashed'));
     }
     if (!empty($core)) {
         $url = trim(tx_dlf_solr::getSolrUrl($core), '/') . '/suggest/?q=' . tx_dlf_solr::escapeQuery(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('q'));
         if ($stream = fopen($url, 'r')) {
             $content .= stream_get_contents($stream);
             fclose($stream);
         }
     }
     echo $content;
 }
 /**
  * Connects to Solr server.
  *
  * @access	protected
  *
  * @param	integer		$core: UID of the Solr core
  * @param	integer		$pid: UID of the configuration page
  *
  * @return	boolean		TRUE on success or FALSE on failure
  */
 protected static function solrConnect($core, $pid = 0)
 {
     // Get Solr instance.
     if (!self::$solr) {
         // Connect to Solr server.
         if (self::$solr = tx_dlf_solr::getInstance($core)) {
             // Load indexing configuration if needed.
             if ($pid) {
                 self::loadIndexConf($pid);
             }
         } else {
             return FALSE;
         }
     }
     return TRUE;
 }
 /**
  * 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 makeFacetsMenuArray($content, $conf)
 {
     $this->init($conf);
     $menuArray = array();
     // Set default value for facet search.
     $search = array('query' => '*', 'params' => array());
     // Extract query and filter from last search.
     $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list');
     if (!empty($list->metadata['options']['source'])) {
         if ($list->metadata['options']['source'] == 'search') {
             $search['query'] = $list->metadata['options']['select'];
         }
         $search['params'] = $list->metadata['options']['params'];
     }
     // Get applicable facets.
     $solr = tx_dlf_solr::getInstance($this->conf['solrcore']);
     if (!$solr->ready) {
         if (TYPO3_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->makeFacetsMenuArray(' . $content . ', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf);
         }
         return array();
     }
     // Set needed parameters for facet search.
     if (empty($search['params']['fq'])) {
         $search['params']['fq'] = array();
     }
     $search['params']['facet'] = 'true';
     $search['params']['facet.field'] = array_keys($this->conf['facets']);
     //override SOLR default value for facet.limit of 100
     $search['params']['facet.limit'] = $this->conf['limitFacets'];
     // Perform search.
     $results = $solr->service->search($search['query'], 0, $this->conf['limit'], $search['params']);
     // Process results.
     foreach ($results->facet_counts->facet_fields as $field => $values) {
         $entryArray = array();
         $entryArray['title'] = htmlspecialchars($this->conf['facets'][$field]);
         $entryArray['count'] = 0;
         $entryArray['_OVERRIDE_HREF'] = '';
         $entryArray['doNotLinkIt'] = 1;
         $entryArray['ITEM_STATE'] = 'NO';
         // Count number of facet values.
         $i = 0;
         foreach ($values as $value => $count) {
             if ($count > 0) {
                 $hasValue = TRUE;
                 $entryArray['count']++;
                 if ($entryArray['ITEM_STATE'] == 'NO') {
                     $entryArray['ITEM_STATE'] = 'IFSUB';
                 }
                 $entryArray['_SUB_MENU'][] = $this->getFacetsMenuEntry($field, $value, $count, $search, $entryArray['ITEM_STATE']);
                 if (++$i == $this->conf['limit']) {
                     break;
                 }
             } else {
                 break;
             }
         }
         $menuArray[] = $entryArray;
     }
     return $menuArray;
 }
 /**
  * Post-processing hook for the process_cmdmap() method.
  *
  * @access	public
  *
  * @param	string		$command: 'move', 'copy', 'localize', 'inlineLocalizeSynchronize', 'delete' or 'undelete'
  * @param	string		$table: The destination table
  * @param	integer		$id: The uid of the record
  * @param	mixed		$value: The value for the command
  * @param	\TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object
  *
  * @return	void
  */
 public function processCmdmap_postProcess($command, $table, $id, $value, $pObj)
 {
     if (in_array($command, array('move', 'delete', 'undelete')) && $table == 'tx_dlf_documents') {
         // Get Solr core.
         $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_solrcores.uid', 'tx_dlf_solrcores,tx_dlf_documents', 'tx_dlf_solrcores.uid=tx_dlf_documents.solrcore AND tx_dlf_documents.uid=' . intval($id) . tx_dlf_helper::whereClause('tx_dlf_solrcores'), '', '', '1');
         if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
             list($core) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
             switch ($command) {
                 case 'move':
                 case 'delete':
                     // Establish Solr connection.
                     if ($solr = tx_dlf_solr::getInstance($core)) {
                         // Delete Solr document.
                         $solr->service->deleteByQuery('uid:' . $id);
                         $solr->service->commit();
                         if ($command == 'delete') {
                             break;
                         }
                     }
                 case 'undelete':
                     // Reindex document.
                     $doc =& tx_dlf_document::getInstance($id);
                     if ($doc->ready) {
                         $doc->save($doc->pid, $core);
                     } else {
                         if (TYPO3_DLOG) {
                             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processCmdmap_postProcess(' . $command . ', ' . $table . ', ' . $id . ', ' . $value . ', [' . get_class($pObj) . '])] Failed to re-index document with UID "' . $id . '"', $this->extKey, SYSLOG_SEVERITY_ERROR);
                         }
                     }
                     break;
             }
         }
     }
 }
 /**
  * Connects to Solr server.
  *
  * @access	protected
  *
  * @return	boolean		TRUE on success or FALSE on failure
  */
 protected function solrConnect()
 {
     // Get Solr instance.
     if (!$this->solr) {
         // Connect to Solr server.
         if ($this->solr = tx_dlf_solr::getInstance($this->metadata['options']['core'])) {
             // Load index configuration.
             $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.indexed AS indexed', 'tx_dlf_metadata', 'tx_dlf_metadata.is_listed=1 AND tx_dlf_metadata.pid=' . intval($this->metadata['options']['pid']) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', 'tx_dlf_metadata.sorting ASC', '');
             while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                 $this->solrConfig[$resArray['index_name']] = $resArray['index_name'] . '_' . ($resArray['tokenized'] ? 't' : 'u') . 's' . ($resArray['indexed'] ? 'i' : 'u');
             }
             // Add static fields.
             $this->solrConfig['type'] = 'type';
         } else {
             return FALSE;
         }
     }
     return TRUE;
 }