/**
  * get all content elements containing a t3s_content-Plugin
  *
  * @return array Array containing tt_content records
  */
 public function getTtContentRecordsWithT3sPlugin()
 {
     $targetPid = intval($this->indexerConfig['targetpid']);
     if ($targetPid) {
         $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tt_content', '1=1' . ' AND pid=' . $targetPid . ' AND CType="list"' . ' AND list_type="t3s_content_pi1"' . ' AND hidden=0 AND deleted=0', '', '', '', 'uid');
         if ($rows) {
             foreach ($rows as $key => $row) {
                 if (TYPO3_VERSION_INTEGER >= 7000000) {
                     $xml = TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($row['pi_flexform']);
                 } else {
                     $xml = t3lib_div::xml2array($row['pi_flexform']);
                 }
                 $config = $xml['data']['general']['lDEF'];
                 $ttContentUids[] = $config['contentElements']['vDEF'];
             }
             $ttContentUids = implode(',', $ttContentUids);
             if (TYPO3_VERSION_INTEGER >= 7000000) {
                 $ttContentUids = TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList($ttContentUids);
             } else {
                 $ttContentUids = t3lib_div::uniqueList($ttContentUids);
             }
             $ttContentRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tt_content', ' uid IN (' . $ttContentUids . ')', '', '', '', 'uid');
             if ($ttContentRecords) {
                 return $ttContentRecords;
             }
         }
     }
     return array();
 }
 /**
  *
  * combines two string comma lists
  *
  * @param string $list1
  * @param string $list2
  * @author Christian Bülter <*****@*****.**>
  * @since 23.07.13
  * @return string
  */
 public function combineLists($list1 = '', $list2 = '')
 {
     if (!empty($list2) && !empty($list2)) {
         $list1 .= ',';
     }
     $list1 .= $list2;
     $returnValue = TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList($list1);
     return $returnValue;
 }
 /**
  * get content of current page and save data to db
  * @param $uid page-UID that has to be indexed
  */
 public function getPageContent($uid)
 {
     $flex = $this->pageRecords[$uid]['tx_templavoila_flex'];
     if (empty($flex)) {
         return '';
     }
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $flex = TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flex);
     } else {
         $flex = t3lib_div::xml2array($flex);
     }
     // TODO: Maybe I need a more detailed collection of retrieving CE UIDS
     $contentElementUids = array();
     if (!$this->indexerConfig['tvpath']) {
         $tvPaths = 'field_content';
     } else {
         $tvPaths = $this->indexerConfig['tvpath'];
     }
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $tvPaths = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tvPaths);
     } else {
         $tvPaths = t3lib_div::trimExplode(',', $tvPaths);
     }
     foreach ($tvPaths as $tvPath) {
         $contentElementUids[] = $flex['data']['sDEF']['lDEF'][$tvPath]['vDEF'];
     }
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $contentElementUids = TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList(implode(',', $contentElementUids));
     } else {
         $contentElementUids = t3lib_div::uniqueList(implode(',', $contentElementUids));
     }
     if (empty($contentElementUids)) {
         return '';
     }
     // TODO: Maybe it's good to check comma seperated list for int values
     // get content elements for this page
     $fields = '*';
     $table = 'tt_content';
     $where = 'uid IN (' . $contentElementUids . ')';
     $where .= ' AND (' . $this->whereClauseForCType . ')';
     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);
     }
     // if indexing of content elements with restrictions is not allowed
     // get only content elements that have empty group restrictions
     if ($this->indexerConfig['index_content_with_restrictions'] != 'yes') {
         $where .= ' AND (fe_group = "" OR fe_group = "0") ';
     }
     $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $table, $where);
     if (count($rows)) {
         $this->counter++;
         foreach ($rows as $row) {
             // header
             // add header only if not set to "hidden"
             if ($row['header_layout'] != 100) {
                 $pageContent[$row['sys_language_uid']] .= strip_tags($row['header']) . "\n";
             }
             // bodytext
             $bodytext = $row['bodytext'];
             if ($row['CType'] == 'table') {
                 // replace table dividers with whitespace
                 $bodytext = str_replace('|', ' ', $bodytext);
             }
             if ($row['CType'] == 'templavoila_pi1') {
                 //$bodytext = $this->getContentForTV($row);
                 $bodytext = $this->tv->renderElement($row, 'tt_content');
             }
             // following lines prevents having words one after the other like: HelloAllTogether
             $bodytext = str_replace('<td', ' <td', $bodytext);
             $bodytext = str_replace('<br', ' <br', $bodytext);
             $bodytext = str_replace('<p', ' <p', $bodytext);
             $bodytext = str_replace('<li', ' <li', $bodytext);
             $bodytext = strip_tags($bodytext);
             $pageContent[$row['sys_language_uid']] .= $bodytext . "\n";
         }
     }
     // get Tags for current page
     $tags = $this->pageRecords[intval($uid)]['tags'];
     // make it possible to modify the indexerConfig via hook
     $indexerConfig = $this->indexerConfig;
     // hook for custom modifications of the indexed data, e. g. the tags
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyTemplaVoilaIndexEntry'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyTemplaVoilaIndexEntry'] as $_classRef) {
             if (TYPO3_VERSION_INTEGER >= 7000000) {
                 $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
             } else {
                 $_procObj =& t3lib_div::getUserObj($_classRef);
             }
             $_procObj->modifyPagesIndexEntry($uid, $pageContent, $tags, $this->cachedPageRecords, $additionalFields, $indexerConfig);
         }
     }
     // store record in index table
     foreach ($pageContent as $langKey => $content) {
         $this->pObj->storeInIndex($indexerConfig['storagepid'], $this->cachedPageRecords[$langKey][$uid]['title'], 'templavoila', $uid, $content, $tags, '', '', $langKey, $this->cachedPageRecords[$langKey][$uid]['starttime'], $this->cachedPageRecords[$langKey][$uid]['endtime'], $this->cachedPageRecords[$langKey][$uid]['fe_group'], false, $additionalFields);
     }
 }
 /**
  * store collected data of defined indexers to db
  *
  * @param integer $storagepid
  * @param string $title
  * @param string $type
  * @param string $targetpid
  * @param string $content
  * @param string $tags
  * @param string $params
  * @param string $abstract
  * @param string $language
  * @param integer $starttime
  * @param integer $endtime
  * @param string $fe_group
  * @param boolean $debugOnly
  * @param array $additionalFields
  */
 function storeInIndex($storagePid, $title, $type, $targetPid, $content, $tags = '', $params = '', $abstract = '', $language = 0, $starttime = 0, $endtime = 0, $fe_group = '', $debugOnly = false, $additionalFields = array())
 {
     // if there are errors found in current record return false and break processing
     if (!$this->checkIfRecordHasErrorsBeforeIndexing($storagePid, $title, $type, $targetPid)) {
         return false;
     }
     // optionally add tag set in the indexer configuration
     if (!empty($this->indexerConfig['filteroption']) && (substr($type, 0, 4) != 'file' || substr($type, 0, 4) == 'file' && $this->indexerConfig['index_use_page_tags_for_files'] || $this->indexerConfig['type'] == 'file')) {
         $indexerTag = $this->getTag($this->indexerConfig['filteroption']);
         $tagChar = $this->extConf['prePostTagChar'];
         if ($tags) {
             $tags .= ',' . $tagChar . $indexerTag . $tagChar;
         } else {
             $tags = $tagChar . $indexerTag . $tagChar;
         }
         if (TYPO3_VERSION_INTEGER >= 7000000) {
             $tags = TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList($tags);
         } else {
             $tags = t3lib_div::uniqueList($tags);
         }
     }
     $table = 'tx_kesearch_index';
     $fieldValues = $this->createFieldValuesForIndexing($storagePid, $title, $type, $targetPid, $content, $tags, $params, $abstract, $language, $starttime, $endtime, $fe_group, $additionalFields);
     // check if record already exists
     if (substr($type, 0, 4) == 'file') {
         $recordExists = $this->checkIfFileWasIndexed($fieldValues['type'], $fieldValues['hash']);
     } else {
         $recordExists = $this->checkIfRecordWasIndexed($fieldValues['orig_uid'], $fieldValues['pid'], $fieldValues['type'], $fieldValues['language']);
     }
     if ($recordExists) {
         // update existing record
         $where = 'uid=' . intval($this->currentRow['uid']);
         unset($fieldValues['crdate']);
         if ($debugOnly) {
             // do not process - just debug query
             t3lib_utility_Debug::debug($GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fieldValues), 1);
         } else {
             // process storing of index record and return uid
             $this->prepareRecordForUpdate($fieldValues);
             return true;
         }
     } else {
         // insert new record
         if ($debugOnly) {
             // do not process - just debug query
             t3lib_utility_Debug::debug($GLOBALS['TYPO3_DB']->INSERTquery($table, $fieldValues, FALSE));
         } else {
             // process storing of index record and return uid
             $this->prepareRecordForInsert($fieldValues);
             return $GLOBALS['TYPO3_DB']->sql_insert_id();
         }
     }
 }
 /**
  * 
  * combines two string comma lists
  * 
  * @param string $list1
  * @param string $list2
  * @author Christian Bülter <*****@*****.**>
  * @since 23.07.13 
  * @return string
  */
 public function combineLists($list1 = '', $list2 = '')
 {
     if (!empty($list2) && !empty($list2)) {
         $list1 .= ',';
     }
     $list1 .= $list2;
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $returnValue = TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList($list1);
     } else {
         $returnValue = t3lib_div::uniqueList($list1);
     }
     return $returnValue;
 }