protected function getTreeJS() { /** @var Tx_PtExtbase_ViewHelpers_Javascript_TemplateViewHelper $treeViewHelper */ $treeViewHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('Tx_PtExtbase_ViewHelpers_Javascript_TemplateViewHelper'); $moduleUrl = ''; if (isset($this->arguments['moduleName'])) { $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl($this->arguments['moduleName']); } return $treeViewHelper->render('EXT:pt_extbase/Resources/Private/JSTemplates/Tree/ManipulationTree.js', array('baseUrl' => $this->getBaseURL(), 'dbNodeTable' => 'tx_ptcertification_domain_model_category', 'moduleUrl' => $moduleUrl), false, false); }
/** * 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() { // 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; }
/** * @param $eventUid * @param $tags */ private function buildCategoryTags($eventUid, &$tags) { $table = 'tx_cal_event_category_mm, tx_cal_category'; $fields = 'title'; $where = 'tx_cal_category.uid = tx_cal_event_category_mm.uid_foreign'; $where .= ' AND tx_cal_event_category_mm.uid_local = ' . intval($eventUid); // add enablefields $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_cal_category'); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_cal_category'); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res, 'res count: '); if ($resCount) { while ($catRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // build tags for connected categories tx_kesearch_helper::makeTags($tags, array($catRecord['title'])); } } }
/** * 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']); } }
/** * @see TYPO3\CMS\Backend\Utility\BackendUtility::getLinkToDataHandlerAction * @see TYPO3\CMS\Backend\Template\DocumentTemplate::issueCommand * @see template::issueCommand * * @param string $getParameters * @param string $redirectUrl * @return string */ public function issueCommand($getParameters, $redirectUrl = '') { if (tx_rnbase_util_TYPO3::isTYPO76OrHigher()) { $link = TYPO3\CMS\Backend\Utility\BackendUtility::getLinkToDataHandlerAction($getParameters, $redirectUrl); } else { $link = $this->getDoc()->issueCommand($getParameters, $redirectUrl); } return $link; }
/** * 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) . ') '; $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); $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) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::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; }
/** * 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; }
/** * 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 ''; } }
/** * 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_mmforum_forums'; $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); } // get all the mm_forum forums to index // don't index hidden or deleted entries, BUT // get the entries with frontend user group access restrictions // or time (start / stop) restrictions. // Copy those restrictions to the index. $table = 'tx_mmforum_forums'; $where = 'tx_mmforum_forums.pid IN (' . implode(',', $indexPids) . ') '; $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_mmforum_forums'); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_mmforum_forums'); // Select forums $forumRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_mmforum_forums', $where, '', '', '', 'uid'); $topicCount = 0; foreach ($forumRecords as $forumRecord) { // calculate effective group-rights recursively if (!empty($forumRecord['grouprights_read'])) { $groups = explode(',', $forumRecord['grouprights_read']); } else { $groups = array(); } $parentID = $forumRecord['parentID']; if ($parentID) { $parentForum = $forumRecords[$parentID]; if (!empty($parentForum['grouprights_read'])) { $groups = array_merge($groups, explode(',', $parentForum['grouprights_read'])); } $parentID = $parentForum['parentID']; } $uniqueGroups = array(); foreach ($groups as $group) { $uniqueGroups[intval($group)] = intval($group); } $fegroups = implode(',', $uniqueGroups); // get all the mm_forum topics to index // don't index hidden or deleted entries, BUT // get the entries with frontend user group access restrictions // or time (start / stop) restrictions. // Copy those restrictions to the index. $table = 'tx_mmforum_topics'; $where = 'tx_mmforum_topics.forum_id = ' . $forumRecord['uid'] . ' '; $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_mmforum_topics'); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_mmforum_topics'); // Select topics $resTopic = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, $where, '', '', ''); if ($resTopic) { while ($topicRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resTopic)) { ++$topicCount; // get all the mm_forum text entries to index // don't index hidden or deleted entries, BUT // get the entries with frontend user group access restrictions // or time (start / stop) restrictions. // Copy those restrictions to the index. $table = 'tx_mmforum_posts_text, tx_mmforum_posts'; $where = 'tx_mmforum_posts_text.post_id = tx_mmforum_posts.uid '; $where .= 'AND tx_mmforum_posts.topic_id = ' . $topicRecord['uid'] . ' '; $where .= 'AND tx_mmforum_posts.forum_id = ' . $forumRecord['uid'] . ' '; $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_mmforum_posts_text'); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_mmforum_posts'); $groupBy = ''; $orderBy = ''; $limit = ''; // Select post-texts $resTexts = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_mmforum_posts_text.post_text', $table, $where, $groupBy, $orderBy, $limit); $content = ''; if ($resTexts) { while ($textRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resTexts)) { $content .= strip_tags($textRecord['post_text']) . "\n"; } } // compile the information which should go into the index $title = strip_tags($topicRecord['topic_title']); $abstract = ''; $fullContent = $abstract . "\n" . $content . "\n"; // create params $paramsSingleView = array(); $paramsSingleView['tx_mmforum_pi1']['action'] = 'list_post'; $paramsSingleView['tx_mmforum_pi1']['fid'] = $forumRecord['uid']; // ###FORUM_ID### $paramsSingleView['tx_mmforum_pi1']['tid'] = $topicRecord['uid']; // ###TOPIC_ID### $params = '&' . http_build_query($paramsSingleView, NULL, '&'); $params = rawurldecode($params); // create tags if ($this->indexerConfig['index_use_page_tags']) { $tags = $this->pageRecords[intval($topicRecord['pid'])]['tags']; } else { $tags = ''; } $additionalFields = array(); // crdate is always given, but can be overwritten if (isset($topicRecord['topic_time']) && $topicRecord['topic_time'] > 0) { $additionalFields['sortdate'] = $topicRecord['topic_time']; } // fill orig_uid if (isset($topicRecord['uid']) && $topicRecord['uid'] > 0) { $additionalFields['orig_uid'] = $topicRecord['uid']; } // fill orig_pid if (isset($topicRecord['pid']) && $topicRecord['pid'] > 0) { $additionalFields['orig_pid'] = $topicRecord['pid']; } // 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']['modifyMMForumIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyMMForumIndexEntry'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyMMForumIndexEntry($title, $abstract, $fullContent, $params, $tags, $postRecord, $additionalFields, $indexerConfig); } } // ... and store them $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'mm_forum', $indexerConfig['targetpid'], $fullContent, $tags, $params, $abstract, 0, 0, 0, $fegroups, false, $additionalFields); } } } if ($topicCount) { $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '":</b><br />' . "\n" . $topicCount . ' mm_forum topics have been indexed.</p>' . "\n"; $content .= $this->showTime(); } $content .= $this->showErrors(); return $content; }
/** * 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); } }
/** * Generates the module content * * @return void */ function moduleContent() { $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ke_search']); $content = ''; $do = TYPO3\CMS\Core\Utility\GeneralUtility::_GET('do'); switch ((string) $this->MOD_SETTINGS['function']) { // start indexing process case 1: // make indexer instance and init /* @var $indexer tx_kesearch_indexer */ $indexer = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_indexer'); // get indexer configurations $indexerConfigurations = $indexer->getConfigurations(); // action: start indexer or remove lock if ($do == 'startindexer') { // start indexing in verbose mode with cleanup process $content .= $indexer->startIndexing(true, $this->extConf); } else { if ($do == 'rmLock') { // remove lock from registry - admin only! if ($GLOBALS['BE_USER']->user['admin']) { $this->registry->removeAllByNamespace('tx_kesearch'); } else { $content .= '<p>' . $GLOBALS['LANG']->getLL('not_allowed_remove_indexer_lock') . '</p>'; } } } // show information about indexer configurations and number of records // if action "start indexing" is not selected if ($do != 'startindexer') { $content .= $this->printIndexerConfigurations($indexerConfigurations); $content .= $this->printNumberOfRecords(); } // check for index process lock in registry // remove lock if older than 12 hours $lockTime = $this->registry->get('tx_kesearch', 'startTimeOfIndexer'); $compareTime = time() - 60 * 60 * 12; if ($lockTime !== null && $lockTime < $compareTime) { // lock is older than 12 hours // remove lock and show "start index" button $this->registry->removeAllByNamespace('tx_kesearch'); $lockTime = null; } // show "start indexing" or "remove lock" button if ($lockTime !== null) { if (!$GLOBALS['BE_USER']->user['admin']) { // print warning message for non-admins $content .= '<br /><p style="color: red; font-weight: bold;">WARNING!</p>'; $content .= '<p>The indexer is already running and can not be started twice.</p>'; } else { // show 'remove lock' button for admins $content .= '<br /><p>The indexer is already running and can not be started twice.</p>'; $content .= '<p>The indexing process was started at ' . strftime('%c', $lockTime) . '.</p>'; $content .= '<p>You can remove the lock by clicking the following button.</p>'; $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'rmLock')); $content .= '<br /><a class="lock-button" href="' . $moduleUrl . '">RemoveLock</a>'; } } else { // no lock set - show "start indexer" link if indexer configurations have been found if ($indexerConfigurations) { $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'startindexer')); $content .= '<br /><a class="index-button" href="' . $moduleUrl . '">' . $GLOBALS['LANG']->getLL('start_indexer') . '</a>'; } else { $content .= '<div class="alert alert-info">' . $GLOBALS['LANG']->getLL('no_indexer_configurations') . '</div>'; } } $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('start_indexer'), $content, 0, 1); break; // show indexed content // show indexed content case 2: if ($this->id) { // page is selected: get indexed content $content = '<h2>Index content for page ' . $this->id . '</h2>'; $content .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], -50); $content .= $this->getIndexedContent($this->id); } else { // no page selected: show message $content = '<div class="alert alert-info">' . $GLOBALS['LANG']->getLL('select_a_page') . '</div>'; } $this->content .= $this->doc->section('Show Indexed Content', $content, 0, 1); break; // index table information // index table information case 3: $content = $this->renderIndexTableInformation(); $this->content .= $this->doc->section('Index Table Information', $content, 0, 1); break; // searchword statistics // searchword statistics case 4: // days to show $days = 30; $content = $this->getSearchwordStatistics($this->id, $days); $this->content .= $this->doc->section('Searchword Statistics for the last ' . $days . ' days', $content, 0, 1); break; // clear index // clear index case 5: $content = ''; // admin only access if ($GLOBALS['BE_USER']->user['admin']) { if ($do == 'clear') { $query = 'TRUNCATE TABLE tx_kesearch_index' . $table; $res = $GLOBALS['TYPO3_DB']->sql_query($query); } $content .= '<p>' . $GLOBALS['LANG']->getLL('index_contains') . ' ' . $this->getNumberOfRecordsInIndex() . ' ' . $GLOBALS['LANG']->getLL('records') . '.</p>'; // show "clear index" link $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'clear')); $content .= '<br /><a class="index-button" href="' . $moduleUrl . '">Clear whole search index!</a>'; } else { $content .= '<p>Clear search index: This function is available to admins only.</p>'; } $this->content .= $this->doc->section('Clear Index', $content, 0, 1); break; // last indexing report // last indexing report case 6: $content = $this->showLastIndexingReport(); $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('function6'), $content, 0, 1); break; } }