/** * 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() { $directories = $this->indexerConfig['directories']; $directoryArray = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $directories, true); if ($this->pObj->indexerConfig['fal_storage'] > 0) { /* @var $storageRepository TYPO3\CMS\Core\Resource\StorageRepository */ $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); $this->storage = $storageRepository->findByUid($this->pObj->indexerConfig['fal_storage']); $files = array(); $this->getFilesFromFal($files, $directoryArray); } else { $files = $this->getFilesFromDirectories($directoryArray); } $counter = $this->extractContentAndSaveToIndex($files); // show indexer content? $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '": </b><br />' . count($files) . ' files have been found for indexing.<br />' . "\n" . $counter . ' files have been indexed.</p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); return $content; }
/** * 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 = ''; // get all the records to index // don't index hidden, deleted or not approved comments $fields = '*'; $table = 'tx_comments_comments'; $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) . ') '; $where .= ' AND approved=1'; $where .= ' AND external_prefix IN ("' . implode('","', TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->indexerConfig['commenttypes'])) . '")'; $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $count = 0; while ($comment = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // compile the information which should go into the index $title = $this->compileCommentTitle($comment); $abstract = ''; $content = trim(strip_tags($comment['content'])); // use page ID stored in field "external_ref" as target page // makes sense for comments to page // Should be adjusted for other comments? if ($comment['external_prefix'] == 'pages') { $external_ref_exploded = explode('_', $comment['external_ref']); $targetPage = $external_ref_exploded[1]; } else { // TODO: Make the target page configurable, eg. for tt_news comments //$targetPage = $indexerConfig['targetpid']; $targetPage = 0; } // create tags if ($this->indexerConfig['index_use_page_tags']) { $tags = $this->pageRecords[intval($comment['pid'])]['tags']; } else { $tags = ''; } // fill additional fields $additionalFields = array('orig_uid' => $comment['uid'], 'orig_pid' => $comment['pid'], 'sortdate' => $comment['crdate']); // make it possible to modify the indexerConfig via hook $indexerConfig = $this->indexerConfig; $params = ''; // hook for custom modifications of the indexed data, e. g. the tags if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyCommentsIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyCommentsIndexEntry'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyCommentsIndexEntry($title, $abstract, $content, $params, $tags, $comment, $additionalFields, $indexerConfig); } } // ... and store them $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'comments', $targetPage, $content, $tags, $params, $abstract, -1, 0, 0, '', false, $additionalFields); $count++; } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '":</b><br />' . "\n" . $count . ' Comments have been indexed.</p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); } return $content; }
/** * 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() { $tagChar = $this->pObj->extConf['prePostTagChar']; $now = strtotime('today'); // get YAC records from specified pid $fields = '*'; $table = 'tx_keyac_dates'; $where = 'pid IN (' . $this->indexerConfig['sysfolder'] . ') '; $where .= ' AND hidden=0 AND deleted=0 '; // do not index passed events? if ($this->indexerConfig['index_passed_events'] == 'no') { $keYacProductsIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('ke_yac_products'); if ($keYacProductsIsLoaded) { // special query if ke_yac_products loaded (VNR) $where .= ' AND (( tx_keyacproducts_type<>"product" AND (startdat >= "' . time() . '" OR enddat >= "' . time() . '") ) OR (tx_keyacproducts_type="product" AND tx_keyacproducts_product<>""))'; } else { // "normal" YAC events $where .= ' AND (startdat >= "' . time() . '" OR enddat >= "' . time() . '")'; } } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, $groupBy = '', $orderBy = '', $limit = ''); $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res); if ($resCount) { while ($yacRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // prepare content for storing in index table $title = strip_tags($yacRecord['title']); $tags = ''; $params = '&tx_keyac_pi1[showUid]=' . intval($yacRecord['uid']); $abstract = str_replace('<br />', chr(13), $yacRecord['teaser']); $abstract = str_replace('<br>', chr(13), $abstract); $abstract = str_replace('</p>', chr(13), $abstract); $abstract = strip_tags($abstract); $content = strip_tags($yacRecord['bodytext']); $fullContent = $abstract . "\n" . $content; $targetPID = $this->indexerConfig['targetpid']; // get tags $yacRecordTags = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $yacRecord['tx_keyacsearchtags_tags'], true); $tags = ''; $clearTextTags = ''; if (count($yacRecordTags)) { foreach ($yacRecordTags as $key => $tagUid) { if ($tags) { $tags .= ',' . $tagChar . $this->getTag($tagUid) . $tagChar; } else { $tags = $tagChar . $this->getTag($tagUid) . $tagChar; } $clearTextTags .= chr(13) . $this->getTag($tagUid, true); } } // add clearText Tags to content if (!empty($clearTextTags)) { $fullContent .= chr(13) . $clearTextTags; } // 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']['modifyYACIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyYACIndexEntry'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyYACIndexEntry($title, $abstract, $fullContent, $params, $tags, $yacRecord, $targetPID, $additionalFields, $indexerConfig); } } // store data in index table $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'ke_yac', $targetPID, $fullContent, $tags, $params, $abstract, $yacRecord['sys_language_uid'], $yacRecord['starttime'], $yacRecord['endtime'], $yacRecord['fe_group'], false, $additionalFields); } } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '": ' . $resCount . ' YAC records have been indexed.</b></p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); return $content; }
/** * The main entry point of this class * It will return the complete sorting HTML * * @return string HTML */ public function renderSorting() { // show sorting: // if show Sorting is activated in FlexForm // if a value to sortBy is set in FlexForm (title, relevance, sortdate, what ever...) // if there are any entries in current search results if ($this->conf['showSortInFrontend'] && !empty($this->conf['sortByVisitor']) && $this->pObj->numberOfResults) { // loop all allowed orderings foreach ($this->sortBy as $field) { // we can't sort by score if there is no sword given if ($this->pObj->sword != '' || $field != 'score') { $sortByDir = $this->getDefaultSortingDirection($field); if (TYPO3_VERSION_INTEGER >= 7000000) { $dbOrdering = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $this->db->getOrdering()); } else { $dbOrdering = t3lib_div::trimExplode(' ', $this->db->getOrdering()); } /* if ordering direction is the same change it * * Explaintation: * No ordering is active. Default Ordering by db is "sortdate desc". * Default ordering by current field is also "sortdate desc". * So...if you click the link for sortdate it will sort the results by "sortdate desc" again * To prevent this we change the default ordering here */ if ($field == $dbOrdering[0] && $sortByDir == $dbOrdering[1]) { $sortByDir = $this->changeOrdering($sortByDir); } $markerArray['###FIELDNAME###'] = $field; $markerArray['###URL###'] = $this->generateSortingLink($field, $sortByDir); $markerArray['###CLASS###'] = $this->getClassNameForUpDownArrow($field, $dbOrdering); $links .= $this->cObj->substituteMarkerArray($this->subpartArray['###SORT_LINK###'], $markerArray); } } $content = $this->cObj->substituteSubpart($this->subpartArray['###ORDERNAVIGATION###'], '###SORT_LINK###', $links); $content = $this->cObj->substituteMarker($content, '###LABEL_SORT###', $this->pObj->pi_getLL('label_sort')); return $content; } else { return ''; } }
/** * get recursive DAM categories * * @param integer $catUid The category uid to search in recursive records * @param integer $depth Recursive depth. Normally you don't have to set it. * @return string A commaseperated list of category uids */ public function getRecursiveDAMCategories($catUid, $depth = 0) { if ($catUid) { $enableFields = TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_dam_cat') . TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_dam_cat'); $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('GROUP_CONCAT(uid) AS categoryUids', 'tx_dam_cat', 'parent_id = ' . intval($catUid) . $enableFields, '', '', ''); // add categories to list $listOfCategories = $row['categoryUids']; $categories = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row['categoryUids']); if (is_array($categories) && count($categories)) { foreach ($categories as $category) { // only if further categories are found, add them to list $tempCatList = $this->getRecursiveDAMCategories($category, $depth + 1); $addCategory = count(TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tempCatList, true)); if ($addCategory) { $listOfCategories .= ',' . $tempCatList; } } } return ($depth === 0 ? $catUid . ',' : '') . $listOfCategories; } else { return ''; } }
/** * get a limitted amount of search results for a requested page * * @return array Array containing a limitted (one page) amount of search results */ public function getSearchResultBySphinx() { require_once TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('ke_search_premium') . 'class.user_kesearchpremium.php'; $this->user_kesearchpremium = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('user_kesearchpremium'); // set ordering $this->user_kesearchpremium->setSorting($this->getOrdering()); // set limit $limit = $this->getLimit(); $this->user_kesearchpremium->setLimit($limit[0], $limit[1], intval($this->pObj->extConfPremium['sphinxLimit'])); // generate query $queryForSphinx = ''; if ($this->pObj->wordsAgainst) { $queryForSphinx .= ' @(title,content) ' . $this->escapeString($this->pObj->wordsAgainst); } if (count($this->pObj->tagsAgainst)) { foreach ($this->pObj->tagsAgainst as $value) { // in normal case only checkbox mode has spaces $queryForSphinx .= ' @tags ' . str_replace('" "', '" | "', trim($value)); } } // add language $queryForSphinx .= ' @language _language_-1 | _language_' . $GLOBALS['TSFE']->sys_language_uid; // add fe_groups to query $queryForSphinx .= ' @fe_group _group_NULL | _group_0'; if (!empty($GLOBALS['TSFE']->gr_list)) { $feGroups = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TSFE']->gr_list, 1); foreach ($feGroups as $key => $group) { $intval_positive_group = TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger($group); if ($intval_positive_group) { $feGroups[$key] = '_group_' . $group; } else { unset($feGroups[$key]); } } if (is_array($feGroups) && count($feGroups)) { $queryForSphinx .= ' | ' . implode(' | ', $feGroups); } } // restrict to storage page (in MySQL: $where .= ' AND pid in (' . . ') ';) $startingPoints = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pObj->startingPoints); $queryForSphinx .= ' @pid '; $first = true; foreach ($startingPoints as $startingPoint) { if (!$first) { $queryForSphinx .= ' | '; } else { $first = false; } $queryForSphinx .= ' _pid_' . $startingPoint; } // hook for appending additional where clause to sphinx query if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['appendWhereToSphinx'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['appendWhereToSphinx'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $queryForSphinx = $_procObj->appendWhereToSphinx($queryForSphinx, $this->user_kesearchpremium, $this); } } $rows = $this->user_kesearchpremium->getSearchResults($queryForSphinx); // get number of records $this->numberOfResults = $this->user_kesearchpremium->getTotalFound(); return $rows; }
/** * 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); } }
/** * gets all preselected filters from flexform * * @return none but fills global var with needed data */ public function getFilterPreselect() { // get definitions from plugin settings // and proceed only when preselectedFilter was not set // this reduces the amount of sql queries, too if ($this->conf['preselected_filters'] && count($this->preselectedFilter) == 0) { $preselectedArray = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['preselected_filters'], true); foreach ($preselectedArray as $option) { $option = intval($option); $fields = ' tx_kesearch_filters.uid as filteruid, tx_kesearch_filteroptions.uid as optionuid, tx_kesearch_filteroptions.tag '; $table = 'tx_kesearch_filters, tx_kesearch_filteroptions'; $where = $GLOBALS['TYPO3_DB']->listQuery('tx_kesearch_filters.options', $option, 'tx_kesearch_filters'); $where .= ' AND tx_kesearch_filteroptions.uid = ' . $option; $where .= $this->cObj->enableFields('tx_kesearch_filters'); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, $groupBy = '', $orderBy = '', $limit = ''); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { //$this->preselectedFilter[$row['filteruid']][] = $row['tag']; $this->preselectedFilter[$row['filteruid']][$row['optionuid']] = $row['tag']; } } } }
function getIndexedContent($pageUid) { $fields = '*'; $table = 'tx_kesearch_index'; $where = '(type="page" AND targetpid="' . intval($pageUid) . '") '; $where .= 'OR (type<>"page" AND pid="' . intval($pageUid) . '") '; $where .= \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table, $inv = 0); $where .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table, $inv = 0); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, $groupBy = '', $orderBy = '', $limit = ''); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // build tag table $tagTable = '<div class="tags" >'; $cols = 3; $tags = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row['tags'], true); $i = 1; foreach ($tags as $tag) { $tagTable .= '<span class="tag">' . $tag . '</span>'; } $tagTable .= '</div>'; // build content $timeformat = '%d.%m.%Y %H:%M'; $content .= ' <div class="summary">' . '<span class="title">' . $row['title'] . '</span>' . '<div class="clearer"> </div>' . $this->renderFurtherInformation('Type', $row['type']) . $this->renderFurtherInformation('Words', str_word_count($row['content'])) . $this->renderFurtherInformation('Language', $row['language']) . $this->renderFurtherInformation('Created', strftime($timeformat, $row['crdate'])) . $this->renderFurtherInformation('Modified', strftime($timeformat, $row['tstamp'])) . $this->renderFurtherInformation('Sortdate', $row['sortdate'] ? strftime($timeformat, $row['sortdate']) : '') . $this->renderFurtherInformation('Starttime', $row['starttime'] ? strftime($timeformat, $row['starttime']) : '') . $this->renderFurtherInformation('Endtime', $row['endtime'] ? strftime($timeformat, $row['endtime']) : '') . $this->renderFurtherInformation('FE Group', $row['fe_group']) . $this->renderFurtherInformation('Target Page', $row['targetpid']) . $this->renderFurtherInformation('URL Params', $row['params']) . $this->renderFurtherInformation('Original PID', $row['orig_pid']) . $this->renderFurtherInformation('Original UID', $row['orig_uid']) . $this->renderFurtherInformation('Path', $row['directory']) . '<div class="clearer"> </div>' . '<div class="box"><div class="headline">Abstract</div><div class="content">' . nl2br($row['abstract']) . '</div></div>' . '<div class="box"><div class="headline">Content</div><div class="content">' . nl2br($row['content']) . '</div></div>' . '<div class="box"><div class="headline">Tags</div><div class="content">' . $tagTable . '</div></div>' . '</div>'; } return $content; }