/** * Initializes this object * * @param tx_kesearch_lib $pObj * @return void */ public function initialize(tx_kesearch_lib $pObj) { $this->pObj = $pObj; $this->cObj = $pObj->cObj; if (TYPO3_VERSION_INTEGER >= 6002000) { $this->db = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_db'); } else { $this->db = t3lib_div::makeInstance('tx_kesearch_db'); } $this->conf = $this->pObj->conf; $this->piVars = $this->pObj->piVars; $this->startingPoints = $this->pObj->startingPoints; $this->tagChar = $this->pObj->extConf['prePostTagChar']; // get filters and filter options $this->filters = $this->getFiltersFromUidList($this->combineLists($this->conf['filters'], $this->conf['hiddenfilters'])); // hook to modify filters if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilters'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilters'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->modifyFilters($this->filters, $this); } } // get list of selected filter options (via frontend or backend) foreach ($this->filters as $filter) { $this->filters[$filter['uid']]['selectedOptions'] = $this->getSelectedFilterOptions($filter); } }
public function fillIndexerConfig(&$params, $pObj) { // hook for custom registration of further indexerConfigurations if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerIndexerConfiguration'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerIndexerConfiguration'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->registerIndexerConfiguration($params, $pObj); } } }
/** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { $this->ms = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds(); $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); // Configuring so caching is not expected. This value means that no cHash params are ever set. // We do this, because it's a USER_INT object! $this->pi_USER_INT_obj = 1; // initializes plugin configuration $this->init(); if ($this->conf['resultPage'] != $GLOBALS['TSFE']->id) { $content = '<div id="textmessage">' . $this->pi_getLL('error_resultPage') . '</div>'; return $this->pi_wrapInBaseClass($content); } // init template $this->initFluidTemplate(); // hook for initials if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->addInitials($this); } } // assign isEmptySearch to fluid templates $this->fluidTemplateVariables['isEmptySearch'] = $this->isEmptySearch; // render "no results"-message, "too short words"-message and finally the result list $this->getSearchResults(); // number of results $this->fluidTemplateVariables['numberofresults'] = $this->numberOfResults; // render links for sorting, fluid template variables are filled in class tx_kesearch_lib_sorting $this->renderOrdering(); // process query time $queryTime = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds() - $GLOBALS['TSFE']->register['ke_search_queryStartTime']; $this->fluidTemplateVariables['queryTime'] = $queryTime; $this->fluidTemplateVariables['queryTimeText'] = sprintf($this->pi_getLL('query_time'), $queryTime); // render pagebrowser if ($GLOBALS['TSFE']->id == $this->conf['resultPage']) { if ($this->conf['pagebrowserOnTop'] || $this->conf['pagebrowserAtBottom']) { $this->renderPagebrowser(); } } // generate HTML output $this->resultListView->assignMultiple($this->fluidTemplateVariables); $htmlOutput = $this->resultListView->render(); return $htmlOutput; }
/** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { $this->ms = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds(); $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->pi_USER_INT_obj = 1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! // initializes plugin configuration $this->init(); // init XAJAX? if ($this->conf['renderMethod'] != 'static') { $xajaxIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('xajax'); if (!$xajaxIsLoaded) { return '<span style="color: red;"><b>ke_search error:</b>"XAJAX" must be installed for this mode.</span>'; } else { $this->initXajax(); } } // hook for initials if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->addInitials($this); } } // get templates $template['multiselect'] = $this->cObj->getSubpart($this->templateCode, '###SUB_FILTER_MULTISELECT###'); $template['multihidden'] = $this->cObj->getSubpart($template['multiselect'], '###SUB_FILTER_MULTISELECT_HIDDEN###'); $template['multifilter'] = $this->cObj->getSubpart($template['multiselect'], '###SUB_FILTER_MULTISELECT_FILTER###'); $template['multioption'] = $this->cObj->getSubpart($template['multifilter'], '###SUB_FILTER_MULTISELECT_OPTION###'); // get current filter $filters = $this->filters->getFilters(); foreach ($filters as $filter) { if ($filter['target_pid'] == intval($GLOBALS['TSFE']->id)) { break; } } // hook for modifying content if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyMultiselectContent'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyMultiselectContent'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $content = $_procObj->modifyMultiselectContent($template['multiselect'], $filter, $this); } } if (is_array($filter) && count($filter)) { $contentOptions = ''; $optionsAmountArray = $GLOBALS['TSFE']->fe_user->getKey('ses', 'ke_search.tagsInSearchResults'); $countLoops = 1; if (is_array($this->piVars['filter'][$filter['uid']]) && count($this->piVars['filter'][$filter['uid']])) { $this->piVars['filter'][$filter['uid']] = array_unique($this->piVars['filter'][$filter['uid']]); } foreach ($filter['options'] as $optionKey => $option) { $option['title'] = htmlspecialchars($option['title']); $option['tag'] = htmlspecialchars($option['tag']); if ($optionsAmountArray[$option['tag']]) { $optionCounter = $optionsAmountArray[$option['tag']]; } else { $optionCounter = 0; } $selected = $this->piVars['filter'][$filter['uid']][$optionKey] ? 'checked="checked"' : ''; $markerArray['###ADDCLASS###'] = $countLoops % 3 ? '' : ' last'; $markerArray['###FILTERNAME###'] = 'tx_kesearch_pi1[filter][' . $filter['uid'] . ']'; $markerArray['###OPTIONID###'] = $option['uid']; $markerArray['###OPTIONKEY###'] = $optionKey; $markerArray['###OPTIONTITLE###'] = $option['title'] . ' (' . $optionCounter . ')'; $markerArray['###OPTIONTAG###'] = $option['tag']; $markerArray['###SELECTED###'] = $selected; $countLoops++; $contentOptions .= $this->cObj->substituteMarkerArray($template['multioption'], $markerArray); } $content .= $this->cObj->substituteSubpart($template['multifilter'], '###SUB_FILTER_MULTISELECT_OPTION###', $contentOptions); $content = $this->cObj->substituteMarker($content, '###TITLE###', $filter['title']); } $content = $this->cObj->substituteSubpart($template['multiselect'], '###SUB_FILTER_MULTISELECT_FILTER###', $content); $content = $this->cObj->substituteMarker($content, '###FORM_ACTION###', $this->pi_getPageLink($this->conf['resultPage'])); $content = $this->cObj->substituteMarker($content, '###SHOW_RESULTS###', $this->pi_getLL('show_results')); $content = $this->cObj->substituteMarker($content, '###LINK_BACK###', $this->cObj->typoLink($this->pi_getLL('back'), array('parameter' => $this->conf['resultPage'], 'addQueryString' => 1, 'addQueryString.' => array('exclude' => 'id')))); if (is_array($this->piVars['filter']) && count($this->piVars['filter'])) { foreach ($this->piVars['filter'] as $filterKey => $filterValue) { if ($filterKey == $filter['uid']) { continue; } foreach ($this->piVars['filter'][$filterKey] as $optionKey => $option) { $hidden .= $this->cObj->substituteMarker($template['multihidden'], '###NAME###', 'tx_kesearch_pi1[filter][' . $filterKey . '][' . $optionKey . ']'); $hidden = $this->cObj->substituteMarker($hidden, '###VALUE###', $option); } } } $content = $this->cObj->substituteSubpart($content, '###SUB_FILTER_MULTISELECT_HIDDEN###', $hidden); $content = $this->cObj->substituteMarker($content, '###PAGEID###', $this->conf['resultPage']); $content = $this->cObj->substituteMarker($content, '###SWORD###', htmlspecialchars($this->piVars['sword'])); return $this->pi_wrapInBaseClass($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; }
public function renderPagebrowser() { $this->initOnclickActions(); // hook for third party pagebrowsers or for modification of build in browser // if the hook return content then return that content // use only if you use marker based templating, not for fluid based templating! $content = ''; if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['renderPagebrowserInit'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['renderPagebrowserInit'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $content = $_procObj->renderPagebrowserInit($this); } } if ($content) { return $content; } $numberOfResults = $this->numberOfResults; $resultsPerPage = $this->conf['resultsPerPage']; $maxPages = $this->conf['maxPagesInPagebrowser']; // get total number of items to show if ($numberOfResults > $resultsPerPage) { // show pagebrowser if there are more entries that are // shown on one page $this->limit = $resultsPerPage; } else { // do not show pagebrowser return ''; } // set db limit $start = $this->piVars['page'] * $resultsPerPage - $resultsPerPage; $this->dbLimit = $start . ',' . $resultsPerPage; // number of pages $pagesTotal = ceil($numberOfResults / $resultsPerPage); $interval = ceil($maxPages / 2); $startPage = $this->piVars['page'] - ceil($maxPages / 2); $endPage = $startPage + $maxPages - 1; if ($startPage < 1) { $startPage = 1; $endPage = $startPage + $maxPages - 1; } if ($startPage > $pagesTotal) { $startPage = $pagesTotal - $maxPages + 1; $endPage = $pagesTotal; } if ($endPage > $pagesTotal) { $startPage = $pagesTotal - $maxPages + 1; $endPage = $pagesTotal; } // render pages list for ($i = 1; $i <= $pagesTotal; $i++) { if ($i >= $startPage && $i <= $endPage) { // render static version unset($linkconf); $linkconf['parameter'] = $GLOBALS['TSFE']->id; $linkconf['addQueryString'] = 1; $linkconf['addQueryString.']['exclude'] = 'id'; $linkconf['additionalParams'] = '&tx_kesearch_pi1[page]=' . intval($i); $filterArray = $this->filters->getFilters(); if (is_array($this->piVars['filter'])) { foreach ($this->piVars['filter'] as $filterId => $data) { if (is_array($data)) { foreach ($data as $tagKey => $tag) { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . '][' . $tagKey . ']=' . $tag; } } else { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . ']=' . $this->piVars['filter'][$filterId]; } } } if ($this->piVars['page'] == $i) { $linkconf['ATagParams'] = 'class="current" '; } $tempContent .= $this->cObj->typoLink($i, $linkconf) . ' '; } } // end $end = $start + $resultsPerPage > $numberOfResults ? $numberOfResults : $start + $resultsPerPage; // previous image with link if ($this->piVars['page'] > 1) { $previousPage = $this->piVars['page'] - 1; // get static version unset($linkconf); $linkconf['parameter'] = $GLOBALS['TSFE']->id; $linkconf['addQueryString'] = 1; $linkconf['additionalParams'] = '&tx_kesearch_pi1[sword]=' . $this->piVars['sword']; $linkconf['additionalParams'] .= '&tx_kesearch_pi1[page]=' . intval($previousPage); $filterArray = $this->filters->getFilters(); if (is_array($this->piVars['filter'])) { foreach ($this->piVars['filter'] as $filterId => $data) { if (is_array($data)) { foreach ($data as $tagKey => $tag) { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . '][' . $tagKey . ']=' . $tag; } } else { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . ']=' . $this->piVars['filter'][$filterId]; } } } $linkconf['ATagParams'] = 'class="prev" '; $previous = $this->cObj->typoLink($this->pi_getLL('pagebrowser_prev'), $linkconf); } else { $previous = ''; } // next image with link if ($this->piVars['page'] < $pagesTotal) { $nextPage = $this->piVars['page'] + 1; // get static version unset($linkconf); $linkconf['parameter'] = $GLOBALS['TSFE']->id; $linkconf['addQueryString'] = 1; $linkconf['additionalParams'] = '&tx_kesearch_pi1[sword]=' . $this->piVars['sword']; $linkconf['additionalParams'] .= '&tx_kesearch_pi1[page]=' . intval($nextPage); $filterArray = $this->filters->getFilters(); if (is_array($this->piVars['filter'])) { foreach ($this->piVars['filter'] as $filterId => $data) { if (is_array($data)) { foreach ($data as $tagKey => $tag) { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . '][' . $tagKey . ']=' . $tag; } } else { $linkconf['additionalParams'] .= '&tx_kesearch_pi1[filter][' . $filterId . ']=' . $this->piVars['filter'][$filterId]; } } } $linkconf['ATagParams'] = 'class="next" '; $next = $this->cObj->typoLink($this->pi_getLL('pagebrowser_next'), $linkconf); } else { $next = ''; } // render pagebrowser content $content = $this->cObj->getSubpart($this->templateCode, '###PAGEBROWSER###'); $markerArray = array('current' => $this->piVars['page'], 'pages_total' => $pagesTotal, 'pages_list' => $tempContent, 'start' => $start + 1, 'end' => $end, 'total' => $numberOfResults, 'previous' => $previous, 'next' => $next, 'results' => $this->pi_getLL('results'), 'until' => $this->pi_getLL('until'), 'of' => $this->pi_getLL('of')); $this->fluidTemplateVariables['pagebrowser'] = $markerArray; // hook for additional markers in pagebrowse // use only if you use marker based templating, not for fluid based templating! if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['pagebrowseAdditionalMarker'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['pagebrowseAdditionalMarker'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->pagebrowseAdditionalMarker($markerArray, $this); } } $content = $this->cObj->substituteMarkerArray($content, $markerArray, $wrap = '###|###', $uppercase = 1); 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() { $content = ''; $table = 'tx_cal_event'; // 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) . ') '; // index expired events? if (!$this->indexerConfig['cal_expired_events']) { $where .= ' AND ((UNIX_TIMESTAMP(start_date) > UNIX_TIMESTAMP()) OR (UNIX_TIMESTAMP(end_date) > UNIX_TIMESTAMP())) '; } // add enablefields $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, 'res count: '); if ($resCount) { while ($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // compile the information which should go into the index: // title, description $title = strip_tags($record['title']); $abstract = ''; $fullContent = strip_tags($record['description']); // compile params for single view, example: // index.php?id=4749&tx_cal_controller[view]=event&tx_cal_controller[type]=tx_cal_phpicalendar&tx_cal_controller[uid]=3&tx_cal_controller[year]=2016&tx_cal_controller[month]=3&tx_cal_controller%5Bday%5D=13&cHash=02c5c65558b8f44e16bee0c6703132bf $paramsSingleView = array(); $paramsSingleView['tx_cal_controller']['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 = ''; } // get category tags if ($record['category_id']) { $this->buildCategoryTags($record['uid'], $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']; // set event start date as sortdate $additionalFields['sortdate'] = strtotime($record['start_date']) + $record['start_time']; // hook for custom modifications of the indexed data, e.g. the tags if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyCalIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyCalIndexEntry'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyCalIndexEntry($title, $abstract, $fullContent, $params, $tags, $record, $additionalFields, $indexerConfig, $this); } } // store this record to the index $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'cal', $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 . ' "Calendar Base" records have been indexed.</p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); } return $content; }
/** * compiles a list of filter options in order to display them to in plugin (pi1) * @param $config */ function getListOfAvailableFilteroptionsForFlexforms(&$config) { if ($this->isTypo3LTS7()) { $parentRow = $config['flexParentDatabaseRow']; } else { $parentRow = $config['row']; } // get id from string if (strstr($parentRow['pages'], 'pages_')) { $intString = str_replace('pages_', '', $parentRow['pages']); $intString = substr($intString, 0, strpos($intString, '|')); $intString = intval($intString); } else { $intString = intval($parentRow['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 . ') '; $where .= BackendUtility::BEenableFields($table); $where .= BackendUtility::deleteClause($table); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res); if ($count) { 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'] . ')'; $whereOpts .= BackendUtility::BEenableFields($tableOpts); $whereOpts .= BackendUtility::deleteClause($tableOpts); $resOpts = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldsOpts, $tableOpts, $whereOpts); while ($rowOpts = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resOpts)) { $config['items'][] = array($rowFilter['title'] . ': ' . $rowOpts['title'], $rowOpts['uid']); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilteroptionsForFlexforms'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilteroptionsForFlexforms'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyFilteroptionsForFlexforms($config, $rowFilter, $this); } } } } }
/** * Delete all index elements that are older than starting timestamp in registry * * @return string content for BE */ function cleanUpIndex() { $content = ''; $startMicrotime = microtime(true); $table = 'tx_kesearch_index'; // select all index records older than the beginning of the indexing process $where = 'tstamp < ' . $this->registry->get('tx_kesearch', 'startTimeOfIndexer'); // hook for cleanup if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['cleanup'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['cleanup'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $content .= $_procObj->cleanup($where, $this); } } // count and delete old index records $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table, $where); $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, $where); // check if Sphinx is enabled // in this case we have to update sphinx index, too. if ($this->extConfPremium['enableSphinxSearch']) { if (!$this->extConfPremium['sphinxIndexerName']) { $this->extConfPremium['sphinxIndexerConf'] = '--all'; } if (is_file($this->extConfPremium['sphinxIndexerPath']) && is_executable($this->extConfPremium['sphinxIndexerPath']) && file_exists($this->extConfPremium['sphinxSearchdPath']) && is_executable($this->extConfPremium['sphinxIndexerPath'])) { $found = preg_match_all('/exec|system/', ini_get('disable_functions'), $match); if ($found === 0) { // executables are allowed $ret = system($this->extConfPremium['sphinxIndexerPath'] . ' --rotate ' . $this->extConfPremium['sphinxIndexerName']); if (strpos($ret, 'WARNING') !== FALSE) { $warning = strstr($ret, 'WARNING'); $content .= '<div class="error">SPHINX ' . $warning . '</div>'; } $content .= $ret; } elseif ($found === 1) { // one executable is allowed if ($match[0] == 'system') { $ret = system($this->extConfPremium['sphinxIndexerPath'] . ' --rotate ' . $this->extConfPremium['sphinxIndexerName']); } else { // use exec exec($this->extConfPremium['sphinxIndexerPath'] . ' --rotate ' . $this->extConfPremium['sphinxIndexerName'], $retArr); foreach ($retArr as $retRow) { if (strpos($retRow, 'WARNING') !== FALSE) { $content .= '<div class="error">SPHINX ' . $retRow . '</div>'; } } $ret = implode(';', $retArr); } $content .= $ret; } else { $content .= '<div class="error">Check your php.ini configuration for disable_functions. For now it is not allowed to execute a shell script.</div>'; } } else { $content .= '<div class="error">We can\'t find the sphinx executables or execution permission is missing.</div>'; } } $content .= '<p><b>Index cleanup:</b><br />' . "\n"; $content .= $count . ' entries deleted.<br />' . "\n"; // calculate duration of indexing process $duration = ceil((microtime(true) - $startMicrotime) * 1000); $content .= '<i>Cleanup process took ' . $duration . ' ms.</i></p>' . "\n"; 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 = ''; $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); } }
/** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { if (TYPO3_VERSION_INTEGER >= 7000000) { $this->ms = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds(); } else { $this->ms = t3lib_div::milliseconds(); } $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->pi_USER_INT_obj = 1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! // initializes plugin configuration $this->init(); // init domReady action $this->initDomReadyAction(); // add header parts when in searchbox mode $this->addHeaderParts(); // init XAJAX? if ($this->conf['renderMethod'] != 'static') { if (TYPO3_VERSION_INTEGER < 6002000) { $xajaxIsLoaded = t3lib_extMgm::isLoaded('xajax'); } else { $xajaxIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('xajax'); } if (!$xajaxIsLoaded) { return '<span style="color: red;"><b>ke_search error:</b>"XAJAX" must be installed for this mode.</span>'; } else { $this->initXajax(); } } // Spinner Image if ($this->conf['spinnerImageFile']) { $spinnerSrc = $this->conf['spinnerImageFile']; } else { if (TYPO3_VERSION_INTEGER < 6002000) { $spinnerSrc = t3lib_extMgm::siteRelPath($this->extKey) . 'res/img/spinner.gif'; } else { $spinnerSrc = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'res/img/spinner.gif'; } } $this->spinnerImageFilters = '<img id="kesearch_spinner_filters" src="' . $spinnerSrc . '" alt="' . $this->pi_getLL('loading') . '" />'; $this->spinnerImageResults = '<img id="kesearch_spinner_results" src="' . $spinnerSrc . '" alt="' . $this->pi_getLL('loading') . '" />'; // get javascript onclick actions $this->initOnclickActions(); // hook for initials if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->addInitials($this); } } // get content $content = $this->getSearchboxContent(); $subpart = $this->cObj->getSubpart($content, '###SHOW_SPINNER###'); if ($this->conf['renderMethod'] == 'static') { $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', ''); } else { $subpart = $this->cObj->substituteMarker($subpart, '###SPINNER###', $this->spinnerImageFilters); $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', $subpart); } $content = $this->cObj->substituteMarker($content, '###LOADING###', $this->pi_getLL('loading')); // hook for additional searchbox markers if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalSearchboxContent'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalSearchboxContent'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->additionalSearchboxContent($content, $this); } } return $this->pi_wrapInBaseClass($content); }
/** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { $this->ms = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds(); $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->pi_USER_INT_obj = 1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! // initializes plugin configuration $this->init(); if ($this->conf['resultPage'] != $GLOBALS['TSFE']->id) { $content = '<div id="textmessage">' . $this->pi_getLL('error_resultPage') . '</div>'; return $this->pi_wrapInBaseClass($content); } // init template if ($this->conf['renderMethod'] == 'fluidtemplate') { $this->initFluidTemplate(); } else { if (!$this->initMarkerTemplate()) { return; } } // hook for initials if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->addInitials($this); } } // fetch template code for marker based templating if ($this->conf['renderMethod'] != 'fluidtemplate') { $content = $this->cObj->getSubpart($this->templateCode, '###RESULT_LIST###'); } // hook: modifyResultList (only valid for marker based templating, not for fluid based templating) if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyResultList($content, $this); } } // assign isEmptySearch to fluid templates $this->fluidTemplateVariables['isEmptySearch'] = $this->isEmptySearch; // if there's exclusive content do the rendering and stop here if ($this->conf['renderMethod'] != 'fluidtemplate') { $exclusiveContent = $this->renderExclusiveMarkerBasedContent(); if ($exclusiveContent) { return $exclusiveContent; } } // render "no results"-message, "too short words"-message and finally the result list $resultList = $this->getSearchResults(); $content = $this->cObj->substituteMarker($content, '###MESSAGE###', $resultList); // number of results $content = $this->cObj->substituteMarker($content, '###NUMBER_OF_RESULTS###', sprintf($this->pi_getLL('num_results'), $this->numberOfResults)); $this->fluidTemplateVariables['numberofresults'] = $this->numberOfResults; // sorting, fluid template variables are filled in class tx_kesearch_lib_sorting $content = $this->cObj->substituteMarker($content, '###ORDERING###', $this->renderOrdering()); // spinner and loading icon (does not apply to fluid template) if ($this->conf['renderMethod'] != 'fluidtemplate') { $subpart = $this->cObj->getSubpart($content, '###SHOW_SPINNER###'); if ($this->conf['renderMethod'] == 'static') { $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', ''); } else { $subpart = $this->cObj->substituteMarker($subpart, '###SPINNER###', $this->spinnerImageResults); $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', $subpart); } $content = $this->cObj->substituteMarker($content, '###LOADING###', $this->pi_getLL('loading')); } // process query time $queryTime = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds() - $GLOBALS['TSFE']->register['ke_search_queryStartTime']; $this->fluidTemplateVariables['queryTime'] = $queryTime; $this->fluidTemplateVariables['queryTimeText'] = sprintf($this->pi_getLL('query_time'), $queryTime); if ($this->conf['showQueryTime']) { $content = $this->cObj->substituteMarker($content, '###QUERY_TIME###', sprintf($this->pi_getLL('query_time'), $queryTime)); } else { $content = $this->cObj->substituteMarker($content, '###QUERY_TIME###', ''); } // render pagebrowser if ($GLOBALS['TSFE']->id == $this->conf['resultPage']) { if ($this->conf['pagebrowserOnTop'] || $this->conf['pagebrowserAtBottom']) { $pagebrowserContent = $this->renderPagebrowser(); } if ($this->conf['pagebrowserOnTop']) { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_TOP###', $pagebrowserContent); } else { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_TOP###', ''); } if ($this->conf['pagebrowserAtBottom']) { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_BOTTOM###', $pagebrowserContent); } else { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_BOTTOM###', ''); } } // generate HTML output (fluid or marker based templating) if ($this->conf['renderMethod'] == 'fluidtemplate') { $this->resultListView->assignMultiple($this->fluidTemplateVariables); $htmlOutput = $this->resultListView->render(); } else { $htmlOutput = $this->pi_wrapInBaseClass($content); } return $htmlOutput; }
/** * renders the "spinner" and loading note and provides a hook for * even more content in the searchbox (only for static and ajax * template, not for fluid template) * * @param string $content * @return string */ public function renderAdditionalSearchboxContent($content) { $subpart = $this->cObj->getSubpart($content, '###SHOW_SPINNER###'); if ($this->conf['renderMethod'] == 'static') { $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', ''); } else { $subpart = $this->cObj->substituteMarker($subpart, '###SPINNER###', $this->spinnerImageFilters); $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', $subpart); } $content = $this->cObj->substituteMarker($content, '###LOADING###', $this->pi_getLL('loading')); // hook for additional searchbox markers if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalSearchboxContent'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalSearchboxContent'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->additionalSearchboxContent($content, $this); } } 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 = ''; $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; }
/** * generate the link for normal textlinks * * @param string $filterUid * @param string $option * @return string The complete link as A-Tag */ public function generateLink($filterUid, $option) { $filters = $this->pObj->filters->getFilters(); $params = array(); $params[] = '[page]=1'; $params[] = '[filter][' . $filterUid . '][' . $option['uid'] . ']=' . $option['tag']; $excludes = array(); $excludes[] = 'id'; $excludes[] = 'tx_kesearch_pi1[multi]'; // hook: modifyParamsForTextlinks // This is useful if you want to define special sortings for each textlink if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyParamsForTextlinks'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyParamsForTextlinks'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyParamsForTextlinks($params, $excludes, $option, $this->conf, $this->pObj); } } foreach ($params as $key => $value) { $params[$key] = $this->cObj->wrap($value, $this->pObj->prefixId . '|'); } $conf = array(); $conf['parameter'] = $this->conf['resultPage']; $conf['addQueryString'] = '1'; $conf['addQueryString.']['exclude'] = implode(',', $excludes); $conf['additionalParams'] = '&' . implode('&', $params); $number_of_results = $this->pObj->renderNumberOfResultsString($option['results'], $filters[$filterUid]); return $this->cObj->typoLink($option['title'] . $number_of_results, $conf); }
/** * 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 = ''; $this->conf['useHRDatesSingle'] = $this->indexerConfig['index_news_useHRDatesSingle']; $this->conf['useHRDatesSingleWithoutDay'] = $this->indexerConfig['index_news_useHRDatesSingleWithoutDay']; // get all the tt_news entries to index // don't index hidden or deleted news, BUT // get the news with frontend user group access restrictions // or time (start / stop) restrictions. // Copy those restrictions to the index. $fields = '*'; $table = 'tt_news'; $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); $counter = 0; if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { while ($newsRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // if mode equals 'choose categories for indexing' (2). 1 = All if ($this->indexerConfig['index_news_category_mode'] == '2') { if (TYPO3_VERSION_INTEGER >= 7000000) { $enableFields = TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_news_cat') . TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_news_cat'); } else { $enableFields = t3lib_befunc::BEenableFields('tt_news_cat') . t3lib_befunc::deleteClause('tt_news_cat'); } $resCat = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tt_news_cat.uid', 'tt_news', 'tt_news_cat_mm', 'tt_news_cat', ' AND tt_news.uid = ' . $newsRecord['uid'] . $enableFields, '', '', ''); if ($GLOBALS['TYPO3_DB']->sql_num_rows($resCat)) { $isInList = false; while ($newsCat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resCat)) { // if category was found in list, set isInList to true and break further processing. if (TYPO3_VERSION_INTEGER >= 7000000) { if (TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->indexerConfig['index_news_category_selection'], $newsCat['uid'])) { $isInList = true; break; } } else { if (t3lib_div::inList($this->indexerConfig['index_news_category_selection'], $newsCat['uid'])) { $isInList = true; break; } } } // if category was not found stop further processing and loop with next news record if (!$isInList) { continue; } } } // compile the information which should go into the index $type = 'tt_news'; $title = strip_tags($newsRecord['title']); $abstract = strip_tags($newsRecord['short']); $content = strip_tags($newsRecord['bodytext']); // add keywords to content if not empty if (!empty($newsRecord['keywords'])) { $content .= "\n" . $newsRecord['keywords']; } // create content $fullContent = $abstract . "\n" . $content; // create params and custom single view page: // if it is a default news (type = 0), add params // if it is an internal page (type = 1), put that into the "targetpid" field // if it is an external url (type = 2), put that into the "params" field if ($newsRecord['type'] == 1) { $singleViewPage = $newsRecord['page']; $params = ''; } else { if ($newsRecord['type'] == 2) { $type = 'external:tt_news'; $singleViewPage = ''; $params = $newsRecord['ext_url']; } else { // get target page from category if set (first assigned category) if (TYPO3_VERSION_INTEGER < 6002000) { $ttnewsIsLoaded = t3lib_extMgm::isLoaded('tt_news'); } else { $ttnewsIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_news'); } if ($ttnewsIsLoaded) { $singleViewPage = $this->getSingleViewPageFromCategories($newsRecord['uid']); } $paramsSingleView = $this->getParamsForHrDateSingleView($newsRecord['datetime']); $paramsSingleView['tx_ttnews']['tt_news'] = $newsRecord['uid']; $params = '&' . http_build_query($paramsSingleView, NULL, '&'); $params = rawurldecode($params); } } // create tags if ($this->indexerConfig['index_use_page_tags']) { $tags = $this->pageRecords[intval($newsRecord['pid'])]['tags']; } else { $tags = ''; } // add additional fields $additionalFields = array(); // crdate is always given, but can be overwritten $additionalFields['sortdate'] = $newsRecord['crdate']; // last changed date if (isset($newsRecord['datetime']) && $newsRecord['datetime'] > 0) { $additionalFields['sortdate'] = $newsRecord['datetime']; } // fill orig_uid and orig_pid $additionalFields['orig_uid'] = $newsRecord['uid']; $additionalFields['orig_pid'] = $newsRecord['pid']; // make it possible to modify the indexerConfig via hook $indexerConfig = $this->indexerConfig; // overwrite default targetpid value from indexerconfig // only if $singleViewPage is set if ($singleViewPage) { $indexerConfig['targetpid'] = $singleViewPage; } // hook for custom modifications of the indexed data, e. g. the tags if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyNewsIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyNewsIndexEntry'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->modifyNewsIndexEntry($title, $abstract, $fullContent, $params, $tags, $newsRecord, $additionalFields, $indexerConfig); } } // ... and store them $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, $type, $indexerConfig['targetpid'], $fullContent, $tags, $params, $abstract, $newsRecord['sys_language_uid'], $newsRecord['starttime'], $newsRecord['endtime'], $newsRecord['fe_group'], false, $additionalFields); $counter++; } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '":</b><br />' . "\n" . $counter . ' news have been indexed.</p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); } return $content; }
/** * 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 =& TYPO3\CMS\Core\Utility\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); }
/** * 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; }
/** * get limit for where query * * @return array */ public function getLimit() { $limit = $this->conf['resultsPerPage'] ? $this->conf['resultsPerPage'] : 10; if ($this->pObj->piVars['page']) { $start = $this->pObj->piVars['page'] * $limit - $limit; if ($start < 0) { $start = 0; } } $startLimit = array($start, $limit); // hook for third party pagebrowsers or for modification $this->pObj->piVars['page'] parameter if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['getLimit'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['getLimit'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->getLimit($startLimit, $this); } } return $startLimit; }
/** * 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; }
/** * 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']; // get categories $categories = $this->getCategories(); // get dam records from categories $fields = 'DISTINCT tx_dam.*'; $table = 'tx_dam_mm_cat, tx_dam'; $where = '1=1'; if (is_array($categories) && count($categories)) { if ($this->indexerConfig['index_dam_without_categories']) { $table = 'tx_dam_mm_cat RIGHT JOIN tx_dam ON (tx_dam_mm_cat.uid_local = tx_dam.uid)'; $where .= ' AND uid_foreign IN (' . implode(',', $categories) . ')'; $where .= ' OR tx_dam.category = 0'; } else { $where .= ' AND tx_dam_mm_cat.uid_local = tx_dam.uid'; $where .= ' AND uid_foreign IN (' . implode(',', $categories) . ')'; } } $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_dam'); $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_dam'); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res); if ($resCount) { while ($damRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $additionalFields = array(); // prepare content for storing in index table $title = strip_tags($damRecord['title']); $params = '&tx_dam[uid]=' . intval($damRecord['uid']); $abstract = ''; $content = strip_tags($damRecord['description']); $title = strip_tags($damRecord['title']); $keywords = strip_tags($damRecord['keywords']); $filename = strip_tags($damRecord['file_name']); $fullContent = $content . "\n" . $keywords . "\n" . $filename; $targetPID = $this->indexerConfig['targetpid']; // get tags for this record // needs extension ke_search_dam_tags $keSearchDamTagsIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('ke_search_dam_tags'); if ($keSearchDamTagsIsLoaded) { $damRecordTags = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $damRecord['tx_kesearchdamtags_tags'], true); $tags = ''; $clearTextTags = ''; if (count($damRecordTags)) { foreach ($damRecordTags 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); } } } else { $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']['modifyDAMIndexEntry'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyDAMIndexEntry'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyDAMIndexEntry($title, $abstract, $fullContent, $params, $tags, $damRecord, $targetPID, $clearTextTags, $additionalFields, $indexerConfig); } } // add clearText Tags to content, make them searchable // by fulltext search if (!empty($clearTextTags)) { $fullContent .= $clearTextTags; } // store data in index table $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'dam', $indexerConfig['targetpid'], $fullContent, $tags, $params, $abstract, $damRecord['sys_language_uid'], $damRecord['starttime'], $damRecord['endtime'], $damRecord['fe_group'], false, $additionalFields); } } $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '": ' . $resCount . ' DAM records have been indexed.</b></p>' . "\n"; $content .= $this->showErrors(); $content .= $this->showTime(); return $content; }
/** * add filter options (preselected by piVars) * * @param array $tagsAgainst */ public function buildPiVarsTagsAgainst(array &$tagsAgainst) { // add filter options selected in the frontend $tagChar = $this->pObj->extConf['prePostTagChar']; if (is_array($this->pObj->piVars['filter'])) { foreach ($this->pObj->piVars['filter'] as $key => $tag) { if (is_array($this->pObj->piVars['filter'][$key])) { foreach ($this->pObj->piVars['filter'][$key] as $subkey => $subtag) { // Don't add the tag if it is already inserted by preselected filters if (!empty($subtag) && strstr($tagsAgainst[$key], $subtag) === false) { // Don't add a "+", because we are here in checkbox mode. It's a OR. $tagsAgainst[$key] .= ' "' . $tagChar . $GLOBALS['TYPO3_DB']->quoteStr($subtag, 'tx_kesearch_index') . $tagChar . '"'; } } } else { // Don't add the tag if it is already inserted by preselected filters if (!empty($tag) && strstr($tagsAgainst[$key], $subtag) === false) { $tagsAgainst[$key] .= ' +"' . $tagChar . $GLOBALS['TYPO3_DB']->quoteStr($tag, 'tx_kesearch_index') . $tagChar . '"'; } } } } // hook for modifiying the tags to filter for if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyTagsAgainst'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyTagsAgainst'] as $_classRef) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); $_procObj->modifyTagsAgainst($tagsAgainst, $this); } } }
/** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { if (TYPO3_VERSION_INTEGER >= 7000000) { $this->ms = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds(); } else { $this->ms = t3lib_div::milliseconds(); } $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->pi_USER_INT_obj = 1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! // initializes plugin configuration $this->init(); if ($this->conf['resultPage'] != $GLOBALS['TSFE']->id) { $content = '<div id="textmessage">' . $this->pi_getLL('error_resultPage') . '</div>'; return $this->pi_wrapInBaseClass($content); } // init XAJAX? if ($this->conf['renderMethod'] != 'static') { if (TYPO3_VERSION_INTEGER < 6002000) { $xajaxIsLoaded = t3lib_extMgm::isLoaded('xajax'); } else { $xajaxIsLoaded = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('xajax'); } if (!$xajaxIsLoaded) { return; } else { $this->initXajax(); } } // Spinner Image if ($this->conf['spinnerImageFile']) { $spinnerSrc = $this->conf['spinnerImageFile']; } else { if (TYPO3_VERSION_INTEGER < 6002000) { $spinnerSrc = t3lib_extMgm::siteRelPath($this->extKey) . 'res/img/spinner.gif'; } else { $spinnerSrc = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'res/img/spinner.gif'; } } $this->spinnerImageFilters = '<img id="kesearch_spinner_filters" src="' . $spinnerSrc . '" alt="' . $this->pi_getLL('loading') . '" />'; $this->spinnerImageResults = '<img id="kesearch_spinner_results" src="' . $spinnerSrc . '" alt="' . $this->pi_getLL('loading') . '" />'; // get javascript onclick actions $this->initOnclickActions(); // hook for initials if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['initials'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->addInitials($this); } } $content = $this->cObj->getSubpart($this->templateCode, '###RESULT_LIST###'); // hook: modifyResultList if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'] as $_classRef) { if (TYPO3_VERSION_INTEGER >= 7000000) { $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef); } else { $_procObj =& t3lib_div::getUserObj($_classRef); } $_procObj->modifyResultList($content, $this); } } // show text instead of results if no searchparams set and activated in ff if ($this->isEmptySearch && $this->conf['showTextInsteadOfResults']) { // Don't replace the following with substituteMarker // this is used to be valid against JavaScript calls $content = '<div id="textmessage">' . $this->pi_RTEcssText($this->conf['textForResults']) . '</div>'; $content .= '<div id="kesearch_results"></div>'; $content .= '<div id="kesearch_updating_results"></div>'; $content .= '<div id="kesearch_pagebrowser_top"></div>'; $content .= '<div id="kesearch_pagebrowser_bottom"></div>'; $content .= '<div id="kesearch_query_time"></div>'; return $content; } if ($this->conf['renderMethod'] == 'ajax_after_reload') { $content = $this->cObj->substituteMarker($content, '###MESSAGE###', ''); $content = $this->cObj->substituteMarker($content, '###QUERY_TIME###', ''); $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_TOP###', ''); $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_BOTTOM###', ''); $content = $this->cObj->substituteMarker($content, '###NUMBER_OF_RESULTS###', ''); $content = $this->cObj->substituteMarker($content, '###ORDERING###', ''); $content = $this->cObj->substituteMarker($content, '###SPINNER###', ''); $content = $this->cObj->substituteMarker($content, '###LOADING###', ''); return $this->pi_wrapInBaseClass($content); } $content = $this->cObj->substituteMarker($content, '###MESSAGE###', $this->getSearchResults()); $content = $this->cObj->substituteMarker($content, '###NUMBER_OF_RESULTS###', sprintf($this->pi_getLL('num_results'), $this->numberOfResults)); $content = $this->cObj->substituteMarker($content, '###ORDERING###', $this->renderOrdering()); $subpart = $this->cObj->getSubpart($content, '###SHOW_SPINNER###'); if ($this->conf['renderMethod'] == 'static') { $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', ''); } else { $subpart = $this->cObj->substituteMarker($subpart, '###SPINNER###', $this->spinnerImageResults); $content = $this->cObj->substituteSubpart($content, '###SHOW_SPINNER###', $subpart); } $content = $this->cObj->substituteMarker($content, '###LOADING###', $this->pi_getLL('loading')); // process query time if ($this->conf['showQueryTime']) { if (TYPO3_VERSION_INTEGER >= 7000000) { $queryTime = TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds() - $GLOBALS['TSFE']->register['ke_search_queryStartTime']; } else { $queryTime = t3lib_div::milliseconds() - $GLOBALS['TSFE']->register['ke_search_queryStartTime']; } $content = $this->cObj->substituteMarker($content, '###QUERY_TIME###', sprintf($this->pi_getLL('query_time'), $queryTime)); } else { $content = $this->cObj->substituteMarker($content, '###QUERY_TIME###', ''); } // render pagebrowser if ($GLOBALS['TSFE']->id == $this->conf['resultPage']) { if ($this->conf['pagebrowserOnTop'] || $this->conf['pagebrowserAtBottom']) { $pagebrowserContent = $this->renderPagebrowser(); } if ($this->conf['pagebrowserOnTop']) { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_TOP###', $pagebrowserContent); } else { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_TOP###', ''); } if ($this->conf['pagebrowserAtBottom']) { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_BOTTOM###', $pagebrowserContent); } else { $content = $this->cObj->substituteMarker($content, '###PAGEBROWSER_BOTTOM###', ''); } } return $this->pi_wrapInBaseClass($content); }