/**
  * creates a index entry for a given file
  * @param string $file
  * @param string $content
  */
 public function storeToIndex($file, $content)
 {
     $tags = '';
     tx_kesearch_helper::makeTags($tags, array('file'));
     // get data from FAL
     if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
         $metadata = $file->_getMetaData();
         $orig_uid = $file->getUid();
     } else {
         $metadata = false;
         $orig_uid = 0;
     }
     $indexRecordValues = array('storagepid' => $this->indexerConfig['storagepid'], 'title' => $this->fileInfo->getName(), 'type' => 'file:' . $this->fileInfo->getExtension(), 'targetpid' => 1, 'tags' => $tags, 'params' => '', 'abstract' => '', 'language_uid' => -1, 'starttime' => 0, 'endtime' => 0, 'fe_group' => 0, 'debug' => false);
     $additionalFields = array('sortdate' => $this->fileInfo->getModificationTime(), 'orig_uid' => $orig_uid, 'orig_pid' => 0, 'directory' => $this->fileInfo->getRelativePath(), 'hash' => $this->getUniqueHashForFile());
     // add additional content if FAL is used
     if ($this->pObj->indexerConfig['fal_storage'] > 0) {
         // index meta data from FAL: title, description, alternative
         if ($metadata['title']) {
             $indexRecordValues['content'] = $metadata['title'] . "\n" . $indexRecordValues['content'];
         }
         if ($metadata['description']) {
             $indexRecordValues['abstract'] = $metadata['description'];
             $content = $metadata['description'] . "\n" . $content;
         }
         if ($metadata['alternative']) {
             $content .= "\n" . $metadata['alternative'];
         }
         // make tags from assigned categories
         $categories = tx_kesearch_helper::getCategories($metadata['uid'], 'sys_file_metadata');
         tx_kesearch_helper::makeTags($indexRecordValues['tags'], $categories['title_list']);
         // assign categories as generic tags (eg. "syscat123")
         tx_kesearch_helper::makeSystemCategoryTags($indexRecordValues['tags'], $metadata['uid'], 'sys_file_metadata');
     }
     // hook for custom modifications of the indexed data, e. g. the tags
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntry'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntry'] as $_classRef) {
             $_procObj =& GeneralUtility::getUserObj($_classRef);
             $_procObj->modifyFileIndexEntry($file, $content, $additionalFields, $indexRecordValues, $this);
         }
     }
     // store record in index table
     $this->pObj->storeInIndex($indexRecordValues['storagepid'], $indexRecordValues['title'], $indexRecordValues['type'], $indexRecordValues['targetpid'], $content, $indexRecordValues['tags'], $indexRecordValues['params'], $indexRecordValues['abstract'], $indexRecordValues['language_uid'], $indexRecordValues['starttime'], $indexRecordValues['endtime'], $indexRecordValues['fe_group'], $indexRecordValues['debug'], $additionalFields);
 }
 /**
  * finds the system categories for $uid in $tablename, creates
  * tags like "syscat123" ("syscat" + category uid).
  *
  * @param string $tags
  * @param integer $uid
  * @param string $tablename
  * @author Christian Bülter <*****@*****.**>
  * @since 24.09.15
  */
 public static function makeSystemCategoryTags(&$tags, $uid, $tablename)
 {
     $categories = tx_kesearch_helper::getCategories($uid, $tablename);
     if (count($categories['uid_list'])) {
         foreach ($categories['uid_list'] as $category_uid) {
             tx_kesearch_helper::makeTags($tags, array('syscat' . $category_uid));
         }
     }
 }
 /**
  *
  * Store the file content and additional information to the index
  *
  * @param $fileObject file reference object or file object
  * @param string $content file text content
  * @param tx_kesearch_indexer_types_file $fileIndexerObject
  * @param string $feGroups comma list of groups to assign
  * @param array $ttContentRow tt_content element the file was assigned to
  * @author Christian Bülter <*****@*****.**>
  * @since 25.09.13
  */
 public function storeFileContentToIndex($fileObject, $content, $fileIndexerObject, $feGroups, $tags, $ttContentRow)
 {
     // get metadata
     if ($fileObject instanceof TYPO3\CMS\Core\Resource\FileReference) {
         $orig_uid = $fileObject->getOriginalFile()->getUid();
         $metadata = $fileObject->getOriginalFile()->_getMetaData();
     } else {
         $orig_uid = $fileObject->getUid();
         $metadata = $fileObject->_getMetaData();
     }
     // assign categories as tags (as cleartext, eg. "colorblue")
     $categories = tx_kesearch_helper::getCategories($metadata['uid'], 'sys_file_metadata');
     tx_kesearch_helper::makeTags($tags, $categories['title_list']);
     // assign categories as generic tags (eg. "syscat123")
     tx_kesearch_helper::makeSystemCategoryTags($tags, $metadata['uid'], 'sys_file_metadata');
     if ($metadata['title']) {
         $content = $metadata['title'] . "\n" . $content;
     }
     if ($metadata['description']) {
         $abstract = $metadata['description'];
         $content = $metadata['description'] . "\n" . $content;
     }
     if ($metadata['alternative']) {
         $content .= "\n" . $metadata['alternative'];
     }
     $title = $fileIndexerObject->fileInfo->getName();
     $storagePid = $this->indexerConfig['storagepid'];
     $type = 'file:' . $fileObject->getExtension();
     $additionalFields = array('sortdate' => $fileIndexerObject->fileInfo->getModificationTime(), 'orig_uid' => $orig_uid, 'orig_pid' => 0, 'directory' => $fileIndexerObject->fileInfo->getRelativePath(), 'hash' => $fileIndexerObject->getUniqueHashForFile());
     //hook for custom modifications of the indexed data, e. g. the tags
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntryFromContentIndexer'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntryFromContentIndexer'] as $_classRef) {
             $_procObj =& \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
             $_procObj->modifyFileIndexEntryFromContentIndexer($fileObject, $content, $fileIndexerObject, $feGroups, $ttContentRow, $storagePid, $title, $tags, $abstract, $additionalFields);
         }
     }
     // Store record in index table:
     // Add usergroup restrictions of the page and the
     // content element to the index data.
     // Add time restrictions to the index data.
     $this->pObj->storeInIndex($storagePid, $title, $type, $ttContentRow['pid'], $content, $tags, '', $abstract, $ttContentRow['sys_language_uid'], $ttContentRow['starttime'], $ttContentRow['endtime'], $feGroups, false, $additionalFields);
 }
 /**
  * get content of current page and save data to db
  * @param $uid page-UID that has to be indexed
  */
 function getPageContent($uid)
 {
     // get content elements for this page
     $fields = '*';
     $table = 'tt_content';
     $where = 'pid = ' . intval($uid);
     $where .= ' AND (' . $this->whereClauseForCType . ')';
     // add condition for not indexing gridelement columns with colPos = -2 (= invalid)
     if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('gridelements')) {
         $where .= ' AND colPos <> -2 ';
     }
     // don't index elements which are hidden or deleted, but do index
     // those with time restrictons, the time restrictens will be
     // copied to the index
     //$where .= t3lib_BEfunc::BEenableFields($table);
     $where .= ' AND hidden=0';
     $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
     // Get access restrictions for this page
     $pageAccessRestrictions = $this->getInheritedAccessRestrictions($uid);
     $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $table, $where);
     if (count($rows)) {
         foreach ($rows as $row) {
             // skip this content element if the page itself is hidden or a
             // parent page with "extendToSubpages" set is hidden
             if ($pageAccessRestrictions['hidden']) {
                 continue;
             }
             if ($row['sys_language_uid'] > 0 && $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['hidden']) {
                 continue;
             }
             // combine group access restrictons from page(s) and content element
             $feGroups = $this->getCombinedFeGroupsForContentElement($pageAccessRestrictions['fe_group'], $row['fe_group']);
             // skip this content element if either the page or the content
             // element is set to "hide at login"
             // and the other one has a frontend group attached to it
             if ($feGroups == DONOTINDEX) {
                 continue;
             }
             // get content for this content element
             $content = '';
             // get tags from page
             $tags = $this->pageRecords[$uid]['tags'];
             // assign categories as tags (as cleartext, eg. "colorblue")
             $categories = tx_kesearch_helper::getCategories($row['uid'], $table);
             tx_kesearch_helper::makeTags($tags, $categories['title_list']);
             // assign categories as generic tags (eg. "syscat123")
             tx_kesearch_helper::makeSystemCategoryTags($tags, $row['uid'], $table);
             // index header
             // add header only if not set to "hidden"
             if ($row['header_layout'] != 100) {
                 $content .= strip_tags($row['header']) . "\n";
             }
             // index content of this content element and find attached or linked files.
             // Attached files are saved as file references, the RTE links directly to
             // a file, thus we get file objects.
             if (in_array($row['CType'], $this->fileCTypes)) {
                 $fileObjects = $this->findAttachedFiles($row);
             } else {
                 $fileObjects = $this->findLinkedFilesInRte($row);
                 $content .= $this->getContentFromContentElement($row) . "\n";
             }
             // index the files fond
             $this->indexFiles($fileObjects, $row, $pageAccessRestrictions['fe_group]'], $tags) . "\n";
             // Combine starttime and endtime from page, page language overlay
             // and content element.
             // TODO:
             // If current content element is a localized content
             // element, fetch startdate and enddate from original conent
             // element as the localized content element cannot have it's
             // own start- end enddate
             $starttime = $pageAccessRestrictions['starttime'];
             if ($this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['starttime'] > $starttime) {
                 $starttime = $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['starttime'];
             }
             if ($row['starttime'] > $starttime) {
                 $starttime = $row['starttime'];
             }
             $endtime = $pageAccessRestrictions['endtime'];
             if ($endtime == 0 || $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['endtime'] && $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['endtime'] < $endtime) {
                 $endtime = $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['endtime'];
             }
             if ($endtime == 0 || $row['endtime'] && $row['endtime'] < $endtime) {
                 $endtime = $row['endtime'];
             }
             // prepare additionalFields (to be added via hook)
             $additionalFields = array();
             // 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']['modifyContentIndexEntry'])) {
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyContentIndexEntry'] as $_classRef) {
                     $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                     $_procObj->modifyContentIndexEntry($row['header'], $row, $tags, $row['uid'], $additionalFields, $indexerConfig);
                 }
             }
             // compile title from page title and content element title
             // TODO: make changeable via hook
             $title = $this->cachedPageRecords[$row['sys_language_uid']][$row['pid']]['title'];
             if ($row['header'] && $row['header_layout'] != 100) {
                 $title = $title . ' - ' . $row['header'];
             }
             // save record to index
             $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'content', $row['pid'] . '#c' . $row['uid'], $content, $tags, '', '', $row['sys_language_uid'], $starttime, $endtime, $feGroups, false, $additionalFields);
             // count elements written to the index
             $this->counter++;
         }
     } else {
         return;
     }
     return;
 }