/** * Test additional query parts for additional fields * @test */ public function getTagTest() { $fields = 'uid, title, tag'; $table = 'tx_kesearch_filteroptions'; $where = '1=1 '; $where .= t3lib_befunc::BEenableFields($table, 0); $where .= t3lib_befunc::deleteClause($table, 0); $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow($fields, $table, $where); if (is_array($row) && count($row)) { $return = $this->indexer->getTag($row['uid'], false); $this->assertEquals($row['tag'], $return); $return = $this->indexer->getTag($row['uid'], true); $this->assertEquals($row['title'], $return); } }
/** * 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() { // get all address records from pid set in indexerConfig $fields = '*'; $table = 'tt_address'; $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); $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res); // no address records found if (!$resCount) { $content = '<p>No address records found!</p>'; return $content; } // if records found: process them while ($addressRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $abstract = ''; $content = ''; // set title, use company if set, otherwise name $title = !empty($addressRow['company']) ? $addressRow['company'] : (!empty($addressRow['name']) ? $addressRow['name'] : $addressRow['first_name'] . ' ' . $addressRow['last_name']); // use description as abstract if set if (!empty($addressRow['description'])) { $abstract = $addressRow['description']; } // build content if (!empty($addressRow['company'])) { $content .= $addressRow['company'] . "\n"; } if (!empty($addressRow['title'])) { $content .= $addressRow['title'] . ' '; } if (!empty($addressRow['name'])) { $content .= $addressRow['name'] . "\n"; // name } else { if (!empty($addressRow['first_name'])) { $content .= $addressRow['first_name'] . ' '; } if (!empty($addressRow['middle_name'])) { $content .= $addressRow['middle_name'] . ' '; } if (!empty($addressRow['last_name'])) { $content .= $addressRow['last_name'] . ' '; } if (!empty($addressRow['last_name']) || !empty($addressRow['middle_name']) || !empty($addressRow['middle_name'])) { $content .= "\n"; } } if (!empty($addressRow['address'])) { $content .= $addressRow['address'] . "\n"; } if (!empty($addressRow['zip'])) { $content .= $addressRow['zip'] . "\n"; } if (!empty($addressRow['city'])) { $content .= $addressRow['city'] . "\n"; } if (!empty($addressRow['country'])) { $content .= $addressRow['country'] . "\n"; } if (!empty($addressRow['region'])) { $content .= $addressRow['region'] . "\n"; } if (!empty($addressRow['email'])) { $content .= $addressRow['email'] . "\n"; } if (!empty($addressRow['phone'])) { $content .= $addressRow['phone'] . "\n"; } if (!empty($addressRow['fax'])) { $content .= $addressRow['fax'] . "\n"; } if (!empty($addressRow['mobile'])) { $content .= $addressRow['mobile'] . "\n"; } if (!empty($addressRow['www'])) { $content .= $addressRow['www']; } // put content together $fullContent = $abstract . "\n" . $content; // there is no tt_address default param like this; you have to modify this by hook to fit your needs $params = '&tt_address[showUid]=' . $addressRow['uid']; // no tags yet if ($this->indexerConfig['index_use_page_tags']) { $tagContent = $this->pageRecords[intval($addressRow['pid'])]['tags']; } else { $tagContent = ''; } // set additional fields for sorting $additionalFields = array('sortdate' => $addressRow['tstamp']); // fill orig_uid if (isset($addressRow['uid']) && $addressRow['uid'] > 0) { $additionalFields['orig_uid'] = $addressRow['uid']; } // fill orig_pid if (isset($addressRow['pid']) && $addressRow['pid'] > 0) { $additionalFields['orig_pid'] = $addressRow['pid']; } // make it possible to modify the indexerConfig via hook $indexerConfig = $this->indexerConfig; // add some fields which you may set in your own hook $customfields = array('sys_language_uid' => 0, 'starttime' => 0, 'endtime' => 0, 'fe_group' => ''); // hook for custom modifications of the indexed data, e. g. the tags if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyAddressIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyAddressIndexEntry'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->modifyAddressIndexEntry($title, $abstract, $fullContent, $params, $tagContent, $addressRow, $additionalFields, $indexerConfig, $customfields); } } // store in index $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'tt_address', $indexerConfig['targetpid'], $fullContent, $tagContent, $params, $abstract, $customfields['sys_language_uid'], $customfields['starttime'], $customfields['endtime'], $customfields['fe_group'], false, $additionalFields); } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '": ' . $resCount . ' address records have been indexed.</b></p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); return $content; }
/** * Adds tags from the ext:news table "tags" as ke_search tags to the index entry * * @author Christian Bülter <*****@*****.**> * @since 26.06.13 14:25 * @param string $tags * @param array $newsRecord * @return string comma-separated list of tags */ private function addTagsFromNewsTags($tags, $newsRecord) { if (TYPO3_VERSION_INTEGER >= 7000000) { $addWhere = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_news_domain_model_tag') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_news_domain_model_tag'); } else { $addWhere = t3lib_befunc::BEenableFields('tx_news_domain_model_tag') . t3lib_befunc::deleteClause('tx_news_domain_model_tag'); } $resTag = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_news_domain_model_tag.title', 'tx_news_domain_model_news', 'tx_news_domain_model_news_tag_mm', 'tx_news_domain_model_tag', ' AND tx_news_domain_model_news.uid = ' . $newsRecord['uid'] . $addWhere); while ($newsTag = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resTag)) { tx_kesearch_helper::makeTags($tags, array($newsTag['title'])); } return $tags; }
/** * Searches the category rootline (up) for a single view pid. If nothing is found in the current * category, the single view pid of the parent categories is taken (recusivly). * taken from tx_ttnews * * @param int $currentCategory: Uid of the current category * @return int first found single view pid */ function getRecursiveCategorySinglePid($currentCategory) { if (TYPO3_VERSION_INTEGER >= 7000000) { $addWhere = ' AND tt_news_cat.deleted=0' . TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_news_cat'); } else { $addWhere = ' AND tt_news_cat.deleted=0' . t3lib_befunc::BEenableFields('tt_news_cat'); } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,parent_category,single_pid', 'tt_news_cat', 'tt_news_cat.uid=' . $currentCategory . $addWhere); $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $GLOBALS['TYPO3_DB']->sql_free_result($res); if ($row['single_pid'] > 0) { return $row['single_pid']; } elseif ($row['parent_category'] > 0) { return $this->getRecursiveCategorySinglePid($row['parent_category']); } }
function getListOfAvailableFilteroptionsForFlexforms(&$config) { // get id from string if (strstr($config['row']['pages'], 'pages_')) { $intString = str_replace('pages_', '', $config['row']['pages']); $intString = substr($intString, 0, strpos($intString, '|')); $intString = intval($intString); } else { $intString = intval($config['row']['pages']); } // print message if no startingpoint is set in plugin config if (empty($intString)) { $config['items'][] = array('[SET STARTINGPOINT FIRST!]', ''); } // get filters $fields = '*'; $table = 'tx_kesearch_filters'; $where = 'pid IN(' . $intString . ') '; if (TYPO3_VERSION_INTEGER > 7000000) { $where .= \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table, $inv = 0); $where .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table, $inv = 0); } else { $where .= t3lib_befunc::BEenableFields($table, $inv = 0); $where .= t3lib_befunc::deleteClause($table, $inv = 0); } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, $groupBy = '', $orderBy = '', $limit = ''); while ($rowFilter = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { if (!empty($rowFilter['options'])) { // get filteroptions $fieldsOpts = '*'; $tableOpts = 'tx_kesearch_filteroptions'; $whereOpts = 'uid in (' . $rowFilter['options'] . ')'; if (TYPO3_VERSION_INTEGER > 7000000) { $whereOpts .= \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($tableOpts, $inv = 0); $whereOpts .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tableOpts, $inv = 0); } else { $whereOpts .= t3lib_befunc::BEenableFields($tableOpts, $inv = 0); $whereOpts .= t3lib_befunc::deleteClause($tableOpts, $inv = 0); } $resOpts = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldsOpts, $tableOpts, $whereOpts, $groupBy = '', $orderBy = '', $limit = ''); while ($rowOpts = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resOpts)) { $config['items'][] = array($rowFilter['title'] . ': ' . $rowOpts['title'], $rowOpts['uid']); } } } }
/** * this function returns all indexer configurations found in DB * independant of PID */ public function getConfigurations() { $fields = '*'; $table = 'tx_kesearch_indexerconfig'; $where = '1=1 '; 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); } return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $table, $where); }
/** * 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) { if (TYPO3_VERSION_INTEGER >= 7000000) { $enableFields = TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_dam_cat') . TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_dam_cat'); } else { $enableFields = t3lib_befunc::BEenableFields('tx_dam_cat') . t3lib_befunc::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']; if (TYPO3_VERSION_INTEGER >= 7000000) { $categories = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row['categoryUids']); } else { $categories = t3lib_div::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); if (TYPO3_VERSION_INTEGER >= 7000000) { $addCategory = count(TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tempCatList, true)); } else { $addCategory = count(t3lib_div::trimExplode(',', $tempCatList, true)); } if ($addCategory) { $listOfCategories .= ',' . $tempCatList; } } } return ($depth === 0 ? $catUid . ',' : '') . $listOfCategories; } else { return ''; } }
/** * 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 = ''; $table = 'tx_a21glossary_main'; // get the pages from where to index the news $indexPids = $this->getPidList($this->indexerConfig['startingpoints_recursive'], $this->indexerConfig['sysfolder'], $table); // add the tags of the parent page if ($this->indexerConfig['index_use_page_tags']) { $this->pageRecords = $this->getPageRecords($indexPids); $this->addTagsToRecords($indexPids); } // get all the glossary records to index, don't index hidden or // deleted glossary records, BUT get the records with frontend user group // access restrictions or time (start / stop) restrictions. // Copy those restrictions to the index. $fields = '*'; $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); $indexedRecordsCounter = 0; $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res); if ($resCount) { while ($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // compile the information which should go into the index: // short, shortcut, longversion, shorttype, description, link $title = strip_tags($record['short']); $abstract = strip_tags($record['longversion']); $fullContent = strip_tags($record['shortcut'] . "\n" . $record['longversion'] . "\n" . $record['description'] . "\n" . $record['link']); // compile params for single view, example: // index.php?id=16&tx_a21glossary[uid]=71&cHash=9f9368211d8ae742a8d3ad29c4f0a308 $paramsSingleView = array(); $paramsSingleView['tx_a21glossary']['uid'] = $record['uid']; $params = rawurldecode('&' . http_build_query($paramsSingleView, NULL, '&')); // add tags from pages if ($this->indexerConfig['index_use_page_tags']) { $tags = $this->pageRecords[intval($record['pid'])]['tags']; } else { $tags = ''; } // make it possible to modify the indexerConfig via hook $indexerConfig = $this->indexerConfig; // set additional fields $additionalFields = array(); $additionalFields['orig_uid'] = $record['uid']; $additionalFields['orig_pid'] = $record['pid']; $additionalFields['sortdate'] = $record['crdate']; // hook for custom modifications of the indexed data, e.g. the tags if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifya21glossaryIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifya21glossaryIndexEntry'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->modifya21glossaryIndexEntry($title, $abstract, $fullContent, $params, $tags, $record, $additionalFields, $indexerConfig, $this); } } // store this record to the index $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'a21glossary', $indexerConfig['targetpid'], $fullContent, $tags, $params, $abstract, $record['sys_language_uid'], $record['starttime'], $record['endtime'], $record['fe_group'], false, $additionalFields); $indexedRecordsCounter++; } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '":</b><br />' . "\n" . $indexedRecordsCounter . ' glossary records 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'; if (TYPO3_VERSION_INTEGER >= 7000000) { $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); } else { $where .= ' AND external_prefix IN ("' . implode('","', t3lib_div::trimExplode(',', $this->indexerConfig['commenttypes'])) . '")'; $where .= t3lib_befunc::BEenableFields($table); $where .= t3lib_befunc::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; // 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) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::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; }
/** * returns the list of assigned categories to a certain record in a certain table * * @param integer $uid * @param string $table * @author Christian Bülter <*****@*****.**> * @since 17.10.14 * @return array */ public static function getCategories($uid, $table) { $categoryData = array('uid_list' => array(), 'title_list' => array()); if ($uid && $table) { if (TYPO3_VERSION_INTEGER >= 7000000) { $enableFields = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('sys_category') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_category'); } else { $enableFields = t3lib_befunc::BEenableFields('sys_category') . t3lib_befunc::deleteClause('sys_category'); } $resCat = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('sys_category.uid, sys_category.title', 'sys_category', 'sys_category_record_mm', $table, ' AND ' . $table . '.uid = ' . $uid . ' AND sys_category_record_mm.tablenames = "' . $table . '"' . $enableFields, '', 'sys_category_record_mm.sorting'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($resCat)) { while ($cat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resCat)) { $categoryData['uid_list'][] = $cat['uid']; $categoryData['title_list'][] = $cat['title']; } } } return $categoryData; }
public function getTag($tagUid, $clearText = false) { $fields = 'title,tag'; $table = 'tx_kesearch_filteroptions'; $where = 'uid="' . intval($tagUid) . '" '; 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, $groupBy = '', $orderBy = '', $limit = '1'); $anz = $GLOBALS['TYPO3_DB']->sql_num_rows($res); $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); if ($clearText) { return $row['title']; } else { return $row['tag']; } }