function listAvailableOrderingsForAdmin(&$config)
 {
     $this->init();
     $this->lang->init($GLOBALS['BE_USER']->uc['lang']);
     // get orderings
     $fieldLabel = $this->lang->sL('LLL:EXT:ke_search/locallang_db.php:tx_kesearch_index.relevance');
     $notAllowedFields = 'uid,pid,tstamp,crdate,cruser_id,starttime,endtime,fe_group,targetpid,content,params,type,tags,abstract,language,orig_uid,orig_pid,hash';
     if (!$config['config']['relevanceNotAllowed']) {
         $config['items'][] = array($fieldLabel . ' UP', 'score asc');
         $config['items'][] = array($fieldLabel . ' DOWN', 'score desc');
     }
     $res = $GLOBALS['TYPO3_DB']->sql_query('SHOW COLUMNS FROM tx_kesearch_index');
     while ($col = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         if (TYPO3_VERSION_INTEGER >= 7000000) {
             $isInList = TYPO3\CMS\Core\Utility\GeneralUtility::inList($notAllowedFields, $col['Field']);
         } else {
             $isInList = t3lib_div::inList($notAllowedFields, $col['Field']);
         }
         if (!$isInList) {
             $file = $GLOBALS['TCA']['tx_kesearch_index']['columns'][$col['Field']]['label'];
             $fieldLabel = $this->lang->sL($file);
             $config['items'][] = array($fieldLabel . ' UP', $col['Field'] . ' asc');
             $config['items'][] = array($fieldLabel . ' DOWN', $col['Field'] . ' desc');
         }
     }
 }
 public function listAvailableOrderingsForAdmin(&$config)
 {
     $this->init();
     $this->lang->init($GLOBALS['BE_USER']->uc['lang']);
     // get orderings
     $fieldLabel = $this->lang->sL('LLL:EXT:ke_search/locallang_db.php:tx_kesearch_index.relevance');
     if (!$config['config']['relevanceNotAllowed']) {
         $config['items'][] = array($fieldLabel . ' UP', 'score asc');
         $config['items'][] = array($fieldLabel . ' DOWN', 'score desc');
     }
     $res = $GLOBALS['TYPO3_DB']->sql_query('SHOW COLUMNS FROM tx_kesearch_index');
     while ($col = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $isInList = TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->notAllowedFields, $col['Field']);
         if (!$isInList) {
             $file = $GLOBALS['TCA']['tx_kesearch_index']['columns'][$col['Field']]['label'];
             $fieldLabel = $this->lang->sL($file);
             $config['items'][] = array($fieldLabel . ' UP', $col['Field'] . ' asc');
             $config['items'][] = array($fieldLabel . ' DOWN', $col['Field'] . ' desc');
         }
     }
 }
 /**
  * This function was called from indexer object and saves content to index table
  *
  * @return string content which will be displayed in backend
  */
 public function startIndexing()
 {
     $content = '';
     $this->conf['useHRDatesSingle'] = $this->indexerConfig['index_news_useHRDatesSingle'];
     $this->conf['useHRDatesSingleWithoutDay'] = $this->indexerConfig['index_news_useHRDatesSingleWithoutDay'];
     // get all the tt_news entries to index
     // don't index hidden or deleted news, BUT
     // get the news with frontend user group access restrictions
     // or time (start / stop) restrictions.
     // Copy those restrictions to the index.
     $fields = '*';
     $table = 'tt_news';
     $indexPids = $this->getPidList($this->indexerConfig['startingpoints_recursive'], $this->indexerConfig['sysfolder'], $table);
     if ($this->indexerConfig['index_use_page_tags']) {
         // add the tags of each page to the global page array
         $this->pageRecords = $this->getPageRecords($indexPids);
         $this->addTagsToRecords($indexPids);
     }
     $where = 'pid IN (' . implode(',', $indexPids) . ') ';
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table);
         $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
     } else {
         $where .= t3lib_befunc::BEenableFields($table);
         $where .= t3lib_befunc::deleteClause($table);
     }
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where);
     $counter = 0;
     if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
         while ($newsRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             // if mode equals 'choose categories for indexing' (2). 1 = All
             if ($this->indexerConfig['index_news_category_mode'] == '2') {
                 if (TYPO3_VERSION_INTEGER >= 7000000) {
                     $enableFields = TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_news_cat') . TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_news_cat');
                 } else {
                     $enableFields = t3lib_befunc::BEenableFields('tt_news_cat') . t3lib_befunc::deleteClause('tt_news_cat');
                 }
                 $resCat = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tt_news_cat.uid', 'tt_news', 'tt_news_cat_mm', 'tt_news_cat', ' AND tt_news.uid = ' . $newsRecord['uid'] . $enableFields, '', '', '');
                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($resCat)) {
                     $isInList = false;
                     while ($newsCat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resCat)) {
                         // if category was found in list, set isInList to true and break further processing.
                         if (TYPO3_VERSION_INTEGER >= 7000000) {
                             if (TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->indexerConfig['index_news_category_selection'], $newsCat['uid'])) {
                                 $isInList = true;
                                 break;
                             }
                         } else {
                             if (t3lib_div::inList($this->indexerConfig['index_news_category_selection'], $newsCat['uid'])) {
                                 $isInList = true;
                                 break;
                             }
                         }
                     }
                     // if category was not found stop further processing and loop with next news record
                     if (!$isInList) {
                         continue;
                     }
                 }
             }
             // compile the information which should go into the index
             $type = 'tt_news';
             $title = strip_tags($newsRecord['title']);
             $abstract = strip_tags($newsRecord['short']);
             $content = strip_tags($newsRecord['bodytext']);
             // add keywords to content if not empty
             if (!empty($newsRecord['keywords'])) {
                 $content .= "\n" . $newsRecord['keywords'];
             }
             // create content
             $fullContent = $abstract . "\n" . $content;
             // create params and custom single view page:
             // if it is a default news (type = 0), add params
             // if it is an internal page (type = 1), put that into the "targetpid" field
             // if it is an external url (type = 2), put that into the "params" field
             if ($newsRecord['type'] == 1) {
                 $singleViewPage = $newsRecord['page'];
                 $params = '';
             } else {
                 if ($newsRecord['type'] == 2) {
                     $type = 'external:tt_news';
                     $singleViewPage = '';
                     $params = $newsRecord['ext_url'];
                 } else {
                     // get target page from category if set (first assigned category)
                     if (TYPO3_VERSION_INTEGER < 6002000) {
                         $ttnewsIsLoaded = t3lib_extMgm::isLoaded('tt_news');
                     } else {
                         $ttnewsIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_news');
                     }
                     if ($ttnewsIsLoaded) {
                         $singleViewPage = $this->getSingleViewPageFromCategories($newsRecord['uid']);
                     }
                     $paramsSingleView = $this->getParamsForHrDateSingleView($newsRecord['datetime']);
                     $paramsSingleView['tx_ttnews']['tt_news'] = $newsRecord['uid'];
                     $params = '&' . http_build_query($paramsSingleView, NULL, '&');
                     $params = rawurldecode($params);
                 }
             }
             // create tags
             if ($this->indexerConfig['index_use_page_tags']) {
                 $tags = $this->pageRecords[intval($newsRecord['pid'])]['tags'];
             } else {
                 $tags = '';
             }
             // add additional fields
             $additionalFields = array();
             // crdate is always given, but can be overwritten
             $additionalFields['sortdate'] = $newsRecord['crdate'];
             // last changed date
             if (isset($newsRecord['datetime']) && $newsRecord['datetime'] > 0) {
                 $additionalFields['sortdate'] = $newsRecord['datetime'];
             }
             // fill orig_uid and orig_pid
             $additionalFields['orig_uid'] = $newsRecord['uid'];
             $additionalFields['orig_pid'] = $newsRecord['pid'];
             // make it possible to modify the indexerConfig via hook
             $indexerConfig = $this->indexerConfig;
             // overwrite default targetpid value from indexerconfig
             // only if $singleViewPage is set
             if ($singleViewPage) {
                 $indexerConfig['targetpid'] = $singleViewPage;
             }
             // hook for custom modifications of the indexed data, e. g. the tags
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyNewsIndexEntry'])) {
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyNewsIndexEntry'] as $_classRef) {
                     if (TYPO3_VERSION_INTEGER >= 7000000) {
                         $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                     } else {
                         $_procObj =& t3lib_div::getUserObj($_classRef);
                     }
                     $_procObj->modifyNewsIndexEntry($title, $abstract, $fullContent, $params, $tags, $newsRecord, $additionalFields, $indexerConfig);
                 }
             }
             // ... and store them
             $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, $type, $indexerConfig['targetpid'], $fullContent, $tags, $params, $abstract, $newsRecord['sys_language_uid'], $newsRecord['starttime'], $newsRecord['endtime'], $newsRecord['fe_group'], false, $additionalFields);
             $counter++;
         }
         $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '":</b><br />' . "\n" . $counter . ' news have been indexed.</p>' . "\n";
         $content .= $this->showErrors();
         $content .= $this->showTime();
     }
     return $content;
 }
 /**
  * get ordering for where query
  *
  * @return string ordering (f.e. score DESC)
  */
 public function getOrdering()
 {
     // if the following code fails, fall back to this default ordering
     $orderBy = $this->conf['sortWithoutSearchword'];
     // if sorting in FE is allowed
     if ($this->conf['showSortInFrontend']) {
         $piVarsField = $this->pObj->piVars['sortByField'];
         $piVarsDir = $this->pObj->piVars['sortByDir'];
         $piVarsDir = $piVarsDir == '' ? 'asc' : $piVarsDir;
         if (!empty($piVarsField)) {
             // if an ordering field is defined by GET/POST
             $isInList = TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->conf['sortByVisitor'], $piVarsField);
             if ($this->conf['sortByVisitor'] != '' && $isInList) {
                 $orderBy = $piVarsField . ' ' . $piVarsDir;
             }
             // if sortByVisitor is not set OR not in the list of
             // allowed fields then use fallback ordering in "sortWithoutSearchword"
         }
         // if sortByVisitor is not set OR not in the list of
         //allowed fields then use fallback ordering in "sortWithoutSearchword"
     } else {
         if (!empty($this->pObj->wordsAgainst)) {
             // if sorting is predefined by admin
             $orderBy = $this->conf['sortByAdmin'];
         } else {
             $orderBy = $this->conf['sortWithoutSearchword'];
         }
     }
     return $orderBy;
 }
 /**
  * loop through all available filters and compile the values for the fluid template rendering
  *
  */
 public function renderFilters()
 {
     foreach ($this->filters->getFilters() as $filter) {
         // if the current filter is a "hidden filter", skip
         // rendering of this filter. The filter is only used
         // to add preselected filter options to the query and
         // must not be rendered.
         $isInList = TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->conf['hiddenfilters'], $filter['uid']);
         if ($isInList) {
             continue;
         }
         // get filter options which should be displayed
         $options = $this->findFilterOptionsToDisplay($filter);
         // alphabetical sorting of filter options
         if ($filter['alphabeticalsorting'] == 1) {
             $this->sortArrayByColumn($options, 'title');
         }
         // hook for modifying filter options
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilterOptionsArray'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilterOptionsArray'] as $_classRef) {
                 $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                 $options = $_procObj->modifyFilterOptionsArray($filter['uid'], $options, $this);
             }
         }
         // build link to reset this filter while keeping the others
         unset($linkconf);
         $linkconf['parameter'] = $GLOBALS['TSFE']->id;
         $linkconf['additionalParams'] = '&tx_kesearch_pi1[sword]=' . $this->piVars['sword'];
         $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filter['uid'] . ']=';
         if (is_array($this->piVars['filter']) && count($this->piVars['filter'])) {
             foreach ($this->piVars['filter'] as $key => $value) {
                 if ($key != $filter['uid']) {
                     $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $key . ']=' . $value;
                 }
             }
         }
         $resetLink = $this->cObj->typoLink_URL($linkconf);
         // set values for fluid template
         $filterData = $filter;
         $filterData['name'] = 'tx_kesearch_pi1[filter][' . $filter['uid'] . ']';
         $filterData['id'] = 'filter_' . $filter['uid'];
         $filterData['options'] = $options;
         $filterData['checkboxOptions'] = $this->compileCheckboxOptions($filter, $options);
         $filterData['optionCount'] = count($options);
         $filterData['resetLink'] = $resetLink;
         // special classes / custom code
         switch ($filter['rendertype']) {
             case 'textlinks':
                 $textLinkObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_lib_filters_textlinks', $this);
                 $textLinkObj->renderTextlinks($filter['uid'], $options, $this);
                 break;
                 // use custom code for filter rendering
             // use custom code for filter rendering
             default:
                 // hook for custom filter renderer
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['customFilterRenderer'])) {
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['customFilterRenderer'] as $_classRef) {
                         $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                         $_procObj->customFilterRenderer($filter['uid'], $options, $this);
                     }
                 }
                 break;
         }
         // add values to fluid template
         $this->fluidTemplateVariables['filters'][] = $filterData;
     }
 }